Vim show newline at the end of file

喜你入骨 提交于 2019-11-27 11:29:58

问题


Using the set eol option Vim automatically adds a newline to the end of the file when it's saved. I have this option on but I would like to be able to see this newline in Vim, so I know that it's actually there.

For example with a file in Vim:

And the same file in TextMate:

This always tricks me and I end up adding a second new line and end up realizing later. This exact same question was posted here but the answer that was accepted didn't answer this portion of the question.

Using set list:

I can see there is a $ character denoting a new line after the last line but this also litters the rest of the file with these. I know I could set up a toggle for this but I'd really prefer the TextMate like behavior.


回答1:


'endofline' is on by default so you don't need it in your ~/.vimrc.

EOL or "newline" doesn't mean "there's an empty line after here", it means "this marks the end of the line, any further characters are to be displayed on another line". "newline" != "new line".

The last line of your file is #21 and it ends with a "newline" character. Since there's no actual line after that "newline" character, no line #22, showing a line #22 is not only wrong but misleading.

TextMate's behavior is wrong.

Vim's behavior is correct.

If you want Vim to show a line #22, you'll need to explicitly add that line but it sounds rather silly to me.



来源:https://stackoverflow.com/questions/15639511/vim-show-newline-at-the-end-of-file

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