Scenario: A file encoding for UTF-8, UNIX system encoding settings are also UTF-8, through Putty to connect to the Unix server, with VI open the file, displays garbled.
1, view UNIX system encoding (locale command): confirmed as UTF-8
Lang = en_GB.UTF-8
Lc_ctype = en_GB.UTF-8
Lc_numeric = en_GB.UTF-8
Lc_time = "en_GB.UTF-8"
Lc_collate = en_GB.UTF-8
Lc_monetary = en_GB.UTF-8
Lc_messages = "en_GB.UTF-8"
Lc_all= en_GB.UTF-8
If not, you can set the current session encoding to a en_GB.UTF-8 by setting export lc_all = UTF-8
2, the file encoding confirmed as UTF-8, UNIX system encoding is also UTF-8, why VI opened after the display of garbled? The problem lies in the putty settings. You also need to set the process of transferring data from UNIX to the local display of putty. The putty menu is change settings --> window --> translation. select 'stored data assumed to be in which character set' as a UTF-8.
3. Use VI to open the file and display it normally.
* In Windows: If the CMD cannot display Chinese characters or other characters normally, use chcp to modify the parameter. The NNN parameter represents three numbers. The codePage in simplified Chinese is: 936 (Spanish): 1252
Syntax
Chcp [nnn]: chcp 936