Vim:Mac 与 Linux ^M 问题
我使用 Vim 和 GIT 在 Linux/Ubuntu 机器上开发我的项目。以前我用的是Windows,这意味着行尾是DOS格式。现在,在迁移到 Linux 后,我总是在行尾看到 ^M 令人困惑/烦人的字符。这里有人:
如何将 ^M 换行符转换为在 vim 中打开的文件中的“正常”换行符?
建议我应该进行查找/替换或使用 dos2unix 等工具。这些都是很好的建议,但是对于版本控制的项目,这意味着我必须在更改后为文件添加不必要的提交,无论如何,这是一项艰巨的任务,不值得花时间在上面。那么:
有什么办法可以让 Vim 容忍这种情况吗?也就是说,如果文件是 DOS 行结束的,它会保持这样,并使用其格式作为新的换行符,依此类推。
I use Vim and GIT to develop my project on a Linux/Ubuntu machine. In the past, I used to use Windows, which means line ends were DOS format. Now after moving to Linux, I always see ^M confusing/annoying characters at the end of the line. Some people here:
How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?
suggested that I should make a find/replace or use tools like dos2unix. These are good suggestions, but with a version-controlled project it means I have to add unnecessary commits for the files after change, and it is a big task anyway that is not worth spending time on it. So:
Is there anyway to make Vim tolerant for this? That is, if the file is DOS line-ended, it keeps it like this, and use its formatting for new newlines, and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已将此行添加到我的 .vimrc 文件中。
如果您不知道 vimrc 文件是什么,它只是配置(并允许您自定义)vim 的文件。默认情况下,vim 将在用户的主文件夹中查找名为 .vimrc 的文件(注意开头的点)。如果找不到它,它将从 /etc/vimrc 获取它。
I have added this line to my .vimrc file.
If you don't know what a vimrc file is, it's simply the file that configure (and allows you to customize) your vim. By default vim will be looking for a file called .vimrc (notice the dot at the beginning) in the user's home folder. If it cannot find it, it will source it from /etc/vimrc.
是的,你可以在 vim 中设置以下内容来表示它是 dos 格式文件:
并且,同样:
Yes, you can set the following in vim to say it's a dos format file:
And, likewise:
我找到的最好答案是 @Keith 在评论中的回答:
“通过 subversion,你可以设置一个属性 svn:eol-style=native,这将导致它自动将行结尾转换为..所有平台的本机类型。我不知道 git 是否有这个功能,但你可能会先研究一下它可能有。”
而这些链接可能有用的链接是如何设置的:
http://help.github.com/dealing-with-lineendings/
http://git-scm.com/docs/gitattributes
The best answer I found is @Keith answer in the comments:
"With subversion you can set a property svn:eol-style=native that will cause it to convert line endings to.. native type for all platforms automatically. I don't know if git has that feature, but you might look into that first. It probably does."
And these links might be useful link is how to set:
http://help.github.com/dealing-with-lineendings/
http://git-scm.com/docs/gitattributes