How do I highlight the column just past my textwidth to visually mark line length limits?
Answer
set colorcolumn=+1
Explanation
The colorcolumn option highlights one or more vertical columns to help keep lines within a length limit. Values prefixed with + or - are relative to textwidth, so the guide column automatically follows if you ever change your line length setting.
How it works
set colorcolumn=80— absolute: always highlights column 80set colorcolumn=+1— relative: highlights the column one pasttextwidthset colorcolumn=-0— highlights exactly attextwidth
With set textwidth=79, set colorcolumn=+1 highlights column 80. If you later do set textwidth=119, the highlight automatically moves to column 120 without touching colorcolumn.
Example
set textwidth=79
set colorcolumn=+1
Column 80 is now highlighted in a different color. Any text reaching that column is clearly past the limit. After set textwidth=99, column 100 becomes highlighted instead.
Tips
- You can highlight multiple columns:
set colorcolumn=+1,+2,+3to show a gradient zone - Customize the highlight color with
:hi ColorColumn guibg=#333333 - Use
set colorcolumn=(empty) to disable the highlight entirely - The relative form only works when
textwidthis non-zero; otherwise it has no effect - Combine with
set wrapandset linebreakfor a visual guide that complements soft wrapping