Jtti: How to solve linux vim Chinese garbled characters

To solve the problem of Chinese garbled characters in Vim in Linux, you can follow the following steps:

Check character encoding :

First, make sure that the character encoding settings of your terminal and Vim are consistent. You can run the following command in the terminal to view the character encoding of the terminal:

echo $LANG

Make sure that the terminal's character encoding (e.g., UTF-8) matches Vim's character encoding.

Configure Vim’s character encoding :

Open Vim and make sure you are in Normal Mode. Then, configure the character encoding in Vim using the following command:

:set encoding=utf-8

This will set Vim's character encoding to UTF-8. If you use another character encoding, you can replace utf-8 with your desired character encoding.

Set file encoding :

If you are editing an existing file, make sure the file's encoding matches the Vim character encoding you configured. You can execute the following commands in Vim to view and set file encoding:

:set fileencoding

If you need to change the file encoding, you can use the following command:

:set fileencoding=utf-8

Reload the file :

If you have opened a file and the character encoding is set correctly, but the file still displays garbled characters, you can try reloading the file:

:e

This will reload the current file and hopefully display it correctly.

Save file :

Finally, if the changes you made to the file are correct, make sure to save the file using the following command:

:w

This will save the changes and exit Vim.

Terminal font settings :

If the above steps don't work, you can also check your terminal's font settings to make sure it supports the desired character encoding. Choosing a font that supports UTF-8 encoding may help display Chinese characters.

Guess you like

Origin blog.csdn.net/JttiSEO/article/details/132832202