Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background color in vim at a certain column

Tags:

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?). A lot of IDEs have this. I mocked up what I'm talking about:

Anyone know if this can be done in macvim or gvim?

like image 820
davetron5000 Avatar asked May 06 '09 16:05

davetron5000


2 Answers

Since Vim 7.3 it's possible to have columns highlighted like this:

Screenshot of MacVim with highlighted column

To set it to the current 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 
like image 117
dchest Avatar answered Oct 14 '22 04:10

dchest


Try this:

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

It will highlight text beyond 80 characters, you can replace '80' with whatever wrap-width you have. 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.

like image 31
sykora Avatar answered Oct 14 '22 03:10

sykora