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

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 list enables list mode, which renders invisible characters using the symbols defined by the listchars option
  • :set nolist disables 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 list enabled permanently and rely on listchars to make the display unobtrusive
  • If you only care about trailing whitespace, you can highlight it with a match command instead:
match ErrorMsg /\s\+$/
  • Use :set listchars (without =) to see the current listchars configuration
  • The eol character can be noisy — omit it from listchars if you find it distracting
  • Combine with :set number and :set cursorline for maximum visibility while debugging formatting issues

Next

How do I edit multiple lines at once using multiple cursors in Vim?