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

How do I display a vertical line at a specific column width?

Answer

:set colorcolumn=80

Explanation

The :set colorcolumn=80 command displays a vertical highlight at column 80, giving you a visual guide for line length. This is invaluable for keeping your code within a consistent width, following style guides, and maintaining readability.

How it works

  • colorcolumn (or cc for short) accepts a comma-separated list of column numbers
  • Vim draws a highlighted vertical stripe at each specified column
  • The highlight color is controlled by the ColorColumn highlight group

Example

To show a guide at column 80:

:set colorcolumn=80

To show guides at both column 80 and column 120:

:set colorcolumn=80,120

You can also use a relative value based on textwidth:

:set textwidth=80
:set colorcolumn=+1

This places the color column one column after textwidth, at column 81.

Removing the color column

To turn off the color column entirely:

:set colorcolumn=

Customizing the color

The default color column highlight can be customized:

highlight ColorColumn ctermbg=235 guibg=#2c2d27

Tips

  • Use :set cc=80 as the short form — cc is an abbreviation for colorcolumn
  • Add set colorcolumn=80 to your vimrc to enable it permanently
  • Use set colorcolumn= (empty value) to disable it when the visual guide is distracting
  • Combine with :set textwidth=80 and the gq operator to both visualize and enforce line length limits
  • Some developers prefer a subtle background color so the column is visible but not distracting — experiment with highlight values to find what works for you
  • The color column is per-window, so different splits can have different settings

Next

How do I edit multiple lines at once using multiple cursors in Vim?