13

This question already has an answer here:

My goal were to somehow make visible, if a whitespace is space, tab, or even newline (and, ideally, in case of newline I would be happy to see \r\n and \n differently).

I am thinking to a similar thing as the GUI text editors can do.

Is it somehow with vim also possible?

marked as duplicate by Rich, Gilles 'SO- stop being evil', Doorknob, Dom, bsmith89 Feb 13 '15 at 23:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

14

Yes, look at :help listchars.

listchars is a string that will be parsed when list is set to determine what to render for certain special characters. You can set listchars in your .vimrc like so:

set listchars=eol:!,tab:>=,trail:.
set list

This will use the ! character to show the end of every line, tabs like >=== (assuming four-space tabs), and trailing spaces with a . character. The characters are highlighted with the SpecialKey group.

In addition, you can include the following tokens in listchars:

  • extends:<character> for the last character in a long line
  • precedes:<character> for the first character in a long line
  • conceal:<character> for concealed text
  • nbsp:<character> for non-breaking spaces

Note that you cannot get vim to display visible whitespace for spaces that are not trailing without a relatively modern version of vim; check if has("patch710") to see if space is supported in listchars.

5

This can be done with :set list. The Characters displayed for the different whitespace chars can be controlled by :set listchars. See the help topics for detailed information. Here's an example from my .vimrc:

set list
set listchars=tab:>-,trail:.,extends:#,nbsp:.

Not the answer you're looking for? Browse other questions tagged or ask your own question.