如何使用vim将文件转换为utf8? [英] How can I use vim to convert my file to utf8?

查看:210
本文介绍了如何使用vim将文件转换为utf8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件.我被告知要使其成为UTF8.我怎么用Vim做到这一点?

I have a text file. I've been told to make it UTF8. How can I do that with Vim?

推荐答案

如果您正在编辑编码为latin1的文件,则会发现该缓冲区的'fileencoding'设置为latin1.因此,在保存文件之前,您需要手动设置文件编码.

If you are editing a file encoded as latin1, you will find that 'fileencoding' for that buffer is set to latin1. So you will need to manually set the fileencoding before saving the file.

:set fileencoding=utf8
:w myfilename

还请注意,UTF8文件通常以指示字节序的字节顺序标记(BOM)开头. BOM 是可选的,但某些程序专门使用它来确定文件编码.在某些情况下,Vim会编写BOM,但有时不会.要明确设置BOM,请执行以下操作:

Also note that UTF8 files often begin with a Byte Order Mark (BOM) which indicates endianness. The BOM is optional but some programs use it exclusively to determine the file encoding. Under certain conditions Vim will write the BOM but sometimes it won't. To explicitly set the BOM do this:

:set bomb

有关更多信息,请 :help mbyte-options :help bomb .

For more information :help mbyte-options and :help utf8 and :help bomb.

这篇关于如何使用vim将文件转换为utf8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆