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

How do I visualize tabs, trailing spaces, and other invisible characters in Vim?

Answer

:set list listchars=tab:→\ ,trail:·

Explanation

:set list enables display of invisible characters. The listchars option defines which characters are shown and how. Together they make hidden whitespace — tabs, trailing spaces, non-breaking spaces, end-of-line markers — visible, which is essential for maintaining consistent indentation and catching invisible formatting bugs.

How it works

  1. Define what to show: :set listchars=tab:→\ ,trail:·
  2. Enable the display: :set list
  3. Disable with: :set nolist or toggle with: :set list!

listchars keys

Key Shows
tab:XY Tab characters — X for the first char, Y for the rest
trail:X Trailing spaces at end of line
space:X All space characters
eol:X End-of-line character
nbsp:X Non-breaking space (\u00A0)
extends:X Line extends past right edge (with nowrap)
precedes:X Line extends past left edge (with nowrap)

Recommended configuration

set list
set listchars=tab:→\ ,trail:·,nbsp:␣,extends:›,precedes:‹

Example output

A line with a tab and trailing space becomes:

→       hello·

Tips

  • :set nolist hides the indicators without changing listchars
  • Trailing space indicator (trail:·) instantly reveals whitespace that would cause linting failures
  • The tab:→\ value needs the escaped space to display the remaining tab width correctly
  • Use Unicode characters (→, ·, ␣) for clean visual indicators — your terminal must support UTF-8
  • :highlight SpecialKey controls the color of listchars indicators

Next

How do I run a search and replace only within a visually selected region?