vim对多个关键字高亮

很早就有这个需求了,但是一直没有找到合适的插件,直到昨天再也按耐不住了。于是就找到了mark这个插件,简单用了几下还可以,更多的功能待以后挖掘。

下载

直接从vim的官网下载:mark.vim就行了。
但是呢,mark.vim的后爹Ingo Karkat在开发mark.vim的时候使用了他自己的一个基础库,也就是说mark.vim还依赖另一个vim,得先装那个库ingo-library

为啥说Ingo Karkat是后爹呢,据后爹的description一栏介绍,Mark的生父Yuheng Xie 已经抛弃了它。于是呢怀着八卦的心就查看了一下Mark的日志,从2009-06-07开始,Ingo Karkat开始上传了第一版Mark,一直到2019-03-24的3.1.0版本,这期间都在时不时的更新着。

再打开Yuheng Xie的Mark后看到也有时不时的更新。且最新的更新记录是2019-01-30,也并不是抛弃了啊。

算了,我好象是跑题了。

前面的都是废话。

整理一下。

我使用的是Ingo Karkat的版本Mark。

需要下载的有:

  1. Ingo-library 传送门
  2. Mark 传送门

我使用的下载方法是git clone.
即在任意目录使用git clone下来这两个插件,然后将下载下来的所有文件copy到~/.vim中就行了。这就是安装了。
下面是下载后的文件结构:

zz@zz:~/.vim/test$ ls
vim-ingo-library  vim-mark
zz@zz:~/.vim/test$ ls vim-mark/
autoload  doc  mark.manifest  plugin  README.md
zz@zz:~/.vim/test$ 
zz@zz:~/.vim/test$ 
zz@zz:~/.vim/test$ 
zz@zz:~/.vim/test$ ls vim-ingo-library/
autoload  doc  ingo-library.manifest  README.md  tests
zz@zz:~/.vim/test$ 

还有一种安装方法是下载vimball,然后用so %来安装,但是我用这种方法安装没有成功,以后再研究一下。

安装完之后就可以用了。
使用很简单,参考说名中的这一段:

USAGE
HIGHLIGHTING
<Leader>m               Mark the word under the cursor, similar to the star
                        command. The next free highlight group is used.
                        If already on a mark: Clear the mark, like
                        <Leader>n.
{Visual}<Leader>m       Mark or unmark the visual selection.
{N}<Leader>m            With {N}, mark the word under the cursor with the
                        named highlight group {N}. When that group is not
                        empty, the word is added as an alternative match, so
                        you can highlight multiple words with the same color.
                        When the word is already contained in the list of
                        alternatives, it is removed.

                        When {N} is greater than the number of defined mark
                        groups, a summary of marks is printed. Active mark
                        groups are prefixed with "*" (or "M*" when there are
                        M pattern alternatives), the default next group with
                        ">", the last used search with "/" (like :Marks
                        does). Input the mark group, accept the default with
                        <CR>, or abort with <Esc> or any other key.
                        This way, when unsure about which number represents
                        which color, just use 99<Leader>n and pick the color
                        interactively!

{Visual}[N]<Leader>m    Ditto, based on the visual selection.

[N]<Leader>r            Manually input a regular expression to mark.
{Visual}[N]<Leader>r    Ditto, based on the visual selection.

                        In accordance with the built-in star command,
                        all these mappings use 'ignorecase', but not
                        'smartcase'.

<Leader>n               Clear the mark under the cursor.
                        If not on a mark: Disable all marks, similar to
                        :nohlsearch.
                        Note: Marks that span multiple lines are not detected,
                        so the use of <Leader>n on such a mark will
                        unintentionally disable all marks! Use
                        {Visual}<Leader>r or :Mark {pattern} to clear
                        multi-line marks (or pass [N] if you happen to know
                        the group number). 

在terminal中输入<Leader>m就行了,咋输入<Leader>呢?
搜索后了解到<Leader>是一个映射,可以把它改成其他的符号,如果没改过的话默认值就是\,也就是依次敲按键\m就行了。这时光标所在的单词就会高亮,将光标移动到下一个需要高亮的字符后,再依次敲按键\m,就会自动使用另一种颜色高亮关键字。

取消高亮的方法是在关键字上依次敲按键\n,

相同颜色的关键字间跳转的命令是 按键\*, 按键*就是要Shift和数字8一起按下。

跳回上一个相同颜色的是按键\#

任意颜色间的关键字跳转命令是\/,即不管颜色,只要是被高亮了,就顺序的往下一个跳。

任意颜色跳回上一个按键是\?,也就是按完\之后,一起按下shift+/

上面的都是从文章开头向文章结尾跳,如果往回跳暂时还没有找到方法,还有更改高亮组的颜色顺序等其他功能稍后再研究。下图是多个高亮的效果:

在这里插入图片描述补充1:
修改高亮颜色组的方法:
在.vimrc里面添加:

按照mark.vim的这一段说明:

If none of the default highlightings suits you, define your own colors
in your vimrc file (or anywhere before this plugin is sourced, but
after any :colorscheme), in the following form (where N = 1…):
highlight MarkWordN ctermbg=Cyan ctermfg=Black guibg=#8CCBEA guifg=Black

对应的操作为:

111 "========================================================
112 "for mark.vim
113 "========================================================
114 highlight MarkWord1 ctermbg=Green ctermfg=White guibg=#8CCBEA guifg=Black
115 highlight MarkWord2 ctermbg=Cyan ctermfg=White guibg=#8CCBEA guifg=Black
116 highlight MarkWord3 ctermbg=Yellow ctermfg=White guibg=#8CCBEA guifg=Black
117 highlight MarkWord4 ctermbg=Red ctermfg=White guibg=#8CCBEA guifg=Black
118 highlight MarkWord5 ctermbg=Blue ctermfg=White guibg=#8CCBEA guifg=Black
119 highlight MarkWord6 ctermbg=Magenta ctermfg=White guibg=#8CCBEA guifg=Black
120 

猜你喜欢

转载自blog.csdn.net/k7arm/article/details/103556376