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

查看:139
本文介绍了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.

使用设置列表:

我可以看到有一个 $ 字符表示最后一行之后的新行,但这也会用这些字符散布文件的其余部分.我知道我可以为此设置一个切换,但我真的更喜欢类似 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" != "new line".

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天全站免登陆