使用 VIM 清理 ^M 符号

更新日期: 2019-08-28 阅读次数: 7512 字数: 132 分类: Vim

在 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

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式