It's really simple. Store all the texts in Unicode and you will be happy (provided the 'encoding' option is set correctly, of course;) Otherwise (you have a lot of texts in national encodings)
read the topic to the end :)
The following options are responsible for encoding in Vim:
'encoding' is the encoding in which Vim stores all the data. That is, the text of buffers, strings in expressions, contents of registers, etc. By default, this is either "latin1" or something corresponding to the $ LANG environment variable. If you do not use such a thing as langmap, it is highly recommended to set 'encoding' to “utf-8”. This will allow you to edit any text, including those saved in one of the lossless Unicode encodings.
')
'fileencoding' is the file encoding in the current buffer. It is either determined automatically (the 'fileencodings' option is used for this, see below), or specified explicitly when opening a file using the ++ enc modifier. For example, to open the file foo.txt in KOI8-R encoding you would write
: e ++ enc = koi8-r foo.txt
and press Enter. And now attention, delicate moment. If you open a file without the ++ enc modifier, the 'fileencoding' option will be set by Vim to whatever it sees fit. For example, it may incorrectly determine the encoding and set 'fileencoding' to "latin1". If you then write
: set fileencoding = koi8-r
Vim does not re-open the file in this encoding, it recodes it from the current to KOI8-R! To open the file in the correct encoding, be sure to use ++ enc. But if you want to save the file in a different encoding from the one in which it is written, change the 'fileencoding' option. For example, you have the file foo.txt encoded in KOI8-R, and you want to save it to the CP-1251. For this, you open it
: e ++ enc = koi8-r foo.txt
change encoding
: set fileencoding = cp-1251
and save
: w
The last two actions can be combined into one by applying the known modifier ++ enc like this
: w ++ enc = cp-1251
'fileencodings' is a list of encodings that Vim will
iterate through when opening a file. About encoding names read in: help encoding-names.
There is another option
'termencoding' , which is responsible for the encoding of the terminal, but in most cases you will not have to configure it.