How to set the character encoding for a file in VIM

后端 未结 6 1786
孤街浪徒
孤街浪徒 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 23:46

    Use

    set fileencodings=utf-8
    

    (with an s at the end) which can contain a list of different encodings. Vim will try the encodings listed, from left to right, until one works and it will set fileencoding to that encoding. If none work then fileencoding is set to an empty string which will result in default behavior.

    Also it would probably make sense to add that to your vimrc so you aren't constantly doing that.

提交回复
热议问题