2

我想为我的模板文件生成一个自定义突出显示规则*.tmpl,即我想标记以开头的行;- 这些是注释行。

我在我的.vimrc

au BufRead,BufNewFile *.tmpl hi tmpl ctermfg=2 ctermbg=3
au BufRead,BufNewFile *.tmpl syn match tmpl /"\zs;\w*\ze"/

但它没有用。

我将 Vim 7.2 与+syntax.

那是我的.vimrc

执行病原体#infect() 设置编号

set clipboard=unnamedplus
set t_Co=256

syntax enable
set background=dark
let g:solarized_termcolors=256
colorscheme solarized

filetype plugin indent on

let g:Powerline_symbols = 'fancy'
set hlsearch

au BufRead,BufNewFile *.tmpl hi tmpl ctermfg=2 ctermbg=3
au BufRead,BufNewFile *.tmpl syn match tmpl /"\zs;\w*\ze"/
4

1 回答 1

6

你的正则表达式:

/"\zs;\w*\ze"/

匹配这样的行:

foo";commenttext"
";commenttext"bar
foo";commenttext"bar

但仅;commenttext突出显示。

如果你想拥有:

我想标记以 ; 开头的行

试试这个:

  syn match tmp /^\s*;\w*/

请注意,我使用\w*而不是.*因为您在正则表达式中编写了它,所以我假设您只想匹配\w。如果你想整行,不管有没有空格(或其他\Ws),使用.*,例如:

  syn match tmp /^\s*;.*$/
于 2013-03-29T11:14:08.197 回答