Vim: highlight word wrap column in insert mode
« Recursive Sum
» Queue Zero
I like vim’s
colorcolumn for highlighting where word wrap will occur, but I consider it a distraction when I’m not in insert mode. After some tinkering, I wrote this in my
" highlight textwidth column in insert mode highlight ColorColumn ctermbg=0* function! HighlightOn() if &textwidth > 0 " the +1 feature in the 'colorcolumn' docs doesn't work for me let &colorcolumn=&textwidth + 1 else let &colorcolumn="" endif endfunction autocmd InsertEnter * :call HighlightOn() autocmd InsertLeave * let &colorcolumn=""
That note about
+1 is me working around a bug. I should be able to just write:
" highlight textwidth column in insert mode highlight ColorColumn ctermbg=0* autocmd InsertEnter * let &colorcolumn=+1 autocmd InsertLeave * let &colorcolumn=""
Unfortunately, some tweak or plugin breaks this feature for me. I wrote this workaround rather than diagnose and fix it properly because the process just seemed too tedious.