如何在 Vim 中编辑文件,所有行都以 ^M 结尾,但最后一行以 ^M^J 结尾 [英] How to edit a file in Vim with all lines ending in ^M except the last line ending in ^M^J

查看:49
本文介绍了如何在 Vim 中编辑文件,所有行都以 ^M 结尾,但最后一行以 ^M^J 结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆文件需要查看.这些文件中的所有行都以 ^M (\x0D) 结尾,但最后一行以 ^M^J (\x0D\x0A) 结尾.

I have a bunch of files that I need to look at. All lines in these files end in ^M (\x0D) except the very last line that ends in ^M^J (\x0D\x0A).

显然,Vim 将文件类型确定为 DOS,效果是文件的整个内容是像这样显示在一行上:

Obviously, Vim determines the filetype to be DOS with the effect that the file's entire content is displayed on one single line like so:

some text foo^Mmore text and^Ma few control-m^Ms and more and more

由于我不想更改文件的内容:Vim 中是否有允许查看这些文件的设置像我期望的那样带有新行的文件?

Since I don't want to change the files' content: is there a setting in Vim that allows to look at these files with the new lines as I'd expect them to be?

推荐答案

如果你不介意底部有一行包含单个 ^J 字符,你可以设置 fileformats(注意末尾的 s)到 mac 并重新加载缓冲区:

If you do not mind having a line at the bottom containing a single ^J character, you can set fileformats (note the s at the end) to mac and reload the buffer:

:set fileformats=mac
:edit

或者等效地,您可以按如下方式启动编辑器:

Or equivalently you could start the editor as follows:

vim -R "+set fileformats=mac" "+edit" <filename>

存在 -R(只读)选项是因为您声明不想更改文件.

The -R (readonly) option is there because you stated you do not want to change the files.

我没有找到不涉及重新加载缓冲区的方法.

I did not find a way that does not involve reloading the buffer.

这篇关于如何在 Vim 中编辑文件,所有行都以 ^M 结尾,但最后一行以 ^M^J 结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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