Last Updated: February 25, 2016
·
603
· galvao

PSR-2 Character limit visual aid for (G)Vim

One of the things that's not easy for people who aren't used to imposing lenght limits on line codes is to respect the 120 character mark as PSR-2 demands.

I've just found out an easy visual aid so you can see if you trespassed the limit on Vim (or GVim):

Insert this on your .vimrc:

let &colorcolumn=join(range(121,999),",")

This will set a different background color for column 121 onwards, making it easy to detect the trespassing.

You can also adjust the colors, so if you use a dark theme (in my case Monokai) the 'valid area' background color doesn't get confused with the highlighted line background color:

:hi CursorLine   cterm=NONE ctermbg=black guibg=black

cterm means Vim and gui means GVim.

You may even set a foreground color for the highlighted line:

:hi CursorLine   cterm=NONE ctermbg=black ctermfg=white guibg=black guifg=white

I didn't in order to avoid losing the syntax coloring.

Happy coding!

References: