Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to show colorcolumn only in insert mode of Vim

📅 2013-Feb-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ colorcolumn, guideline, vim ⬩ 📚 Archive

I like to have the colorcolumn enabled in Vim. I use it as a guideline to remind me when my code line is too long or nesting is too deep. As such, it is useful only in insert mode and is distracting the rest of the time.

To show colorcolumn only in insert mode, add this to your vimrc:

augroup ColorcolumnOnlyInInsertMode
  autocmd!
  autocmd InsertEnter * setlocal colorcolumn=80
  autocmd InsertLeave * setlocal colorcolumn=0
augroup END

The number assigned to colorcolumn is the column at which the guideline is drawn. 0 means no guideline is displayed.

Tried with: Vim 7.3 and Ubuntu 12.04 LTS


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧