How do I show invisible characters like tabs and trailing spaces?
Answer
:set list
Explanation
The :set list command makes invisible characters visible by displaying them as special symbols. Tabs, trailing spaces, non-breaking spaces, and line endings are all shown using configurable placeholder characters. This is essential for debugging whitespace issues, enforcing coding standards, and catching hidden formatting problems.
How it works
:set listenables list mode, which renders invisible characters using the symbols defined by thelistcharsoption:set nolistdisables list mode and returns to normal display:set list!toggles list mode on and off
Default display
With default settings, :set list shows:
- Tabs as
^I - End of line as
$
The default symbols are not very readable, so most users customize listchars.
Customizing listchars
Add this to your vimrc for a much better experience:
set listchars=tab:→\ ,trail:·,nbsp:␣,eol:↵,extends:»,precedes:«
This shows:
→for tabs (arrow followed by spaces)·for trailing spaces␣for non-breaking spaces↵for end-of-line characters»when a line extends beyond the screen to the right«when a line extends beyond the screen to the left
Tips
- Use
:set list!to quickly toggle the display on and off - Many users keep
listenabled permanently and rely onlistcharsto make the display unobtrusive - If you only care about trailing whitespace, you can highlight it with a
matchcommand instead:
match ErrorMsg /\s\+$/
- Use
:set listchars(without=) to see the currentlistcharsconfiguration - The
eolcharacter can be noisy — omit it fromlistcharsif you find it distracting - Combine with
:set numberand:set cursorlinefor maximum visibility while debugging formatting issues