windows 在 Vim 中如何隐藏 eol doc 字符 ^M

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1505978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:13:03  来源:igfitidea点击:

in Vim how do I hide the eol doc chars ^M

windowsvimnewlineeol

提问by marekj

in gvim on windows if I have text with CRLF eol then the text will display ^M at the end of each line.

在 Windows 上的 gvim 中,如果我有带有 CRLF eol 的文本,那么文本将在每行的末尾显示 ^M。

How do I 'hide' that special char from display?

如何从显示中“隐藏”那个特殊字符?

the :set nolist command """ does not dismiss it. I am stumped.

:set nolist 命令 """ 不会关闭它。我很难过。

UPDATE

更新

I did :set fileformats=unix,dos as a list but it didn't work at first. I closed the file and reopened it again and it worked. By default I had set fileformats to only unix value. Thanks for answers.

我做了 :set fileformats=unix,dos 作为列表,但一开始没有用。我关闭了文件并再次打开它,它起作用了。默认情况下,我将文件格式设置为仅 unix 值。感谢您的回答。

回答by Michael Krelin - hacker

You may want to set fileformatto dos.

您可能希望设置fileformatdos.

:ed ++ff=dos %

回答by jqno

To hide them:

隐藏它们:

:set fileformats=dos

To remove them (so you can later save the file as a unix file):

要删除它们(以便您以后可以将文件另存为 unix 文件):

:%s/\r//g

回答by wiz

While convening on the DOS or Unix format once and for all is of course the preferable approach, sometimes some co-workers just don't care enough about proper source management to make their editors behave.

虽然一劳永逸地使用 DOS 或 Unix 格式当然是更可取的方法,但有时一些同事只是不太关心适当的源代码管理来使他们的编辑器表现得很好。

In those desperate cases, instead of converting the file completely (resulting in a file completely rewritten by yourself according to the SCM, rendering the “blame” function useless), I found it preferable to just pretend that the problem doesn't exist. If the compiler is accommodating, and PHP by all means is, you can have a mixed-EOL file look perfectly cool with the following command:

在那些绝望的情况下,与其完全转换文件(导致文件完全由您自己根据 SCM 重写,使“责备”功能无用),我发现最好只是假装问题不存在。如果编译器是包容的,并且 PHP 无论如何都是,您可以使用以下命令使混合 EOL 文件看起来非常酷:

:match Invisible /\r$/

Or in newer versions of VIM 7.4+

或在较新版本的 VIM 7.4+ 中

:match Ignore /\r$/

To make things even worse, most GUI editors don'tend a text file with a newline, and when a file does end with a newline, they show an empty line at the bottom. Since this is kind of annoying, most people will remove that empty line, which will result in a mixed-EOL file (and the dreadful ^Ms shown in Vim) if the file format was DOS.

更糟糕的是,大多数 GUI 编辑器不会以换行符结束文本文件,并且当文件以换行符结束时,它们会在底部显示一个空行。由于这有点烦人,大多数人会删除那个空行,如果文件格式是 DOS,这将导致混合 EOL 文件(以及 Vim 中显示的可怕的 ^Ms)。

If anyone knows how to make Eclipse or NetBeans honor the newline termination without showing the empty last line (as Vim cleverly does), pleaseshare your knowledge and you'll make a coder happy here. ;-)

如果有人知道如何让 Eclipse 或 NetBeans 在不显示空的最后一行的情况下接受换行符终止(正如 Vim 巧妙地所做的那样),分享您的知识,您将在这里让编码人员感到高兴。;-)

回答by Roboprog

The file format is usually automatically detected. You must have mixed Unix and DOS/Windows lines in your file.

通常会自动检测文件格式。您的文件中必须混合有 Unix 和 DOS/Windows 行。

try this to clean it up (where "clean" = unix format):

试试这个来清理它(其中“clean”= unix格式):

% tr -d '5' < old.file > new.file

回答by Mark McCorkle

I'd like to point out that if you are using full blown VIM (at least on my ubuntu 9.10 box) it "does what you want" and auto-hides it, but the stock vi (and vim-tiny) do NOT auto-hide the ^M. If you do a minimal install (or server install) you get vi and vim-tiny only. The fix I found was to install proper vim (apt-get install vim) on my ubuntu box. Hope that helps someone that comes along this topic for the same reason I did :-D

我想指出的是,如果您使用的是完整的 VIM(至少在我的 ubuntu 9.10 盒子上),它会“做您想做的事”并自动隐藏它,但是库存 vi(和 vim-tiny)不会自动-隐藏^M。如果您进行最小安装(或服务器安装),您只会获得 vi 和 vim-tiny。我找到的解决方法是在我的 ubuntu 机器上安装正确的 vim(apt-get install vim)。希望能帮助到与我一样的原因的人:-D

回答by John Millikin

:0,$ s/<ctrl-v><ctrl-m>//g
:set ff=dos

回答by Lonzo

use the command:

使用命令:

:1,$ s/^v^M/ /g