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
- Define what to show:
:set listchars=tab:→\ ,trail:· - Enable the display:
:set list - Disable with:
:set nolistor 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 nolisthides the indicators without changinglistchars- 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 SpecialKeycontrols the color of listchars indicators