Vim 突出显示单词列表 [英] Vim highlight a list of words
问题描述
我需要在 vim 中突出显示一个单词列表,最好在文件中定义这些单词.有点像拼写检查.我一直在查看 http://vim.wikia.com/wiki/Highlight_multiple_words 但它需要我将每个单词定义为一个新位置,并且不支持将这些单词存储到文件中(尽管它们是可存储的).
I need to highlight a list of words in vim, preferably the words should be defined in a file. A bit like spell checking. I have been looking at http://vim.wikia.com/wiki/Highlight_multiple_words but it requires that I define each word as a new position and does not support storing the words to a file (though they are storable).
推荐答案
您可以使用 :match
命令.
:match Todo /word1/
命令的第一个参数是highlight-group(查看所有可用的组:highlight
).第二个参数是搜索模式.
The first parameter of the command is the highlight-group (to see all available groups :highlight
). The second parameter is a search pattern.
您可以将它们放在任何文件中并通过 :source
加载.
You can put these in any file and load it via :source
.
另一种方法是改变正则表达式(thx @zpon):
Another way is to change the regular expression (thx @zpon):
:match Todo /word1\|word2\|word3/
如果您想以不同的方式突出显示它们:
If you want to highlight them differently:
:match Todo /word1/
:2match Error /word2/
:3match Title /word3/
这篇关于Vim 突出显示单词列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!