I feel like the way I do 80-column indication in Vim is incorrect: set columns=80
. At times I also set textwidth
but I like to be able to see and anticipate line overflow with the set columns
alternative.
This has some unfortunate side effects -- I can't set number
for fear of splitting between files that have different orders of line numbers; i.e. < 100 line files and >= 100 line files will require two different set columns
values because of the extra column used for the additional digit display. I also start new (g)Vim sessions instead of splitting windows vertically, which forces me to use the window manager's clipboard -- vsplit
s force me to do set columns
every time I open or close a pane, so starting a new session is less hassle.
How do you handle the 80-character indication when you want to set numbers
, vertically split, etc.?
As of vim 7.3, you can use
set colorcolumn=80
(set cc=80
for short).Since earlier versions do not support this, my
.vimrc
uses instead:See also the online documentation on the
colorcolumn
option.Simon Howard's answer is great. But
/\%81v.\+/
fails to highlight tabs that exceed column 81 . So I did a little tweak, based on the stuff I found on VIM wiki and HS's choice of colors above:And now VIM will highlight anything that exceed column 80. Cheers!
You can try this to set the window size to allow 80 characters of actual text. This still doesn't work with vertical splits though.
let &co=80 + &foldcolumn + (&number || &relativenumber ? &numberwidth : 0)
This requires vim 7+, 7.3 for relativenumber.
You also can draw line to see 80 limit:
Result:
this one is out of left field but its a nice little map for resizing your current split to 80 characters if you've got the line numbers on:
Minimalistic, not-over-the-top approach. Only the 79th character of lines that are too long gets highlighted. It overcomes a few common problems: works on new windows, overflowing words are highlighted properly.
Note: notice the
FileType scala,java
this limits this to Scala and Java source files. You'll probably want to customize this. If you were to omit it, it would work on all file types.