在GNOME终端(3.4.1.1)
$ echo $LANG
en_US.UTF-8
$ echo 你好 | iconv -f UTF8 -t UTF32BE | tee hello.txt
O`Y}内文(7.3):
$ vim -N -u NONE --cmd 'set tenc=utf32 enc=utf32 fencs=utf32be' hello.txt
你好
~
~
~
:set tenc enc fenc
termencoding=ucs-4
encoding=ucs-4
fileencoding=ucs-4终端无法显示UTF32字符。
在修改了Vim的几个编码选项之后。
Vim仍然可以显示UTF32,没有任何问题。
为什么?
发布于 2012-06-08 03:25:00
有意思的。您可以在script中运行您的命令,以验证Vim实际上是在将UTF-8写入您的终端。
对于'charconvert'和'encoding'的帮助给出了关于内部操作的间接提示,但我没有找到相应的提示,表明同样的行为被应用于termencoding。分别:
Vim内部使用UTF-8,而不是UCS-2或UCS-4.
和
当使用"unicode“、"ucs-2”或"ucs-4“时,Vim内部使用utf-8。
因此,我们将使用来源 (具体来说是7.3.548版本)来了解正在发生的事情。
termencoding/tenc选项的值是全局变量p_tenc中的已存储。
did_set_string_option()似乎处理字符串值选项的设置。- When [handling `termencoding`](http://code.google.com/p/vim/source/browse/src/option.c?name=v7-3-548#5958), it calls [`convert_setup()`](http://code.google.com/p/vim/source/browse/src/mbyte.c?name=v7-3-548#5806) to setup `output_conv` (for converting `encoding` to `termencoding`).convert_setup的注释给出了关于正在发生什么的第一个提示:
注:不能用于从ucs-2和ucs-4转换(将使用utf-8 )。
- `convert_setup` [calls](http://code.google.com/p/vim/source/browse/src/mbyte.c?name=v7-3-548#5821) [`convert_setup_ext()`](http://code.google.com/p/vim/source/browse/src/mbyte.c?name=v7-3-548#5824) with TRUE for both of the {`from`,`to`}`_unicode_is_utf8` parameters. - When {`from`,`to`}`_unicode_is_utf8` are true (they are), it sets the local variables {`from`,`to`}`_is_utf8` based on whether the specified encodings have the ENC\_UNICODE property ([`ucs-4` does](http://code.google.com/p/vim/source/browse/src/mbyte.c?name=v7-3-548#254), as do all of Vim’s `utf-…` and `ucs-…` encodings).当涉及到iconv时,如果{from,to}_is_utf8是真的,则Vim替换utf-8 (在本例中,是这样的)。
最终,encoding和termencoding的值在这里以相同的方式处理。ucs-4有ENC_UNICODE,Vim用UTF-8代替所需的编码。也许在提交日志中有一些提示,说明为什么termencoding会被这样对待;不过,我将把考古学留给其他人。
处理fileencoding的代码路径是不同的。它只为转换的“内部侧”强制UTF-8 (并且只有当“Unicode”encoding生效时)。
https://stackoverflow.com/questions/10941643
复制相似问题