在我的vimrc中,对ShowMarks进行了如下配置: """""""""""""""""""""""""""""" " showmarks setting """""""""""""""""""""""""""""" " Enable ShowMarks let showmarks_enable = 1 " Show which marks let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" " Ignore help, quickfix, non-modifiable buffers let showmarks_ignore_type = "hqm" " Hilight lower & upper marks let showmarks_hlline_lower = 1 let showmarks_hlline_upper = 1 首先,使能showmarks插件,然后定义showmarks只显示全部的大写标记和小写,并高亮这两种标记;对文件类型为help, quickfix, 和不可修改的缓冲区,不显示标记的位置。 你可以定义自己的颜色来高亮标记所在的行,下面是我的定义,我把它放在我自己的colorscheme文件中: " For showmarks plugin hi ShowMarksHLl ctermbg=Yellow ctermfg=Black guibg=#FFDB72 guifg=Black hi ShowMarksHLu ctermbg=Magenta ctermfg=Black guibg=#FFB3FF guifg=Black ShowMarks插件中已经定义了一些快捷键:
mt - 打开/关闭ShowMarks插件 mo - 强制打开ShowMarks插件 mh - 清除当前行的标记 ma - 清除当前缓冲区中所有的标记 mm - 在当前行打一个标记,使用下一个可用的标记名 我最常使用的是“mm”和“mh”,用起来非常方便。 在VIM 7.0中,如果大写的标记被定义了,那么函数line()无论在哪个缓冲区里都会返回该标记的行号,导致showmarks在每个缓冲区里都会把这个大写标记显示出来。因此我为这个插件打了个补丁来修正此问题。 VIM 7.0中也可以真正的删除一个mark标记,所以也改了showmarks插件的删除标记功能。原来的功能在删除标记时,并未真正删除它,只是把这个标记指向缓冲区的第一行;现在则是真正删除此标记。 补丁的内容如下: --- easwy/showmarks.vim 2007-03-13 10:15:07.000000000 +0800 +++ plugin/showmarks.vim 2007-03-23 09:35:01.000000000 +0800 @@ -144,6 +144,25 @@ hi default ShowMarksHLo ctermfg=darkblue ctermbg=blue cterm=bold guifg=blue guibg=lightblue gui=bold hi default ShowMarksHLm ctermfg=darkblue ctermbg=blue cterm=bold guifg=blue guibg=lightblue gui=bold
+" Function: GetMarkLine() +" Authors: Easwy Yang +" Description: This function will return the line number where the mark +" placed. In VIM 7.0 and later, function line() always returns line number but +" not 0 in case an uppercase mark or number mark is placed. However, in VIM 6, +" it only returns 0 when the uppercase mark isn't placed in current file. +fun! s:GetMarkLine(mark) + if v:version < 700 + let lnum = line(a:mark) + else + let pos = getpos(a:mark) + let lnum = pos[1] + if pos[0] && bufnr("%") != pos[0] + let lnum = 0 + endif + endif + return lnum +endf + " Function: IncludeMarks() " Description: This function returns the list of marks (in priority order) to " show in this buffer. Each buffer, if not already set, inherits the global @@ -354,7 +373,8 @@ let c = strpart(s:IncludeMarks(), n, 1) let nm = s:NameOfMark(c) let id = n + (s:maxmarks * winbufnr(0)) - let ln = line("'".c) + "let ln = line("'".c) + let ln = s:GetMarkLine("'".c)
if ln == 0 && (exists('b:placed_'.nm) && b:placed_{nm} != ln) exe 'sign unplace '.id.' buffer='.winbufnr(0) @@ -393,11 +413,18 @@ let s:maxmarks = strlen(s:IncludeMarks()) while n < s:maxmarks let c = strpart(s:IncludeMarks(), n, 1) - if c =~# '[a-zA-Z]' && ln == line("'".c) + "if c =~# '[a-zA-Z]' && ln == line("'".c) + if c =~# '[a-zA-Z]' && ln == s:GetMarkLine("'".c) let nm = s:NameOfMark(c) let id = n + (s:maxmarks * winbufnr(0)) exe 'sign unplace '.id.' buffer='.winbufnr(0) - exe '1 mark '.c + " Easwy, we can really remove marks in VIM 7.0 and later + if v:version >= 700 + exe 'delm '.c + else + exe '1 mark '.c + endif + " Easwy, end let b:placed_{nm} = 1 endif let n = n + 1 @@ -417,7 +444,13 @@ let nm = s:NameOfMark(c) let id = n + (s:maxmarks * winbufnr(0)) exe 'sign unplace '.id.' buffer='.winbufnr(0) - exe '1 mark '.c + " Easwy, we can really remove marks in VIM 7.0 and later + if v:version >= 700 + exe 'delm '.c + else + exe '1 mark '.c + endif + " Easwy, end let b:placed_{nm} = 1 endif let n = n + 1 @@ -466,7 +499,8 @@ while n < s:maxmarks let c = strpart(s:IncludeMarks(), n, 1) if c =~# '[a-z]' - if line("'".c) <= 1 + "if line("'".c) <= 1 + if s:GetMarkLine("'".c) <= 1 " Found an unused [a-z] mark; we're done. let next_mark = n break 用法: 1. 保存该patch到某一目录,例如:/tmp/showmarks.vim.patch 2. cd到你的.vim目录:cd ~/.vim 3. 运行命令:cat /tmp/showmarks.vim.patch | patch -p0 Marks Browser可以显示出当前缓冲区中定义的小写标记的位置,在你无法对应上标记的名字和其位置时,非常有用。这个插件在此下载: