Make Vim show ALL white spaces as a character

Viewed 754005

I can't find a way to make Vim show all white spaces as a character. All I found was about tabs, trailing spaces etc.

23 Answers

To cover Unicode whitespace characters:

set list
set listchars=tab:│\ ,nbsp:·
highlight StrangeWhitespace guibg=Red ctermbg=Red
" The list is from https://stackoverflow.com/a/37903645 (with `\t`, `\n`, ` `, `\xa0` removed):
call matchadd('StrangeWhitespace', '[\x0b\x0c\r\x1c\x1d\x1e\x1f\x85\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]')

The result:

  • Only the ordinal space (U+0020) looks like an ordinal space (" ").
  • The tab (U+0009) looks like "│ " (two characters: a long pipe and then an ordinal space; they are gray in colorscheme murphy).
  • The non-breaking space (U+00A0) looks like "·" (one character; it's gray in colorscheme murphy).
  • Any other whitespace character looks like a red space (" ").

Keep those hacks in the .vimrc as comments, so in the shell, simply :

echo '
  " how-to see the non-visible while spaces
  " :set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
  " set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
  " :set list
  " but hei how-to unset the visible tabs ?!
  " :set nolist
  ' >> ~/.vimrc
Related