Remove or replace ^ m characters in vim

Source: Internet
Author: User

Vim remove or replace ^ m character replace or replace ^ M character in Linux use vi to view some text files created in Windows, sometimes you will find some "^ M" at the end of the row ". There are several methods for processing. 1. Use the dos2unix command. This tool is included in the general distribution version (if not, you can download the tool based on the following connection). It is very convenient to use: $ dos2unix myfile.txt the command above will remove the ^ M at the end of the line. 2. Use the replacement function of vi. Start vi and enter the command mode. Enter the following command: % s/^ M $ // g # Remove ^ M at the end of the line. : % S/^ M // g # Remove all ^ M. : % S/^ M/[ctrl-v] + [enter]/g # Replace ^ M with the carriage return. : % S/^ M/\ r/g # Replace ^ M with the carriage return. 3. Use the sed command. Similar to vi usage: $ sed-e's/^ M/\ n/G' myfile.txt Note: Here "^ M" is generated using the CTRL-V CTRL-M, instead of directly typing "^ M"

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.