Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some GUI text editors have a vertical line which serves as line length marker (it helps keeping lines shorter than 80 chars in source code files).

Is is possible to have something similar in vim/gvim? I know about ruler vim option, but it is not very handy to follow it visually on a big screen.

Edit: when googling for "colorcolumn" to learn more, I have found that this question is a duplicate of

share|improve this question
up vote 62 down vote accepted

Just execute this

:set colorcolumn=72

You can also prefix the argument with - or + to put the marker that many columns to the left or right of textwidth, and it accepts a comma-separated list of columns. I think the colorcolumn option is only in Vim 7.3. See

:help colorcolumn
share|improve this answer
Wow, vim never ceases to amaze me! – Peter Nore Jun 21 '11 at 2:38
Nice! Also useful when columns=80, wrap is set and colorcolumn=81,161,241,321,401,481,561,641,721,801 – shows up to 10 wrapped lines with the first column highlighted. – Amir Jun 11 '12 at 15:45

From Damian Conway's "More Instantly Better Vim" talk at OSCON 2013:

highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)

This results in the character being highlighted in magenta (the screenshot is in DarkCyan) when the line goes over the 80-character maximum.

vim with highlighting enabled

For gVim: it's best to move those 2 lines to the last part of your .vimrc file to ensure it works.

share|improve this answer
Huh! I just answered your very similar question about this... small world!… – lornix Jun 21 '14 at 5:29
I put this answer in, then remembered I couldn't do it in gVim, so I asked. ;) – Isxek Jun 21 '14 at 6:18

Below is a clumsy trick from Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor by Kim Schultz.

It highlights with ErrorMsg (usually bright red) any lines that go over 80 characters. Works well for me.

function! RemoveWidthLimitWarnigns()
    silent! call matchdelete(4)
function! InsertWidthLimitWarnings()
    call RemoveWidthLimitWarnigns()
    call matchadd("ErrorMsg", "\\%>79v.\\+", 10, 4)
share|improve this answer
What am I supposed to do with this snippet? Just stick it into .vimrc? – vtest Feb 24 '11 at 16:02
Trying first by just calling :call matchadd("ErrorMsg", "\\%>79v.\\+", 10, 4) suffices. But I wouldn't recommend this anymore since @garyjohn knew something better – progo Feb 24 '11 at 17:40

You could try this:

grep '.\{81\}' file


set colorcolumn=80

(or the shorthand equivalent)

set cc=80

or as aforementioned:

match ErrorMsg '\%>80v.\+'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.