Why would Vim add a new line at the end of a file?

发布时间:2021-07-24 14:26:09 阅读:1061次

https://stackoverflow.com/questions/14171254/why-would-vim-add-a-new-line-at-the-end-of-a-file

I work with wordpress a lot, and sometimes I changed wordpress core files temporarily in order to understand what is going on, especially when debugging. Today I got a little surprise. When I was ready to commit my changes to my git repository, I noticed that git status was marking one of wordpress' files as not staged for commit. I remember I had reverted all the changes I did to that file before closing it, so I decided to use diff to see what had changed. I compared the file on my project with the file on the wordpress copy that I keep in my downloads directory. It turns out the files differ at the very end. diff indicates that the there is a newline missing at the end of the original file:

1724c1724
< }
\ No newline at end of file
---
> }

I never even touched that line. The changes I made where somewhere in the middle of a large file. This leads me to think that vim added a newline character at the end of the file. Why would that happen?

:set noeol

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:Why would Vim add a new line at the end of a file? 出自老鄢博客 | 欢迎分享