Vim: show line feeds & carriage-return

carriage returnfeednewlinesvim

How can I display line feeds and/or carriage-return characters in vi/vim?

I know that set list shows all the whitespace characters (?), it also replaces tabs \t etc (but that's not what I want). Basically I just want to display certain characters like \r (on Debian this seems to be the default, however on Gentoo it's different).

Kind regards

Best Answer

In recent versions of Vim there's a 'listchars' setting that lets you specify which characters should be used for the EOL and TAB characters, and for trailing spaces.

You could:

set listchars=eol:$,tab:\[SPACE]\[SPACE]

...to display eol chars specially without collapsing tabs (type a space character, not [,S,P,A,...).

I don't know of anything specifically about return chars in the 'listchars' setting, but I suspect you can use syntax highlighting for this. I think the default display of \r characters is to show them with SpecialKey highlighting.

So the default SpecialKey highlighting of \r characters, combined with setting 'listchars' as above, should be close to what you need.

:highlight SpecialKey ctermfg=5

...if you're fond of magenta.

Related Question