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"