如何在VIM中设置文件的字符编码 [英] How to set the character encoding for a file in VIM

查看:133
本文介绍了如何在VIM中设置文件的字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:set fileencoding = utf-8 ,文件保存正确,但下次打开时,会出现乱码,:set fileencoding?表示该选项未设置。

I'm using :set fileencoding=utf-8 and the file is saved correctly, but the next time I open it, I get garbled characters and :set fileencoding? says the option isn't set.

从文档中我明白我不应该触摸 encoding 选项。

From the docs I understand that I shouldn't touch the encoding option.

在VIM中为文件指定编码的方式是什么?

What's the correct way of specifying an encoding for a file in VIM?

推荐答案

使用

set fileencodings=utf-8

(最后有一个s),可以包含不同编码的列表。 Vim将尝试列出的编码,从左到右,直到一个工作,它将设置文件编码为该编码。如果没有工作,那么fileencoding将设置为一个空字符串,这将导致默认行为。

(with an s at the end) which can contain a list of different encodings. Vim will try the encodings listed, from left to right, until one works and it will set fileencoding to that encoding. If none work then fileencoding is set to an empty string which will result in default behavior.

此外,添加到您的vimrc可能是有意义的,所以你不是不断做这个。

Also it would probably make sense to add that to your vimrc so you aren't constantly doing that.

这篇关于如何在VIM中设置文件的字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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