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

highlight, search, vim

Solution

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:

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

Problem

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?

Original source