使用 VIM 清理 ^M 符号

发布时间: 2019-08-28 20:56:20 作者: 大象笔记

在 Ubuntu VIm 中打开了一个 Windows 上编辑过的代码文件,里面代码完全没有换行,只有大片的 ^M 符号。乱得完全无法阅读。

^M 符号是什么

Unix uses 0xA for a newline character. Windows uses a combination of two characters: 0xD 0xA. 0xD is the carriage return character. ^M happens to be the way vim displays 0xD (0x0D = 13, M is the 13th letter in the English alphabet).

windows 上的换行符是 \r\n, 在 VIM 中展示为 ^M.

VIM 清理 ^M 符号的方法

:%s/\r/\r/g

参考

https://stackoverflow.com/questions/5843495/what-does-m-character-mean-in-vim

我是一名山东烟台的开发者,联系作者