Why do gedit and vim hide the final newline from the user?

痞子三分冷 提交于 2019-11-30 17:32:43
Ingo Karkat

That you perceive the last line as "visually hidden" stems from the opposite viewpoints.

Many people (especially with a Unix background) argue that text files should always end with a newline (e.g. see Why should text files end with a newline?), and that any text editor that allows to create files without it is fundamentally broken. From that perspective, that there is no additional empty line in Vim is only consistent with this world view. The file appears in the editor as it would when it is cated into the terminal.

From Vim's point of view, a file with a missing newline is heretical and defective; that's why it is indicated with the [noeol] message on load (and it is quite hard to edit the file while keeping the missing newline; though I've written the PreserveNoEOL plugin to aid with that).

I believe this is a convention, that is carried over from vi. One advantage of doing so, is that when concatenating files, you can still distinguish where each file ended.

Some more context is provided in this thread on the vim_use mailinglist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!