Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight every matched pattern while searching in Vim [duplicate]

Tags:

regex

vim

I have set incsearch set in my .vimrc and it highlights EVERY matched pattern only when tapping enter. But is there any way to highlight all the matches while typing in the search?

like image 405
Jikku Jose Avatar asked Jan 03 '14 08:01

Jikku Jose


People also ask

How do I highlight all instances of words in vim?

The hlsearch option will highlight all of them if set. # will search for the previous occurrence of the word. You might wish to map :nohlsearch<CR> to some convenient key. But you can go back to the position where you pressed * or # by <Ctrl>o in normal mode.

Why are some words highlighted in vim?

Syntax highlighting is nothing but a feature of vi/vim text editors that displays text, especially source code, in different colors and fonts according to the category of terms.


1 Answers

That's what :set incsearch is about: showing the matches while typing the pattern:

enter image description here

Ensure that the IncSearch highlight group actually has distinctive visual features; it may have been cleared:

:hi IncSearch

Only the next match is highlighted here; this is to enable the features mentioned at :help 'incsearch':

CTRL-L can be used to add one character from after the current match to the command line. If 'ignorecase' and 'smartcase' are set and the command line has no uppercase characters, the added character is converted to lowercase.

CTRL-R CTRL-W can be used to add the word at the end of the current match, excluding the characters that were already typed.

If you want all matches highlighted, you have to either modify Vim's source code (and eventually post a patch), or re-implement search (using getchar() and matchad()) entirely in Vimscript. Both are not trivial, so I'd recommend to stick with the status quo.

like image 76
Ingo Karkat Avatar answered Nov 02 '22 20:11

Ingo Karkat