将DOS行结束转换为vim中的Linux行尾 [英] Convert DOS line endings to Linux line endings in vim
问题描述
如果我打开我在Windows中创建的文件,行全部以 ^ M
结尾。
如何一次删除这些字符?
If I open files I created in Windows, the lines all end with ^M
.
How do I delete these characters all at once?
推荐答案
dos2unix 是一个命令行实用程序,如果您使用 Ctrl - 将执行此操作,或:%s / ^ M // g
> v Ctrl - m 输入^ M,或者你可以:set ff = unix
并且vim将为您做。
dos2unix is a commandline utility that will do this, or :%s/^M//g
will if you use Ctrl-v Ctrl-m to input the ^M, or you can :set ff=unix
and vim will do it for you.
'fileformat'设置中的文档是这里,vim维基有一个全面的页面在线结束转换。
Docs on the 'fileformat' setting are here, and the vim wiki has a comprehensive page on line ending conversions.
另外,如果你来回移动文件很多,你可能不想要要转换它们,而是要做:set ff = dos
,所以vim会知道它是一个DOS f ile并使用DOS约定行尾。
Alternately, if you move files back and forth a lot, you might not want to convert them, but rather to do :set ff=dos
, so vim will know it's a DOS file and use DOS conventions for line endings.
这篇关于将DOS行结束转换为vim中的Linux行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!