如何在 VIM 中隐藏 eol 文档字符 ^M
在 Windows 上的 gvim
中,如果我有带有 CRLF
eol
的文本,那么文本将在末尾显示 ^M
每行。
如何从显示中“隐藏”该特殊字符?
:set nolist 命令 """
不会忽略它。
更新
我将 :set fileformats=unix,dos
作为列表。一开始它不起作用,但是我关闭了该文件并重新打开它,
默认情况下我已将文件格式设置为仅 unix 值,
谢谢您的回答。
In gvim
on windows if I have text with CRLF
eol
then the text will display ^M
at the end of each line.
How do I 'hide' that special char from display?
The :set nolist command """
does not dismiss it.
UPDATE
I did :set fileformats=unix,dos
as a list. It didn't work at first, but I closed the file and reopened it again and it worked.
By default I had set fileformats to only unix value.
Thanks for answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可能需要将
fileformat
设置为dos
。You may want to set
fileformat
todos
.隐藏它们:
删除它们(以便稍后可以将文件另存为 unix 文件):
To hide them:
To remove them (so you can later save the file as a unix file):
虽然一劳永逸地使用 DOS 或 Unix 格式召开会议当然是更好的方法,但有时一些同事只是不太关心正确的源代码管理,无法让他们的编辑器表现良好。
在那些绝望的情况下,我发现与其完全转换文件(导致文件完全由您自己根据SCM重写,使“责备”功能无用),不如假装问题不存在。如果编译器是兼容的,并且 PHP 无论如何都是这样,那么您可以使用以下命令让混合 EOL 文件看起来非常酷:
或者在较新版本的 VIM 7.4+ 中
,让事情变得更糟,大多数 GUI 编辑器不会以换行符结束文本文件,并且当文件以换行符结束时,它们会在底部显示一个空行。因为这有点烦人,所以大多数人会删除那个空行,如果文件格式是 DOS,这将导致混合 EOL 文件(以及 Vim 中显示的可怕的 ^M)。
如果有人知道如何使 Eclipse 或 NetBeans 遵循换行符终止而不显示空的最后一行(正如 Vim 巧妙地做到的那样),请分享您的知识,您将使这里的编码员感到高兴。 ;-)
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.
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:
Or in newer versions of VIM 7.4+
To make things even worse, most GUI editors don't end 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.
If anyone knows how to make Eclipse or NetBeans honor the newline termination without showing the empty last line (as Vim cleverly does), please share your knowledge and you'll make a coder happy here. ;-)
通常会自动检测文件格式。您的文件中必须混合有 Unix 和 DOS/Windows 行。
尝试这个来清理它(其中“clean”= unix 格式):
The file format is usually automatically detected. You must have mixed Unix and DOS/Windows lines in your file.
try this to clean it up (where "clean" = unix format):
我想指出的是,如果你使用完整的 VIM(至少在我的 ubuntu 9.10 盒子上),它会“做你想做的事”并自动隐藏它,但普通 vi(和 vim-tiny)不会自动隐藏-隐藏^M。如果您进行最小安装(或服务器安装),您将仅获得 vi 和 vim-tiny。我发现的修复方法是在我的 ubuntu 机器上安装正确的 vim (apt-get install vim)。希望能帮助那些出于与我相同的原因参与此主题的人:-D
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
使用命令:
use the command:
当我的 neovim 在
node_modules
的一些文件中向我展示这些丑陋的^M
时,我通过向BufWinEnter
添加以下代码来修复此问题:When my neovim showed me these ugly
^M
in some files fromnode_modules
, I fixed this by adding following code toBufWinEnter
: