Change vim priorities

I have the following four types of highlighting in my .vimrc (each one displays a different color):

  • incsearch (backlit matches as you search)
  • match (current word, a la visual studio editor)
  • 2match (trailing spaces at the end of a line)
  • hlsearch (regular matches / )

The allocation priority seems to be exactly like me above. For instance. incremental search coloring will override any other matching colors if they are in the same character.

I would like to make hlsearch second in priority, so that it redefines the colors match and 2match (if present in the same character).

Is there any way to do this?

For reference, these are the relevant lines in my .vimrc file:

 [...] set hlsearch set incsearch [...] function Matches() highlight curword ctermbg=darkgrey cterm=bold gui=bold guibg=darkgrey silent! exe printf('match curword /\V\<%s\>/', escape(expand('<cword>'), '/\')) highlight eolspace ctermbg=red guibg=red 2match eolspace /\s\+$/ endfunction au CursorMoved * exe 'call Matches()' [...] 
+4
source share
1 answer

The priority of everything you use is fixed; the only way to specify priority is through matchadd() , which you can use as a replacement for :match and :2match . Since hlsearch priority is zero, you need to pass a negative priority, for example. -1).

For example, replace

 :match Match /\<\w\{5}\>/ 

with

 if exists(w:lastmatch) call matchdelete(w:lastmatch) endif let w:lastmatch = call matchadd('Match', '\<\w\{5}\>', -1) 
+6
source

All Articles