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

How do I visually display tabs, trailing spaces, and end-of-line characters in Vim?

Answer

:set list listchars=tab:>-,trail:~,eol:$

Explanation

Enabling list mode makes Vim render normally invisible characters using configurable symbols defined in listchars. This is invaluable for debugging mixed indentation, trailing whitespace, or unexpected line endings in code and configuration files.

How it works

  • :set list — enables the display of special characters
  • listchars — maps each whitespace type to a display character:
    • tab:>- — renders a tab as > followed by - fill characters
    • trail:~ — marks trailing spaces with ~
    • eol:$ — places a $ at the end of each line
    • space:. — shows every space as . (optional, can be noisy)
    • nbsp:+ — highlights non-breaking spaces

You can combine multiple keys in one listchars setting:

:set listchars=tab:>-,trail:~,eol:$,nbsp:+

Toggle the view off with :set nolist.

Example

A file with a tab-indented line and a trailing space:

	hello world 

With list enabled and tab:▸\ ,trail:·:

▸   hello world·

Tips

  • Use Unicode symbols for a cleaner look: tab:▸\ ,trail:·,eol:↲
  • :set nolist or toggle with yol (vim-unimpaired) to switch quickly
  • Pair with autocmd BufWritePre * :%s/\s\+$//e to auto-strip trailing whitespace on save
  • :set list is a great first step when diagnosing 'mixed indentation' errors in Python or Makefiles

Next

How do I get just the filename without its path or extension to use in a command?