我一直在我的vimrc中获得^M
字符并且它破坏了我的配置。
#1楼
:%s/\r//g
今天为我工作。 但我的情况可能略有不同。
#2楼
在FreeBSD中,您可以通过键入以下内容手动清除^M
:
:%s/
Ctrl + V ,然后按Ctrl + M ,然后再按Ctrl + M.
#3楼
翻译新行而不是删除它:
:%s/\r/\r/g
#4楼
我有一个文本文件,最初是通过Mac用户在Windows机器上生成的,需要使用load data
命令将其导入Linux MySQL数据库。
虽然VIM显示'^ M'字符,但上述所有内容都不适合我的特定问题,数据会导入,但总是以某种方式损坏。 解决方案最终很容易(经过很多挫折)。
解决方案:在同一个文件上执行dos2unix
TWICE就可以了! 使用file
命令可以显示整个过程中发生的情况。
$ file 'file.txt'
file.txt: ASCII text, with CRLF, CR line terminators
$ dos2unix 'file.txt'
dos2unix: converting file file.txt to UNIX format ...
$ file 'file.txt'
file.txt: ASCII text, with CRLF line terminators
$ dos2unix 'file.txt'
dos2unix: converting file file.txt to UNIX format ...
$ file 'file.txt'
file.txt: ASCII text
并且文件的最终版本完美地导入到数据库中。
#5楼
我用sed将它们全部删除了:
sed -i -e 's/\\r//g'
也可以用不同的字符串或字符替换:
sed -i -e 's/\\r/string/g'
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3161111