<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yousri&#039;s Blog &#187; 字符编码</title>
	<atom:link href="http://blog.yousri.org/tag/%e5%ad%97%e7%ac%a6%e7%bc%96%e7%a0%81/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.yousri.org</link>
	<description>一个人骑单车在陌生城市路上自由穿梭的生活</description>
	<lastBuildDate>Fri, 20 Jan 2012 15:01:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Windows系统Vim编辑器乱码解决分析</title>
		<link>http://blog.yousri.org/2009/02/27/analysis-and-solution-vim-editor-coding-garbled-on-windows.html</link>
		<comments>http://blog.yousri.org/2009/02/27/analysis-and-solution-vim-editor-coding-garbled-on-windows.html#comments</comments>
		<pubDate>Fri, 27 Feb 2009 08:05:59 +0000</pubDate>
		<dc:creator>Yousri</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[乱码]]></category>
		<category><![CDATA[字符编码]]></category>

		<guid isPermaLink="false">http://qingxianyan.cn/?p=305</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160;貌似之前就有遇到过在windows系统下vim出现中文乱码的情况，只是用得较少而且也懒得去捣鼓它/// 这问题直到昨晚因为试用了个Casparant同学介绍的一款用于实现twitter客户端功能Vim插件—TwitVim的时候查看消息的时候出现的根本都是乱码。。。所以决定搞定关于Vim编辑器编码方式导致中文乱码的问题/// &#160;&#160;&#160;&#160;&#160;&#160;&#160;上网了解了下才知道原来Vim有四个跟字符编码方式有关的选项，分别是：encoding、fileencoding、fileencodings、 termencoding (这些选项可能的取值请参考 Vim 在线帮助 :help encoding-names)，它们各自的意义: &#160;&#160;&#160;&#160;&#160;&#160;&#160;* encoding: Vim 内部使用的字符编码方式，包括 Vim 的 buffer (缓冲区)、菜单文本、消息文本等。用户手册上建议只在 .vimrc 中改变它的值，事实上似乎也只有在 .vimrc 中改变它的值才有意义。 &#160;&#160;&#160;&#160;&#160;&#160;&#160;* fileencoding: Vim 中当前编辑的文件的字符编码方式，Vim 保存文件时也会将文件保存为这种字符编码方式 (不管是否新文件都如此)。 &#160;&#160;&#160;&#160;&#160;&#160;&#160;* fileencodings: Vim 启动时会按照它所列出的字符编码方式逐一探测即将打开的文件的字符编码方式，并且将 fileencoding 设置为最终探测到的字符编码方式。因此最好将 Unicode 编码方式放到这个列表的最前面，将拉丁语系编码方式 latin1 放到最后面。 &#160;&#160;&#160;&#160;&#160;&#160;&#160;* termencoding: Vim 所工作的终端 (或者 Windows 的 Console 窗口) 的字符编码方式。这个选项在 Windows 下对我们常用的 GUI 模式的 gVim 无效，而对 Console 模式的 <a href='http://blog.yousri.org/2009/02/27/analysis-and-solution-vim-editor-coding-garbled-on-windows.html'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2008%2F11%2F16%2Fconfusion_code.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">中文乱码解决方案集中篇</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2008%2F12%2F22%2Fwindows-server-2003-install-and-setting.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Windows Server 2003服务器简易安全配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2009%2F01%2F17%2Fsome-skills.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">vi使用及ubuntu旧内核删除</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F28%2F%25E5%25A4%25B1%25E7%259C%25A0%25E4%25BA%2586.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">失眠了</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;貌似之前就有遇到过在windows系统下vim出现中文乱码的情况，只是用得较少而且也懒得去捣鼓它///  这问题直到昨晚因为试用了个Casparant同学介绍的一款用于实现twitter客户端功能Vim插件—TwitVim的时候查看消息的时候出现的根本都是乱码。。。所以决定搞定关于Vim编辑器编码方式导致中文乱码的问题///<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;上网了解了下才知道原来Vim有四个跟字符编码方式有关的选项，分别是：encoding、fileencoding、fileencodings、 termencoding (这些选项可能的取值请参考 Vim 在线帮助 :help encoding-names)，它们各自的意义:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* encoding: Vim 内部使用的字符编码方式，包括 Vim 的 buffer (缓冲区)、菜单文本、消息文本等。用户手册上建议只在 .vimrc 中改变它的值，事实上似乎也只有在 .vimrc 中改变它的值才有意义。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* fileencoding: Vim 中当前编辑的文件的字符编码方式，Vim 保存文件时也会将文件保存为这种字符编码方式 (不管是否新文件都如此)。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* fileencodings: Vim 启动时会按照它所列出的字符编码方式逐一探测即将打开的文件的字符编码方式，并且将 fileencoding 设置为最终探测到的字符编码方式。因此最好将 Unicode 编码方式放到这个列表的最前面，将拉丁语系编码方式 latin1 放到最后面。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* termencoding: Vim 所工作的终端 (或者 Windows 的 Console 窗口) 的字符编码方式。这个选项在 Windows 下对我们常用的 GUI 模式的 gVim 无效，而对 Console 模式的 Vim 而言就是 Windows 控制台的代码页，并且通常我们不需要改变它。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;由于 Unicode 能够包含几乎所有的语言的字符，Unicode的 UTF-8 编码方式又是非常具有性价比的编码方式，因此encoding 的值设置为utf-8。同时将encoding设置为utf-8时，Vim自动探测文件的编码方式会更准确。在中文 Windows里编辑的文件，为了兼顾与其他软件的兼容性，文件编码还是设置为GB2312/GBK比较合适，因此fileencoding建议设置为 chinese (chinese 是个别名，在Unix里表示gb2312，在Windows里表示cp936，也就是GBK的代码页)。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;最终对于文件中显示乱码、菜单乱码、右键菜单乱码以及Conlse输出乱码问题的解决方案，修改Vim编辑器所对应的配置文件_vimrc，添加如下配置：<br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“处理文本中显示乱码</p>
<pre lang="vim">
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
</pre>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“处理菜单及右键菜单乱码</p>
<pre lang="vim">
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
</pre>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“处理consle输出乱码</p>
<pre lang="vim">language messages zh_CN.utf-8</pre>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关于Vim的支持多字符编码方式工作的运作原理是：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;首先、Vim 启动，根据_vimrc配置文件中设置的encoding的值来设置buffer、菜单文本、消息文的字符编码方式。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;紧接、读取要编辑的文件，根据fileencodings中列出的字符编码方式逐一探测该文件编码方式。并设置fileencoding 为探测到的字符编码方式。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后、对比fileencoding和encoding的值，若不同则调用iconv将文件内容转换为encoding所描述的字符编码方式，并且把转换后的内容放到为此文件开辟的buffer里，完成后就可以开始编辑这个文件。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;最后、编辑完成后保存文件时，再次对比fileencoding和encoding的值。若不同再次调用iconv将即将保存的buffer中的文本转换为fileencoding所描述的字符编码方式，并保存到指定的文件中。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：需要调用外部的iconv.dll，需要保证这个文件存在于$VIMRUNTIME或者其他列在PATH环境变量中的目录里。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2008%2F11%2F16%2Fconfusion_code.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">中文乱码解决方案集中篇</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2008%2F12%2F22%2Fwindows-server-2003-install-and-setting.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Windows Server 2003服务器简易安全配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2009%2F01%2F17%2Fsome-skills.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">vi使用及ubuntu旧内核删除</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F28%2F%25E5%25A4%25B1%25E7%259C%25A0%25E4%25BA%2586.html&from=http%3A%2F%2Fblog.yousri.org%2F2009%2F02%2F27%2Fanalysis-and-solution-vim-editor-coding-garbled-on-windows.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">失眠了</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.yousri.org/2009/02/27/analysis-and-solution-vim-editor-coding-garbled-on-windows.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

