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

Is there a way to make Vim warn me after a line has exceeded n characters?

Something simple like a screen flash or the text go bold red or something.

!! Bonus points if n can be made a variable that is easy to set in each individual window (I use 80 columns usually, but 100 columns for PHP).

share|improve this question
up vote 4 down vote accepted

There are two possible solutions:

  1. If your version of Vim is 7.3 at least, just set 'colorcolumn' option (see :help 'colorcolumn'), e.g. to 81

    set colorcolumn=81

  2. Since 'colorcolumn' adds only one column or if you have Vim version prior to 7.3, you may want to define custom highlight rule too highlight all characters after specific column, e.g.:

    syn match tooLong /\%81c.*$/ hi link tooLong Error

To have different settings for different file types, put this commands to appropriate filetype plugin (for example to ~/.vim/ftplugin/cpp.vim). Or define autocommands (see :help :autocmd) triggered by FileType event (see :help FileType) in your .vimrc.

share|improve this answer
thanks, colorcolumn serves the purpose. – iDontKnowBetter Aug 28 '12 at 0:34
or if you want to shorten it :set cc=80 – Braden Sep 2 '12 at 16:01

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.