22

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?

Community
  • 1
  • 1
davetron5000
  • 24,123
  • 11
  • 70
  • 98

3 Answers3

35

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
dchest
  • 1,525
  • 18
  • 20
22

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.

sykora
  • 96,888
  • 11
  • 64
  • 71
  • Yes! That works well; I wasn't wrapping my head around the fact that this is a way to "highlight long lines" (which your link is the first hit for). – davetron5000 May 06 '09 at 18:18
1
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! So basically you wont be able to see highlighted search items beyond that margin...

expelledboy
  • 2,033
  • 18
  • 18