Answers:
使用时vim -b
,这会将所有高位字符显示为<xx>
:
set encoding=latin1
set isprint=
set display+=uhex
任何单字节编码都可以使用,vim对所有低位字符使用ASCII并将其硬编码为可打印。设置isprint
为空将把其他所有内容标记为不可打印。设置uhex
会将它们显示为十六进制。
以下是每个命令后显示的变化:
set encoding=latin1|set isprint=|set display+=uhex
这听起来像您要找的东西。vim
Wiki上的技巧提示为:强制UTF-8 Vim将Latin1读取为Latin1。
$ vim -c "e ++enc=latin1" file.txt
同样来自vim
的:help
,你可以做到这一点,看看更多的编码。
:help enc
摘录自 :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).
...
...
vim
仅显示ASCII可打印字符”,并且您的解决方案使用latin1字符集(即ISO-8859-1,ASCII的超集),因此它将显示诸如é
“ d宁愿显示为<e9>
。
-b
,它们只会设置其他几个选项,请参见:help edit-binary
。我看不出不可打印字节的显示方式有所不同(它-b
通常不显示NUL )。我主要不使用-b
,因为我使用这些选项来检查文本文件中的奇怪编码。