Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

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)
                        global
                        {only available when compiled with the +multi_byte
                        feature}
                        {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 at 1:41

Your Answer

 
discard

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.