Display hidden characters


A fixture of many .vimrc files, Vim’s list and listchars option can be enabled to show hidden characters such as line breaks, tabs, non-breaking spaces, trailing whitespace, and more. By default list is not enabled, but you can enable it with set list in your .vimrc.

From there, you have a number of options you can configure to your liking using the listchars setting. The most commonly used are tab and trail which will set a character to display in place of tabs and trailing line spaces respectively. Here’s how we can set those:

" enable list mode
set list
" display chars for tabs and trailing spaces
set listchars=tab:> ,trail:-

The format of the listchars option is a comma-separated list of key/value pairs where the key and value are separated by a colon. Most of the options keys, which I’ll list below, accept only one character value. This is the character is displayed in place of the hidden one.

But tab can take either 2 or 3 characters. In my example above, I’ve used 2: a greater than and a space. When 2 characters are used, the first one is displayed in place of the first character of the tab width. The second character is filled in the rest of the way up to the width set by the tabstop setting.

If you specify 3 characters for your tab listchars, then the first is displayed in the first position, the last is displayed in the last position, and the middle character is used to fill all the spaces in between.

The trail option is another commonly used listchars which we discuss in our post about how to remove trailing whitespace in Vim. Any whitespace character hanging at the end of the line will transform into the character you set, making it easier to see those pesky dangling spaces.

In addition to those two highly recommended listchars values, the setting supports of host of other cases. You can read the full details under :help listchars but here’s a summary of the remaining:

  • eol – Shows line break characters. For example, a return symbol: ⏎
  • space – Space can be displayed for those that need it. You could use a middle dot: ·
  • extends – Used to indicate there is text to the right when you have line wrapping disabled with set nowrap
  • precedes – Same, but for the text hidden to the left
  • conceal – In Vim 7.3 and above with the conceal features compiled in, Vim can conceal certain text. See :conceallevel.
  • nbsp – Displayed in place of a non-breaking space. I recommend you set this to a middle dot · so you can distinguish from regular breaking spaces.

How useful was this tip?

Average rating 4.5 / 5. Vote count: 29

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts