What is `^M` and how do I get rid of it?

在Vim中打开文件出现奇怪的特殊字符,因搜索引擎对特殊字符查询效果不佳,提出问题:该字符是什么、如何产生、怎样去除。还提到使用:e ++ff=dos命令让Vim重读文件,强制采用dos文件格式,去除特定行尾符。

When I open the file in vim, I am seeing strange ^M characters.

Unfortunately, the world's favorite search engine does not do well with special characters in queries, so I'm asking here:

  • What is this ^M character?

  • How could it have gotten there?

  • How do I get rid of it?

he ^M is a carriage-return character. If you see this, you're probably looking at a file that originated in the DOS/Windows world, where an end-of-line is marked by a carriage return/newline pair, whereas in the Unix world, end-of-line is marked by a single newline.

A simpler way to do this is to use the following command:(需要安装该工具:yum install dos2unix)
dos2unix filename
This command works with path patterns as well, Eg
dos2unix path/name*
If it doesn't work, try using different mode:
dos2unix -c mac filename
-c Set conversion mode. Where CONVMODE is one of: ascii, 7bit, iso, mac with ascii being the default.
 
其它方法:
:e ++ff=dos 

The :e ++ff=dos command tells Vim to read the file again, forcing dos file format. Vim will remove CRLF and LF-only line endings, leaving only the text of each line in the buffer.

then

:set ff=unix 

and finally

:wq 

转载于:https://www.cnblogs.com/rusking/p/10575794.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值