5

我有以下四种类型的突出显示.vimrc(每种显示不同的颜色):

  • incsearch(高亮搜索匹配)
  • 匹配(当前单词,la Visual Studio 编辑器)
  • 2match(行尾的尾随空格)
  • hlsearch(常规/搜索匹配)

突出显示的优先级似乎与我上面列出的完全一样。例如,如果存在于同一字符中,增量搜索着色将覆盖任何其他匹配颜色。

我想hlsearch排在第二位,以便它覆盖match2match颜色(如果存在于同一个字符中)。

有没有办法做到这一点?

.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()'
[...]
4

1 回答 1

9

您使用的所有内容的优先级都是固定的;指定优先级的唯一方法是 via matchadd(),您可以使用它来替代:matchand :2match。由于 hlsearch 的优先级为零,因此您需要传递一个负优先级,例如 -1)。

例如,替换

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

if exists(w:lastmatch)
    call matchdelete(w:lastmatch)
endif
let w:lastmatch = call matchadd('Match', '\<\w\{5}\>', -1)
于 2012-12-28T12:13:27.770 回答