Vi/vim display Chinese characters and remove the ^m method

Source: Internet
Author: User

vim often encounter the phenomenon of abnormal Chinese display, which is the legendary garbled. A search, found a solution in http://www.chinalinuxpub.com/bbs/showthread.php?t=45475. But the GBK code is normal, and the UTF8 is wrong. So a little bit changed. Create a. vimrc file in the user directory join set fileencodings=utf-8,gb2312,gbk,gb18030 set Termencoding=utf-8 set Fileformats=unix set encoding= The PRC fileencodings utf-8 to be in front.

This will show the Chinese as normal. With Pietty, can be completely normal display, editing Chinese.

Several methods of removing ^m

1. Cat Filename1 | Tr-d "\ r" > NewFile

2. Sed-e "s/^v^m//" filename > OutputFileName

3, vi: Open file with VI

1. Press the ESC key

2. Input:%s/^m//g

Make sure that ^m is using "Ctrl-v ctrl-m" instead of literally ^m. This regular will replace all carriage returns before the ^m is empty ($ is to ensure that ^m appear at the end of the line) 4, some Linux version has Dos2unix program, can be used to eliminate ^m

5, with Vim

Input: Set Notextmode

Unfortunately, after the above processing, ^m does not exist, but the line is not successful. Everything was on the line and looked very laborious. This means that the file is missing "\ n" when it is processed and can be added at the time of substitution:

Cat FileName | TR "\ r" "\ n" > NewFile

Vi/vim display Chinese characters and remove the ^m method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.