我想为我的模板文件*.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"/
答案 0 :(得分:6)
你的正则表达式:
/"\zs;\w*\ze"/
匹配这样的行:
foo";commenttext"
";commenttext"bar
foo";commenttext"bar
但只突出显示;commenttext
。
如果你想拥有:
我想标记以...开头的行;
试试这个:
syn match tmp /^\s*;\w*/
注意我使用\w*
代替.*
,因为您在正则表达式中编写了它,我假设您只想匹配\w
。如果您想要整行,无论是否有空格(或其他\W
s),请使用.*
,例如:
syn match tmp /^\s*;.*$/