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
?
Click Tools, then select Web options. Go to the Encoding tab. In the dropdown for Save this document as: choose Unicode (UTF-8). Click Ok.
UTF-8 is a character encoding system. It lets you represent characters as ASCII text, while still allowing for international characters, such as Chinese characters. As of the mid 2020s, UTF-8 is one of the most popular encoding systems.
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
.
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)."
set encoding=utf-8 " The encoding displayed. set fileencoding=utf-8 " The encoding written to file.
You may as well set both in your ~/.vimrc
if you always want to work with utf-8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With