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

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 (v means virtual column, honoring your tabstop setting)
  • . — 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 \%<80v to 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 :match command highlights just this pattern in a dedicated color: :match ErrorMsg /\%>80v./
  • Pair with :g/\%>80v/d to delete all lines that exceed 80 columns
  • \%>Nl constrains by line number instead of column; \%>10l matches only after line 10

Next

How do I visually re-select the exact region I just changed or yanked?