Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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

share|improve this answer
These options don't depend on -b, that will just set a few other options, see :help edit-binary. I don't see a difference in how nonprintable bytes are shown (it shows NUL without -b as well usually). I'm mostly not using -b, because I use these options to check on weird encodings in text files. – pascal May 19 '15 at 1:44

This sounds like what you're looking for. This tip from the vim wiki titled: Forcing UTF-8 Vim to read Latin1 as Latin1.

$ vim -c "e ++enc=latin1" file.txt

Also from vim's :help you can do this to see more on encodings.

:help enc

excerpt from :help enc

'encoding' 'enc'        string (default: "latin1" or value from $LANG)
                        {only available when compiled with the +multi_byte
                        {not in Vi}
    Sets the character encoding used inside Vim.  It applies to text in
    the buffers, registers, Strings in expressions, text stored in the
    viminfo file, etc.  It sets the kind of characters which Vim can work
    with.  See encoding-names for the possible values.

    NOTE: Changing this option will not change the encoding of the
    existing text in Vim.  It may cause non-ASCII text to become invalid.
    It should normally be kept at its default value, or set when Vim
    starts up.  See multibyte.  To reload the menus see :menutrans.

    This option cannot be set from a modeline.  It would most likely
    corrupt the text.

    NOTE: For GTK+ 2 it is highly recommended to set 'encoding' to
    "utf-8".  Although care has been taken to allow different values of
    'encoding', "utf-8" is the natural choice for the environment and
    avoids unnecessary conversion overhead.  "utf-8" has not been made
    the default to prevent different behavior of the GUI and terminal
    versions, and to avoid changing the encoding of newly created files
    without your knowledge (in case 'fileencodings' is empty).
share|improve this answer
That's pretty nice, but I'd like "vim to only display ASCII printable characters", and your solution uses the latin1 charset (that is ISO-8859-1, a superset of ASCII), it will thus display characters such as é which I'd rather like to be displayed as <e9>. – Totor Jan 25 '14 at 1:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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