I have the following in my .vimrc:

:set colorcolumn=81

This sets the background color of every window's 81st column to red. I would like to disable this for "pop-up" windows like syntastic's error display window or jedi's docstring window. Since buffers similar to these are usually non-modifiable I thought I might be able to only active colorcolumn for modifiable buffers but I can not figure out how.

  • Should be no problem with an autocommand with event, oh, BufReadPost probably. Have it check the newly opened buffer and set colorcolumn only when desired conditions exist. – B Layer Aug 10 '18 at 20:39
  • See my edit, I get what you mean but I'm not sure on the details. – Peter Aug 10 '18 at 20:48
  • All right. Good job. Add it as an answer. – B Layer Aug 10 '18 at 21:05

I'm adding my solution as an answer, the following snippet solves my problem:

autocmd BufWinEnter * call SetColorColumn()

function! SetColorColumn()
    if &modifiable
        set colorcolumn=81
        set colorcolumn&
  • Can be shorter as: autocmd BufwinEnter * let &l:colorcolumn = &modifiable ? 81 : 0 – probably also better to use &l: (which sets the local variable, like setlocal) instead of setting the global one. – Martin Tournoij May 8 '19 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.