Remove Vim ^m symbol

Source: Internet
Author: User

From: https://zhidao.baidu.com/question/267905868.html

There are two cases in which the open file appears with the ^m symbol:
1. Vim is configured as Fileformat=unix, and the files you open are in DOS format. The Unix-formatted newline character is 0A (ASCII) and the newline character in <lf>,dos format is 0D 0A (that is, <CR><LF>),<cr> is actually displayed as ^m.

Here is a detailed explanation: DOS, Mac, and UNIX-formatted files recall the prehistoric history of the computer, when the typewriter used two characters to start a new line. The first is a character command to move the printhead back to the start position (carriage return,<cr>), and the other character command controls the forward line (feed,<lf>).
At the beginning of the computer, storage devices were very expensive. Then someone suggested that it is not necessary to use two characters to indicate the end of a line. The Unix family decided to use only one character <LineFeed> to represent the end of the line. People from the Apple camp put the carriage return <CR> as the standard for line breaks.

MS-DOS (and Microsoft's Windows) still decided to follow the old carriage return line <CR><LF> tradition.
This also means that if you move files from one system to another, you will encounter problems with line breaks. The VIM Editor can recognize these files in different formats.
You can specify the set of formats you want Vim to recognize automatically in the ' fileformats ' option.

The following command allows vim to automatically recognize the UNIX format and MS-DOS format:

:Set Fileformats=unix,dos

Put this sentence in the _VIMRC, the general situation will be OK.
2. Your text has both a UNIX line break and a DOS newline, so vim will think you are opening UNIX, so those DOS line breaks will have annoying ^m. However, this is not a common situation. The approach is:
1) If your VIM version is greater than 7.1, and you want to display and save with DOS, the following statement:

: E ++ff=dos

2) If your VIM version is less than or equal to 7.1, and you want to display and save the article in DOS format, the following statement:

:set ff=dos:%s/\r\+$//e

3) If your VIM version is less than or equal to 7.1, and you want to display and save the article in UNIX format, the following statement:

:set ff=Unix:%s/\r\+$//e



Remove Vim ^m symbol

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.