Search code examples
vim

How can I make vim show spaces?


I'm currently trying to switch from gedit to vim. I try to make vim look similar to gedit:

gedit

Especially, I would like to show spaces with dots.

I currently have:

enter image description here

There are some differences, but it looks quite similar (this is my current .vimrc file). But I don't get those dots for spaces.

How can I make vim show spaces?

I found some answers (like this one) that seem to suggest to replace spaces by a special visible character and then replace it back. I don't want to do this every time. I want to be able to open vim and see those spaces.


Solution

  • Vim has been providing the 'listchars' option to show Tab vs. Space, and space characters in critical places, i.e. trailing at the end of lines. In previous versions (when the question was written), it did not offer a modification for all spaces: a blank square is a space, period. Other answers provided some workarounds, though.

    In current Vim versions, there are many space-related options; cp. :help 'listchars' for details.

    You can get the effect seen in your screenshot; persist by putting that command into your ~/.vimrc:

    :set list listchars+=space:. listchars-=eol:$