Search code examples
vimidevicobolnerdtree

How to change column colors in the NERDTree only


I would like to set up VIM for Cobol development and wanted to have the lines form column 7 to 11 marked so as to indicate the code areas. However, when I added this line of code in my vimrc file it colorized the NERDTree too.

set colorcolumn=7,11,73,80
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p

How can I make the NERDTree columns not colorized and keep colorization only on the working file?

See a pic of my cobol file on VIM


Solution

  • With the following line in your vimrc:

    set colorcolumn=7,11,73,80
    

    you define a global value for a window-local option which is reused for every new window. It is set for the 1st window, which passes it on to the 2nd window, etc.

    Since that specific value for that specific option only is to be applied to Cobol buffers, you are supposed to use Vim's built-in filetype plugin support:

    1. Make sure you have either of those lines in your vimrc:

      filetype plugin on
      filetype plugin indent on
      filetype indent plugin on
      

      See :help :filetype.

    2. Create after/ftplugin/cobol.vim under your Vim runtime. On a typical Unix system, it should look like this:

      $HOME/.vim/after/ftplugin/cobol.vim
      
    3. And add the line below:

      setlocal colorcolumn=7,11,73,80
      

      We use :help :setlocal to make sure that the option won't be passed on to other windows.