Changing background color in vim at a certain column

davetron5000 picture davetron5000 · May 6, 2009 · Viewed 8.8k times · Source

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?

Answer

dchest picture dchest · Jul 1, 2011

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