我有四种类型的突出显示.vimrc(每种都显示不同的颜色):
/搜索匹配)突出显示的优先级似乎与我上面列出的完全相同.例如,增量搜索着色将覆盖任何其他匹配颜色(如果存在于同一字符中).
我想hlsearch优先考虑第二,以便它覆盖两者match和2match颜色(如果存在于同一个字符中).
有没有办法实现这一目标?
作为参考,这些是我.vimrc文件中的相关行:
[...]
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()'
[...]
Run Code Online (Sandbox Code Playgroud)
您使用的一切的优先级是固定的; 指定优先级的唯一方法是via matchadd(),您可以将其用作:matchand 的替代:2match.由于hlsearch的优先级为零,因此您需要传递负优先级,例如-1).
例如,替换
:match Match /\<\w\{5}\>/
Run Code Online (Sandbox Code Playgroud)
同
if exists(w:lastmatch)
call matchdelete(w:lastmatch)
endif
let w:lastmatch = call matchadd('Match', '\<\w\{5}\>', -1)
Run Code Online (Sandbox Code Playgroud)