在 Vim 中将 DOS 行尾转换为 Linux 行尾 [英] Convert DOS line endings to Linux line endings in Vim

查看:52
本文介绍了在 Vim 中将 DOS 行尾转换为 Linux 行尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打开在 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 是一个命令行实用程序会这样做,或者 :%s/^M//g 会,如果你使用 Ctrl-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 设置的文档,以及 Vimwiki 有一个全面的关于行尾转换的页面.

There is documentation on the fileformat setting, and the Vim wiki has a comprehensive page on line ending conversions.

或者,如果你经常来回移动文件,你可能不想转换它们,而是执行 :set ff=dos,这样 Vim 就会知道这是一个 DOS 文件并使用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.

这篇关于在 Vim 中将 DOS 行尾转换为 Linux 行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆