Vim Line Length Marker
Since version 7.3, Vim includes a way to highlight a line length by coloring a specific column of text. Many teams enforce a line length limit as a coding standard and this feature provides a useful visual indicator. Vim’s line length marker is called a “color column” (see
:help colorcolumn) . In fact, it can be multiple columns in case you wish to highlight several increments across the width of your text. Here’s how to use Vim’s colorcolumn:
Vim Line Length Marker Options
There are two ways to use the
colorcolumn setting: using absolute numbers or relative numbers. In the case of absolute, simply use
set colorcolumn=100 where
100 is the column number you wish to highlight. You can just run this command in your present buffer or place that statement in your
In the case of relative numbers, use
set colorcolumn=+1 or
1 is a number relative to the current
textwidth value you have set. Use
+0 to have the marker directly on your max text width. The advantage of using relative numbers is that if you have different text width settings for different file types, the
colorcolumn setting will respect that difference. (See our post about changing Vim settings by file type.).
Multiple Color Columns in Vim
You can actually pass a comma-separated list of values to
set colorcolumn and Vim will highlight up to 256 different columns. This can be useful when you want to evenly space text across a page or even show when text is wrapped along a long line.
Vim colorcolumn Demo
In the demo below, I first show how to use multiple color columns to highlight everything after a certain width on my screen. My initial setting is
colorcolumn=60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80 Then I show several columns evenly spaced with
colorcolumn=20,40,60 and finally I use
colorcolumn=+0 to display the line width marker exactly on my textwidth setting, which is
How do I enable a line length marker in Vim?
colorcolumnsetting to enable a line length marker in Vim. The value of this setting will enable a visual highlight at that particular line length. Use a relative number like
-1to have the value offset from your
textwidthsetting or an absolute number like
80to show the marker that that specific width.
How can I change the color of the Vim colorcolumn?
highlightsetting. For example the following will show the color column in red:
highlight ColorColumn ctermbg=1
Can I highlight multiple columns in Vim?
colorcolumnsetting such as:
Can I abbreviate colorcolumn?
cc. However, since space is not at a premium in your config, we recommend leaving the full name for clarity. The
ccshort name can be useful when setting a quick line length marker in the current Vim window on a one-off basis.
What are the Vim colorcolumn docs?
colorcolumnis a comma separated list of screen columns that are highlighted with ColorColumn. Useful to align text. Will make screen redrawing slower. The screen column can be an absolute number, or a number preceded with + or
-, which is added to or subtracted from
:set cc=+1 " highlight column after 'textwidth' :set cc=+1,+2,+3 " highlight three columns after 'textwidth' :hi ColorColumn ctermbg=lightgrey guibg=lightgreyWhen
textwidthis zero then the items with
+are not used. A maximum of 256 columns are highlighted.
Does colorcolumn work in Neovim?
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?