103

How can I configure vim to display hidden characters like tabs or spaces ONLY while those characters are typed? I do not want tabs and/or space replaced with special characters like ">" or "_" when the file is written.

muru
  • 207,228
dan0
  • 1,033

4 Answers4

112

You can use the commands

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

to show all characters that aren't whitespace. So spaces are the only thing that doesn't show up.

If you absolutely need spaces to be marked as well, you'll need to try something less nice. Something like

:%s/ /█/g

Will replace all spaces with a block character. Then you'd need to undo it before writing. You could remap your write command do

cmap :w :%s/█/ /g<CR>:w

Just a suggestion. I haven't tried that though.

Kris Harper
  • 13,705
50

More recent versions of vim can show spaces as well. (Confirmed on vim 7.4.1689).

:set list
:set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»
wisbucky
  • 2,762
  • 32
  • 17
12

In my case I had to fight nbsp,

:set listchars=nbsp:☠,tab:▸␣
:set list

You can also use ␣ instead of ☠

Here is an example where the above vim config highlights the "invisible weird" spaces and additionally it highlights tabs (red color because I am using trailing-whitespace vim plugin)

Here

stumblebee
  • 4,379
2

In vim just type search pattern and then scan with n or N. If the search fails, then no \r. You can get your answer in a couple of seconds.

/\r  or /\n

If you are configured to highlight search targets, you will even see where all the occurrences or lack of them are.