Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.