Vim Editor – Display ASCII Characters Only and Treat Other Bytes as Binary Data

asciibinarycharacter encodingunicodevim

I already know vim -b, however, depending on the locale used, it displays multi-byte characters (like UTF-8) as single letters.

How can I ask vim to only display ASCII printable characters, and treat the rest as binary data, no matter the charset?

Best Answer

When using vim -b, this displays all high characters as <xx>:

set encoding=latin1
set isprint=
set display+=uhex

Any single-byte encoding will work, vim uses ASCII for all lower chars and has them hard-coded as printable. Setting isprint to empty will mark everything else as non-printable. Setting uhex will display them as hexadecimal.

Here is how the display changes after each command:

before after setting encoding after setting isprint after setting uhex

Related Question