简体   繁体   中英

How do I make vim syntax highlight a whole line?

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.)

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:

It is possible to highlight an entire line using the :sign mechanism.
An example can be found at :help sign-commands
In a nutshell:

:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt

Obviously, you should pick a higlight group that changes the color of the background for the linehl argument.

source: Erik Falor, vim mailing list

From the documentation on syn-pattern :

The highlighted area will never be outside of the matched text.

I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.

也可以尝试:设置cursorline:设置cursorcolumn更改颜色如下:: hi cursorline:hi cursorcolumn使用通常的term =,ctermfg =,ctermbg =等查看此答案VIM突出显示整个当前行

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM