How to set the character encoding for a file in VIM

后端 未结 6 1789
孤街浪徒
孤街浪徒 2020-12-07 23:05

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? sa

6条回答
  •  萌比男神i
    2020-12-07 23:43

    You should set fileencodings to the different encodings vim should try when opening a file, for example:

    set fileencodings=ucs-bom,utf-8,latin1
    

    From :help fileencodings:

    This is a list of character encodings considered when starting to edit an existing file. When a file is read, Vim tries to use the first mentioned character encoding. If an error is detected, the next one in the list is tried. When an encoding is found that works, fileencoding is set to it.

    You best put these settings in your .vimrc file so that you don't have to input them manually each time you start vim.

提交回复
热议问题