vimcharacter-limit

Vim 80 character line in specific files


I've recently started to use Vim. I set 80 character line in .vimrc, using follow command:

set colorcolumn=80

But this line is displayed not in all files. Look at screenshots below:

enter image description here enter image description here

My .vimrc is here. Does anybody know, what problem is?


Solution

  • You have the following lines scattered within your vimrc:

    " higlight column right after max textwidth
    set colorcolumn=+1
    
    " Disable vertical line at max string length in NERDTree
    autocmd FileType * setlocal colorcolumn=+1
    autocmd FileType nerdtree setlocal colorcolumn=""
    
    set colorcolumn=80
    

    Also relevant is the fact that you have not apparently set 'textwidth' to anything, so it should be at its default value of zero, and from the vim help on 'colorcolumn':

    When 'textwidth' is zero then the items with '-' and '+' are not used.

    So, what I suspect is happening is that the autocommand with * as the wildcard is running and setting colorcolumn=+1, which is basically disabling it, since 'textwidth' is zero.

    Thus, you can solve the problem by either ensuring 'textwidth' is set, or removing the autocommand. And, more generally, you should clean up your various settings of 'colorcolumn' within your vimrc to not negate / interfere with one another.