Hide non printable characters in vim

Solution 1:

This is controlled by the 'isprint' option. Since (quoting from the :help) "The characters from space (ASCII 32) to '~' (ASCII 126) are always displayed directly", the only way is to condense the special characters. You can do that via

:set isprint=1-255

Depending on your font, those characters (like ^[) will probably show up as empty display cells or a generic replacement character.

Solution 2:

Maybe you could use the conceal feature:

:syn match nonprinting /[^[:print:]]/ conceal cchar=%

And set conceallevel if you haven't already:

:set conceallevel=1

This will still expand out the characters when the cursor is on them:

bunch of nul characters same shown as <code>%</code> characters