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 characterslistchars— maps each whitespace type to a display character:tab:>-— renders a tab as>followed by-fill characterstrail:~— marks trailing spaces with~eol:$— places a$at the end of each linespace:.— 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 nolistor toggle withyol(vim-unimpaired) to switch quickly- Pair with
autocmd BufWritePre * :%s/\s\+$//eto auto-strip trailing whitespace on save :set listis a great first step when diagnosing 'mixed indentation' errors in Python or Makefiles