在Vim中将编码和文件编码设置为utf-8
这两个命令有什么区别?
What is the difference between these two commands?
-
set encoding = utf-8
-
set fileencoding = utf-8
-
set encoding=utf-8
set fileencoding=utf-8
当我想使用utf-8时是否需要同时设置两者?
Do I need to set both when I want to use utf-8?
此外,我是否需要将文件编码设置为 set
或 setglobal
?
Also, do I need to set fileencoding with set
or setglobal
?
TL; DR
TL;DR
在第一种使用
set encoding = utf-8
的情况下,您将更改终端中显示的输出编码。
In the first case with
set encoding=utf-8
, you'll change the output encoding that is shown in the terminal.
在第二种情况下,使用 set fileencoding = utf-8
,您将更改文件的输出编码
In the second case with set fileencoding=utf-8
, you'll change the output encoding of the file that is written.
如@Dennis所述,您可以将它们都设置为〜/。如果您一直想在 utf-8
中工作,请使用vimrc。
As stated by @Dennis, you can set them both in your ~/.vimrc if you always want to work in utf-8
.
encoding
设置 vim内部表示字符的方式。对于大多数情况,utf-8是必需的Unicode风格。
"encoding
sets how vim shall represent characters internally. Utf-8 is necessary for most flavors of Unicode."
fileencoding
将编码设置为特定文件(本地于缓冲区);:setglobal设置默认值。也可以使用一个空值:它的默认值与 encoding相同;或者您可能希望设置ucs编码之一,可能使相同的磁盘文件更大或更小,具体取决于您的特殊的字符组合。另外,IIUC的utf-8始终是大端(高位在前),而ucs可以是大端或小端,因此,如果使用它,则可能需要设置炸弹(见下文)。
"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)."