vimtricks.wiki Concise Vim tricks, one at a time.

How do I display multiple column guide lines at different widths simultaneously in Vim?

Answer

:set colorcolumn=80,120

Explanation

colorcolumn highlights one or more screen columns to serve as a visual ruler. Setting it to multiple values draws guides at each specified column width, making it easy to enforce different line length limits for different contexts — for example, a soft 80-column wrap limit and a hard 120-column maximum.

How it works

  • :set colorcolumn=80 — highlights column 80 with the ColorColumn highlight group
  • :set colorcolumn=80,120 — highlights both columns 80 and 120 simultaneously
  • :set colorcolumn=+1 — highlights the column one past textwidth (relative offset)
  • :set colorcolumn= — clears all column guides

The highlight color is controlled by the ColorColumn group, which you can override:

:highlight ColorColumn ctermbg=237 guibg=#3a3a3a

Example

To mark both the conventional 79-character PEP 8 Python limit and an absolute 99-character hard limit:

:set colorcolumn=79,99

For a project-wide setting using textwidth as the primary limit:

:set textwidth=100 colorcolumn=+1

Tips

  • Use +N offsets so the guide automatically tracks textwidth changes
  • Set per-filetype in your config: autocmd FileType python setlocal colorcolumn=79,99
  • In Neovim, you can use vim.opt.colorcolumn = { '80', '120' } in Lua

Next

How do I quickly configure Vim to parse compiler errors for a specific language using a built-in compiler plugin?