Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Vim highlight all search results while typing the search and turn off highlighting when I do anything else

I would like my Vim to highlight all search results as I am typing my search, i.e. not just the next search result (as in incsearch), but all of them (as in hlsearch but at the same time as I am typing). I would also like to turn off search highlighting as soon as I do anything else than search. Is this possible?

like image 656
00prometheus Avatar asked Oct 22 '25 16:10

00prometheus


2 Answers

It sounds like you want haya14busa/incsearch.vim. The biggest thing it does is highlighting every result as you are searching, which you can see in this gif:

enter image description here

There are other things it does too. For example, it can be configured to turn of highlighting when you are done searching, and it can also provide useful mappings for other search related features, like

n  
N  
*  
#  
g* 
g# 

You can install it with Neobundle/Vundle/vim-plug by doing

NeoBundle 'haya14busa/incsearch.vim'
Plugin 'haya14busa/incsearch.vim'
Plug 'haya14busa/incsearch.vim'

or with pathogen by doing:

git clone https://github.com/haya14busa/incsearch.vim ~/.vim/bundle/incsearch.vim
like image 108
DJMcMayhem Avatar answered Oct 24 '25 13:10

DJMcMayhem


You could try the vim-cool plugin, which was mentioned in a similar question:

Vim-cool disables search highlighting when you are done searching and re-enables it when you search again.

Vim-cool re-enables search highlighting when the cursor is on a word that matches the last search pattern.

Vim-cool is cool.

like image 23
mMontu Avatar answered Oct 24 '25 13:10

mMontu