gpt4 book ai didi

以 ; 开头的行的 Vim 自定义高亮显示

转载 作者:行者123 更新时间:2023-12-04 21:57:41 24 4
gpt4 key购买 nike

我想为我的模板文件 *.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"/

最佳答案

你的正则表达式:

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

像这样匹配行:

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

但只有;commenttext突出显示。

如果你想拥有:

I would like to mark the lines that start with ;

试试这个:

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

注意我用了\w*而不是 .*因为你在你的正则表达式中写了它,我假设你想匹配 \w仅有的。如果你想 hi 整行,不管是否有空格(或其他 \W s),使用 .* ,例如:

  syn match tmp /^\s*;.*$/

关于以 ; 开头的行的 Vim 自定义高亮显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15701808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com