Vim在文件末尾显示换行符 [英] Vim show newline at the end of file

查看:919
本文介绍了Vim在文件末尾显示换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用set eol选项,Vim在保存文件时会自动在文件末尾添加换行符.我启用了此选项,但我希望能够在Vim中看到此换行符,所以我知道它实际上就在其中.

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.

例如,在Vim中有一个文件:

For example with a file in Vim:

和TextMate中的相同文件:

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.

使用set list:

我可以看到在最后一行之后有一个$字符表示一个新行,但这也会用这些字符乱丢文件的其余部分.我知道我可以为此设置一个切换开关,但是我真的更喜欢像TextMate这样的行为.

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.

推荐答案

'endofline'默认情况下处于启用状态,因此您无需在~/.vimrc中使用它.

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

EOL或换行符"并不表示此后有空行",而是表示这标志着该行的结尾,任何其他字符都将显示在另一行上". "newline"!=换行".

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".

文件的最后一行是#21,并以换行符"结尾.由于该换行符"之后没有实际的行,因此没有行#22,显示行#22不仅是错误的,而且具有误导性.

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的行为是错误的.

TextMate's behavior is wrong.

Vim的举止是正确的.

Vim's behavior is correct.

如果您想让Vim显示第22行,则需要显式添加该行,但这对我来说听起来很愚蠢.

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

这篇关于Vim在文件末尾显示换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆