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

How do I customize which invisible characters are shown in list mode, including trailing spaces and off-screen indicators?

Answer

:set listchars=

Explanation

The listchars option controls exactly which invisible characters Vim highlights when list mode is active. Beyond the commonly known tab and trail, it includes a full set of indicators for off-screen content, end-of-line markers, non-breakable spaces, and every plain space — each configurable with any Unicode symbol.

How it works

  • :set list activates display of invisible characters
  • :set listchars={key}:{char},... configures what is shown for each type
  • Unset keys keep their defaults; you only need to configure what you want

The full set of keys:

Key Shows
tab Tab characters (use two chars: leader + fill)
trail Trailing spaces
space Every space character
eol End-of-line marker
extends Character shown on the right when the line extends past the screen
precedes Character shown on the left when the line extends before the screen
nbsp Non-breaking spaces (\u00a0)
conceal Replacement for concealed text

Example

A practical configuration for code review:

:set listchars=tab:»·,trail:·,extends:›,precedes:‹,nbsp:⎵

This highlights:

  • »· — tab (arrow head + dot fill)
  • · — trailing spaces (a common source of merge noise)
  • / — text that scrolls off-screen in nowrap mode
  • — non-breaking spaces that look like regular spaces but break alignment

Tips

  • Set extends and precedes before using :set nowrap so you always know when content is off-screen
  • Enable trail globally in your vimrc to catch accidental trailing whitespace while editing
  • Use :set nolist or set list! to toggle on/off without losing the configuration
  • :set listchars=space:· can be noisy; prefer trail alone unless you specifically want to see all spaces

Next

How do I enable matchit so % jumps between if/else/end style pairs?