简体   繁体   English

在某个列的vim中更改背景颜色

[英]Changing background color in vim at a certain column

I'd like to be able to highlight the wrap margin/text width in vim by changing the background color (or maybe just a line?). 我想通过改变背景颜色(或者只是一条线?)来突出显示vim中的包边/文本宽度。 A lot of IDEs have this. 很多IDE都有这个。 I mocked up what I'm talking about: 我嘲笑我在说什么:

Anyone know if this can be done in macvim or gvim? 有人知道这可以在macvim或gvim中完成吗?

Since Vim 7.3 it's possible to have columns highlighted like this: 从Vim 7.3开始,可以像这样突出显示列:

带有突出显示列的MacVim的屏幕截图

To set it to the current textwidth : 要将其设置为当前textwidth

:set cc=+1

Or you can set it to predefined value: 或者您可以将其设置为预定义值:

:set cc=80

You can change its color like this: 你可以改变它的颜色:

:hi ColorColumn ctermbg=lightgrey guibg=lightgrey

See help for more details: 有关详细信息,请参阅帮助

:help colorcolumn

Try this: 尝试这个:

:match ErrorMsg '\%>80v.\+'

It will highlight text beyond 80 characters, you can replace '80' with whatever wrap-width you have. 它将突出显示超过80个字符的文本,您可以用您拥有的任何包装宽度替换“80”。 However, it will only highlight the characters that exceed the width, and then only on lines that are actually longer than the width. 但是,它只会突出显示超出宽度的字符,然后才会突出显示实际长于宽度的行。

Check http://vim.wikia.com/wiki/Highlight_long_lines for more info, but they all pretty much accomplish the same thing. 查看http://vim.wikia.com/wiki/Highlight_long_lines了解更多信息,但他们几乎完成了同样的事情。

autocmd FileType * execute "setlocal colorcolumn=" . join(range(&textwidth,250), ',')
highlight ColorColumn guibg=#303030 ctermbg=0

Big problem with this is that the colorcolumn highlighting has higher priority then hlsearch! 这个问题很大,颜色列突出显示优先于hlsearch! So basically you wont be able to see highlighted search items beyond that margin... 所以基本上你不能看到超出该边际的突出显示的搜索项目......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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