Search code examples
vimnewlineeol

how to tell when vim has added EOL character


How I can see in vim when a file has a newline character at the end? It seems vim always shows one, whether it's truly there or not.

For example, opening a file that has a newline at the end:

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

This shows:

hi$

Now by comparison, a file without the newline:

# 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

Still shows:

hi$

So how can I see whether a file truly has a newline at the end or not in vim?


Solution

  • Vim stores this information in the 'endofline' buffer option. You can check with

    :setlocal eol?