即使文件模式明确为 DOS,gVim 也会显示回车 (^M) [英] gVim showing carriage return (^M) even when file mode is explicitly DOS

查看:37
本文介绍了即使文件模式明确为 DOS,gVim 也会显示回车 (^M)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上使用 gVim.我的代码在行尾显示 ^M 字符.我使用 :set ff=dos 无济于事.^M 字符保留用于现有行,但不会出现在我输入的换行符中.我已将模式切换到 mac(显示 ^J 字符)和 unix(还显示 ^M 字符)并返回到 dos.有没有其他人看到这个?

I'm using gVim on Windows. My code shows ^M characters at the end of lines. I used :set ff=dos to no avail. The ^M characters remain for existing lines, but don't show up for newlines I enter. I've switched modes to mac (shows ^J characters) and unix (also shows ^M characters) and back to dos. Has anyone else seen this?

推荐答案

当您混合使用 Windows 行尾和 Unix 行尾时,会发生这种情况.如果您有 100 行,其中 99 行是 \r\n,而 1 行是 \n,您将看到 99 个 ^M 字符.解决方法是找到那一行并替换它.或者在文件上运行 dos2unix.您可以将 Windows 行结尾替换为:

This happens when you have a mixture of Windows line endings and Unix ones. If you have 100 lines, 99 are \r\n and one is \n, you'll see 99 ^M characters. The fix is to find that one line and replace it. Or run dos2unix on the file. You can replace the Windows line endings with:

:%s/\r\(\n\)/\1/g

这篇关于即使文件模式明确为 DOS,gVim 也会显示回车 (^M)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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