在 Vim 中将 encoding 和 fileencoding 设置为 utf-8 [英] Set encoding and fileencoding to utf-8 in Vim

查看:9
本文介绍了在 Vim 中将 encoding 和 fileencoding 设置为 utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个命令有什么区别?

  • 设置编码=utf-8
  • 设置文件编码=utf-8

当我想使用 utf-8 时,是否需要同时设置?

另外,我是否需要使用 setsetglobal 设置文件编码?

解决方案

TL;DR

<块引用>

在使用 set encoding=utf-8 的第一种情况下,您将更改终端中显示的输出编码.

在使用 set fileencoding=utf-8 的第二种情况下,您将更改写入的文件的输出编码.

正如@Dennis 所说,如果你总是想在 utf-8 中工作,你可以在你的 ~/.vimrc 中设置它们.

更多详情

来自 VIM 关于使用 unicode 的 wiki

"encoding 设置 vim 在内部表示字符的方式.对于大多数 Unicode 风格,utf-8 是必需的."

"fileencoding 设置特定文件的编码(本地到缓冲区); :setglobal 设置默认值.也可以使用空值:它默认与编码"相同.或者您可能想要设置其中一种 ucs 编码,它可能会根据您的特定字符组合使相同的磁盘文件更大或更小.此外,IIUC,utf-8 总是很大-endian(高位在前)而 ucs 可以是 big-endian 或 little-endian,所以如果你使用它,你可能需要设置 'bomb'(见下文)."

What is the difference between these two commands?

  • set encoding=utf-8
  • set fileencoding=utf-8

Do I need to set both when I want to use utf-8?

Also, do I need to set fileencoding with set or setglobal?

解决方案

TL;DR

In the first case with set encoding=utf-8, you'll change the output encoding that is shown in the terminal.

In the second case with set fileencoding=utf-8, you'll change the output encoding of the file that is written.

As stated by @Dennis, you can set them both in your ~/.vimrc if you always want to work in utf-8.

More details

From the wiki of VIM about working with unicode

"encoding sets how vim shall represent characters internally. Utf-8 is necessary for most flavors of Unicode."

"fileencoding sets the encoding for a particular file (local to buffer); :setglobal sets the default value. An empty value can also be used: it defaults to same as 'encoding'. Or you may want to set one of the ucs encodings, It might make the same disk file bigger or smaller depending on your particular mix of characters. Also, IIUC, utf-8 is always big-endian (high bit first) while ucs can be big-endian or little-endian, so if you use it, you will probably need to set 'bomb" (see below)."

这篇关于在 Vim 中将 encoding 和 fileencoding 设置为 utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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