How do I search for and highlight text that exceeds a specific column width like 80 or 120?
Answer
/\%>80v.
Explanation
The pattern /\%>80v. matches any character positioned after virtual column 80, highlighting all text that exceeds your line-width limit. The \%>Nv assertion is a zero-width match that succeeds only when the cursor is past virtual column N — making it perfect for finding long-line violations without modifying your file.
How it works
\%>80v— a zero-width virtual column assertion that only matches at positions beyond column 80 (vmeans virtual column, honoring yourtabstopsetting).— matches any character at that position (the actual character you want to highlight)- Together they match all characters in lines longer than 80 columns
Virtual column (v) is important: it uses the visual width after tab expansion, so a tab counts as tabstop spaces, not 1 byte.
Example
To highlight all text past column 80:
/\%>80v.
To highlight text past column 120 (common for modern projects):
/\%>120v.
To make this permanent in your vimrc, map it:
nnoremap <leader>ll /\%>80v.<CR>
Tips
- Use
\%<80vto match characters before column 80 (the opposite constraint) - Combine with
:set hlsearch(default on) so all matches stay highlighted until you press<C-l>or:noh - The
:matchcommand highlights just this pattern in a dedicated color::match ErrorMsg /\%>80v./ - Pair with
:g/\%>80v/dto delete all lines that exceed 80 columns \%>Nlconstrains by line number instead of column;\%>10lmatches only after line 10