Separate windows search in VIM

When I split VIM to show me multiple files or different parts of the same file, is there a way for me to have one search in one window and another search in another? For example, I would like the top window to have a foo search pattern and the bottom window to have a bar search pattern.

The active search pattern affects what is highlighted when using search highlighting, and it is quite annoying when foo highlighted in the top window, and then I switch to the bottom window and do a bar search and foo stops highlighting in the top window.

Edit: This question seems to be related, although I'm not sure if this is an exact duplicate.

+4
source share
2 answers

I use this script to highlight multiple search patterns.

+6
source

Canopus's answer is probably the nicest way to do this if you use it often, but if you want to do it by installing vanilla vim (or more, without installing any plugins), you can just do

 :call matchadd('Search', 'foo') :call matchadd('Search', 'bar') 

Then you can clear all matches with

 :call clearmatches() 

There are also ways to be more fussy about what you are clearing (with :call matchdelete(...) ) by storing the output of matchadd with a variable. For more information, see :help matchadd() and :help matchdelete()

If you are not using a syntax file that is too complicated (and in particular, not using rainbow.vim highlighting), you can also do this with:

 :syn keyword Search foo :syn keyword Search bar 

and clean it with

 :syn clear Search 

The only possible advantage of this that I can think of is that if there are many matches that you are trying to highlight, keyword highlighting is much faster than match highlighting (as the latter uses regex search). You can still execute syn keyword if you use rainbow.vim, but the command is much more complicated.

+4
source

Source: https://habr.com/ru/post/1286559/


All Articles