如何判断vim何时添加了EOL字符

时间:2013-10-23 15:37:42

标签: vim newline eol

当文件末尾有换行符时,我怎么能在vim中看到?似乎vim总是显示一个,无论它是否真的存在。

例如,打开最后有换行符的文件:

echo "hi" > hi
# confirm that there are 3 characters, because of the extra newline added by echo
wc -c hi 
# open in binary mode to prevent vim from adding its own newline
vim -b hi
:set list

这表明:

hi$

现在比较一下,没有换行符的文件:

# prevent echo from adding newline
echo -n "hi" > hi
# confirm that there are only 2 characters now
wc -c hi 
# open in binary mode to prevent vim from adding its own newline
vim -b hi
:set list

仍显示:

hi$

那么我如何才能看到文件最终是否真的有一个换行符在vim中?

3 个答案:

答案 0 :(得分:1)

Vim将此信息存储在'endofline'缓冲区选项中。您可以查看

:setlocal eol?

答案 1 :(得分:1)

在第二种情况下,Vim在加载文件时显示[noeol]

加载该文件时,您是否看到[noeol]输出?

答案 2 :(得分:1)

Vim在最后一行末尾打开/写入没有<EOL>的文件时会发出警告:

"filename" [noeol] 4L, 38C
"filename" [noeol] 6L, 67C written