Chinaunix首页 | 论坛 | 博客
  • 博客访问: 277682
  • 博文数量: 65
  • 博客积分: 3091
  • 博客等级: 中校
  • 技术积分: 705
  • 用 户 组: 普通用户
  • 注册时间: 2005-01-25 09:44
文章存档

2013年(2)

2012年(11)

2011年(12)

2010年(13)

2009年(15)

2008年(12)

分类: LINUX

2010-06-06 16:58:18

2010-06-06
1.背景说明:
Debian lenny系统的locale是zh_CN.UTF-8;现有WinXX上的源代码文件在vi下不能正常显示,因此需要设置vi工作环境的编码。注意:通过 dpkg-reconfigure locales 改变配置不是一个好方法。
2.编码option说明:
阅读vi(vim)的在线帮助文档,或者直接进入vi后,通过:help encoding-names 找到相关的说明。
a) encoding
Encoding used for the keyboard, display and all the text that is used inside Vim. Not only the text in the buffers, but also in registers, variables, etc. It is also the default encoding for files.
可用的 encoding 值有:
Latin1(ISO 8859-1), iso-8859-n(n=2 to 15), cpxxx(代表MS下的codepage,如cp936为简体中文),euc-cn(简体中文,在unix下使用), ..., utf-8, ucs-2, ..., ucs-4, ...
以下是上面 encoding 名的一些别名:
ansi, japan, korea, prc(在unix下为euc-cn,windows下为cp936), chinese(同prc), utf8, unicode(ucs-2的别名), ucsxxx...
b) fileencoding
Encoding of a file. 当与 encoding 值不同时,在读写文件时会进行编码转换。
c) fileencodings
文件可能的编码列表、当打开一个文件时,将使用这些编码逐一试探,其中第一个没有引起编码错误的编码值将作为 fileencoding 的值。
d) termencoding
The GUI fully supports multi-byte characters. It is also possible in a terminal, if the terminal supports the same encoding that Vim uses. Thus this is less flexible.
For example, you can run Vim in a xterm with added multi-byte support and/or |XIM|. Examples are kterm (Kanji term) and hanterm (for korean), Eterm (Enlightened terminal) and rxvt.
如果你的终端或仿真器不支持相应的编码,你可以设置 termencoding 选项。Vim 会把从终端键入的字符从 termencoding 编码转换成 encoding 编码,以及将输出显示的文字从 encoding 编码转换成 termencoding 编码。如果你的终端(例如 xterm)支持 unicode,那么这个转换过程不会丢失信息。
通常情况下, encoding 等于你当前使用的 locale,而 termencoding 一般为空。这使得键盘输入和显示输出使用你当前的 locale 工作,且 Vim 内部也使用相同的字符编码。
3.内部转换说明
当vim运行时,在以下过程中会自动将一种编码转换为另一种编码:
a) 读取一个文件并且 fileencoding 与 encoding 不同时;
b) 存储一个文件并且 fileencoding 与 encoding 不同时;
c) 读取终端输入并且 termencoding 与 encoding 不同时;
d) 显示字符串并且 termencoding 与 encoding 不同时;
e) 显示消息并且 LC_MESSAGE 的编码与 encoding 不同时;
f) 读取 Vim 脚本发现 |:scriptencoding| 与 encoding 不同时;
g) 读或写一个 |viminfo| 文件时。
4. 实践
$cp /etc/vim/vim ~/.vimrc
编辑 ~/.vimrc 文件(删除一些内容),然后在最后加入 set fileencodings=utf-8,gb18030 或者根据实际情况加入编码设置选项的值。
阅读(1158) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~