如何让 vim 语法高亮整行?
我想让 vim 突出显示与某些模式匹配的整行。我可以突出显示一行中的所有文本(通过执行 syn match MyMatch "^.*text-to-match.*$"
),但它总是停在文本末尾。我想继续到学期结束,比如突出显示 CursorLine。
我尝试用 \n^
替换 $
,希望能将其包裹起来。没有变化。 (我实际上并没有想到这会起作用,但是尝试也没有什么坏处。)我还尝试调整 syn-pattern-offset (我在这里读到了:http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern)。长话短说,添加 he=he-5
将突出显示少 5 个字符,但 he=he+5
不会显示任何额外字符,因为没有字符可显示强调。
这是我第一次尝试制作 vim 语法,而且我对 vim 还比较陌生。请保持温和并提供解释。
谢谢!
(编辑:忘记包含,这是多行突出显示。这可能会增加一点复杂性。)
I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"
), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $
with a \n^
, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5
will highlight 5 fewer characters, but he=he+5
doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它的适应性不是很强,因为需要明确标识文件名(缓冲区)和行到整行突出显示,但显然 sign 命令:
来源: Erik Falor,vim 邮件列表
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
source: Erik Falor, vim mailing list
来自
syn-pattern
的文档:如果你能做到这一点,我会感到很惊讶,但话又说回来,Vim 总是充满惊喜。
From the documentation on
syn-pattern
:I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
也可以尝试
:设置光标线
:设置光标列
像这样改变颜色:
:嗨光标线
:嗨光标栏
使用常用术语=、ctermfg=、ctermbg= 等
看到这个答案
VIM 突出显示整个当前行
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line