^m line break in the vim replacement file under Linux

Source: Internet
Author: User

Open the edited text of Windows under Linux, and there will be an issue with content formatting that is inconsistent with line breaks. The most common is the appearance of ^m.

my problem is: in Windows edited files, uploaded to Linux and then opened with Vim, the content is not wrapped. That is, all the file contents are on one line. And then the actual line of the position more than a ^m.

The following method is searched online. One of the Dos2unix also has a relative Unix2dos

1. Use the Dos2unix command. This gadget is available in the general distribution version (if it is not available to download according to the following connection), it is convenient to use: $ dos2unix myfile.txt The above command will remove the ^m at the end of the line.
2. Use the Replace function of VI. Launch VI, enter command mode, enter the following command::%s/^m$//g # Remove the ^m at the end of the line. :%s/^m//g # Remove all the ^m. :%s/^m/[ctrl-v]+[enter]/g # Replace ^m with a carriage return. (I tuned it in this way):%s/^m/\r/g # Replace ^m with a carriage return.
3. use the SED command. Similar to the use of VI: $ Sed-e ' s/^m/\n/g ' myfile.txt Note: Here the "^m" is generated using "Ctrl-v ctrl-m" instead of typing "^m" directly.
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.