如何阻止 VIM 在文件末尾添加换行符? [英] How to stop VIM from adding a newline at end of file?
问题描述
所以我在 PHP 商店工作,我们都使用不同的编辑器,而且我们都必须在 Windows 上工作.我使用vim,商店里的每个人都在抱怨,每当我编辑文件时,底部都会有一个换行符.我四处搜索,发现这是 vi & 的记录行为.vim ...但我想知道是否有某种方法可以禁用此功能.(如果我可以为特定的文件扩展名禁用它,那将是最好的.
So I work in a PHP shop, and we all use different editors, and we all have to work on Windows. I use vim, and everyone in the shop keeps complaining that whenever I edit a file there is a newline at the bottom. I've searched around and found that this is a documented behavior of vi & vim... but I was wondering if there was some way to disable this feature. (It would be best if I could disable it for specific file extensions).
如果有人知道这个,那就太好了!
If anyone knows about this, that would be great!
推荐答案
而且对于 vim
7.4+ 你可以使用(最好在你的 .vimrc 上)(感谢罗泽轩的最后一点消息!):
And for vim
7.4+ you can use (preferably on your .vimrc) (thanks to 罗泽轩 for that last bit of news!):
:set nofixendofline
现在关于 vim
的旧版本.
Now regarding older versions of vim
.
即使文件已经以新行的结尾保存:
Even if the file was already saved with new lines at the end:
vim -b 文件
还有一次在 vim 中:
vim -b file
and once in vim:
:set noeol
:wq
完成.
或者,您可以使用 :e ++bin file
另一种选择:
:set binary
:set noeol
:wq
在 为什么'noeol' 是否需要二进制模式的 vim 才能工作?
这篇关于如何阻止 VIM 在文件末尾添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!