How to display number of matches in incremental search? - search

I think ordinary editors can display the number of matches while searching strings like following. How to do this in Emacs? Especially I want to see these numbers while using isearch-forward and isearch-forward-regexp.

The 3rd party package anzu.el displays the current match and the total number of matches of the current incremental search in the mode line.
You can install from Marmalade or MELPA with M-x package-install RET anzu. Note that neither of these archives are enabled by default in Emacs, so you need to customize package-archives as explained in the instructions of the corresponding archive.

Related

Is there a one-liner to tell vim/ctags autocompletion to search from the middle of a word?

In vim (in Insert mode, after running exuberant ctags), I am using ctrl-x followed by ctrl-] to bring up a dropdown of various possible words/tokens. It's a great feature.
The problem is that by default, this list starts with a bunch of numeric options and automatically inserts the first numeric option, and if I backspace to get rid of the numbers and start typing a part of a word fresh -- with the idea of searching from the middle of the word -- the autocompletion behavior exits entirely.
I know I could type the first letter of the word that I want, then go from there. But that assumes that I know the first letter of the word, which is not necessarily a given.
For example, if I'm working on a pair-programming project with a friend during a long weekend, I might not remember at any given moment whether he called his method promoteRecordStatus(), updateRecordStatus() or boostRecordStatus(). In this example, I would like to type RecordStatus and get the relevant result, which does not seem to be possible at a glance with the current behavior.
So with that scenario in mind: Is there a simple, vim-native way to tell the editor to start its autocompletion without any assumptions, then search all available tokens for my typed string in all parts of each token?
I will of course consider plugin suggestions helpful, but I would prefer a short, vim-native answer that doesn't require any plugins if possible. Ideally, the configuration could be set using just a line or two.
The built-in completions all require a match at the starting position. In some cases, you could drop separator characters from the 'iskeyword' option (e.g. in Vimscript, drop # to be able to complete individual components from foo#bar#BazFunction()), but this won't work for camelCaseWords at all.
Custom :help complete-functions can implement any completion search, though. To be based on the tags database, it would have to use taglist() as a source, and filter according to the completion base entered before triggering the completion. If you do not anchor this pattern match at the beginning, you have your desired completion.

Vim: How to search for more than one word in the same search?

Is it possible to search within vim for more than one word?
For example:
Let's say i'm inside vim and I press / in order to start a search for a certain word, is it possible to search for more than one word in the same search?
Yes, you can have several branches in a search pattern:
/foo\|bar
See :help \|.
Use the OR operator
/first\|second
If you do this often, my SearchAlternatives plugin may be useful to you.
The plugin provides mappings and commands to add and subtract alternative
branches to the current search pattern. Currently searching for "foo", but
also want to find matches for "bar"? You could type /foo\|bar<CR> or
/<C-R>/\|bar<CR>, but once you want to limit the search to whole \<words\>
(like the * command), and juggle several alternatives, adding and
dropping them as you search, this plugin is quicker than manually editing the
search command-line (which you can still do).

Searching hundreds of org-mode files without loading them into Emacs?

I've compiled hundres of org-mode files in a specific directory.
Is there any way to search these files for specific keywords, or build agendas,
without loading them into Emacs, possibly using external search tools such as `ag'?
You can search them using Icicles. In Icicle minor mode, C-x C-f is bound to a multi-completion command that lets you match against the file name or the file content, or both. You can change the match patterns on the fly. Buffer *Completions* shows you the files that match.
And you can use progressive completion, combining any number of search patterns. Each pattern can itself be a regexp (or a substring), but it is a lot easier to combine several simple patterns than it is to come up with one complex pattern to DTRT. You can also negate patterns (obtain the complement of the match set).
You can visit any of the matching files that you like -- any number of them during the same command invocation. Or you can visit none of them if you like (C-g), and just use the command to locate those that match. You can use C-M-RET, C-M-down, etc. to get information about particular matching files (file type, permissions, size, last access time, creation time, etc.).
You can act on any number of them in some other way than visiting, using an alternate function that you specify: Just bind variable icicle-candidate-alt-action-fn to this function in a command you write that invokes icicle-find-file-of-content. Lots more features --- see Icicles - File-Name Input.

How to merge completion candidates for vim?

I often rely on omni-completion to edit source codes, so my current .vimrc contains following setting to gain quick access to intended candidates:
inoremap <C-f> <C-x><C-o>
Now I find there are many kinds of ins-completions except for omni-completion and become interested to use both tags and file names completions too.
1. Whole lines i_CTRL-X_CTRL-L
2. keywords in the current file i_CTRL-X_CTRL-N
3. keywords in 'dictionary' i_CTRL-X_CTRL-K
4. keywords in 'thesaurus', thesaurus-style i_CTRL-X_CTRL-T
5. keywords in the current and included files i_CTRL-X_CTRL-I
6. tags i_CTRL-X_CTRL-]
7. file names i_CTRL-X_CTRL-F
8. definitions or macros i_CTRL-X_CTRL-D
9. Vim command-line i_CTRL-X_CTRL-V
10. User defined completion i_CTRL-X_CTRL-U
11. omni completion i_CTRL-X_CTRL-O
12. Spelling suggestions i_CTRL-X_s
13. keywords in 'complete' i_CTRL-N*emphasized text*
The question is, how can I list up whole candidates from these specific completion sources on a ins-complete-menu with single command, <C-f>.
Use the default completion (CTRL-N / CTRL-P); its completion sources can be configured via the 'complete' option. Unfortunately, from your list, only tags (not file names) can be (and is by default) included in there. (But don't you know beforehand that you want file completion? I particularly like the many different completion commands because they narrow down the result list, which for me is far more valuable than not having to think about which completion to invoke.)
If you really want an all-encompassing completion, you'd have to implement that yourself as a user-completion, and you'd have to re-implement all the built-in sources, as there currently is no way to programmatically get them.
You should check the plugin neocomplcache. It can acomplish this but the setting may not be trivial.

Reload tags file Vim

How do i reload the tags file from within Vim?
Is a restart necessary?
According to :help tag-binary-search, the tags file is binary (or linear) searched on each lookup, so there's no need to reload the file:
*tag-binary-search*
Vim uses binary searching in the tags file to find the desired tag quickly
(when enabled at compile time |+tag_binary|). But this only works if the
tags file was sorted on ASCII byte value. Therefore, if no match was found,
another try is done with a linear search. If you only want the linear search,
reset the 'tagbsearch' option. Or better: Sort the tags file!
Note that the binary searching is disabled when not looking for a tag with a
specific name. This happens when ignoring case and when a regular expression
is used that doesn't start with a fixed string. Tag searching can be a lot
slower then. The former can be avoided by case-fold sorting the tags file.
See 'tagbsearch' for details.
As far as I know it is not necessary Vim 7.3 use the tags file as soon as it has been generated.
I find it helps to just load the tags file in another buffer/tab. Then I can re-load that buffer with :e! to get vim to see my tag updates.

Resources