How to set the character encoding for a file in VIM

后端 未结 6 1798
孤街浪徒
孤街浪徒 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:41

    I read many thread about VIM encoding. I find that the most important trick is: Before open the file ,you should open VIM first, then use the command: edit ++enc= filename.ext It can handle most questions about encoding and fileencoding.

    the key points include:

    1. You must display the charset correctly! without correct display, any other operations may cause unrecoverable issue.
    2. after the file is displayed correctly, if needed , you can ":set fileencoding=UTF-8"
      : write" to let VIM can always display it correctly.

    Because I am not an English mother tongue user, I think my way is able to be validate.

提交回复
热议问题