^M at the end of every line in vim

2019-01-08 05:42发布

When I am editing source files using vim and other editors sometimes at the end of the line I get these ^M characters at the end of each line. I think that it has something to do with editing a file in windows and then in linux. How can I remove all of these automatically?

9条回答
我想做一个坏孩纸
2楼-- · 2019-01-08 06:07

I tend to run afflicted files through fromdos before reopening them. fromdos is part of the tofrodos package.

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-08 06:08

As a command, type

:%s/^M$//

(To get ^M, press ^V ^M, where ^ is CTRL on most keyboards)

查看更多
Lonely孤独者°
4楼-- · 2019-01-08 06:10

mcedit: shift+f2, set unix format (LF), ok

查看更多
登录 后发表回答