Can you force Vim to show a blank line at the end of a file?

前端 未结 4 1955
你的背包
你的背包 2021-02-13 20:14

When I open a text file in Notepad, it shows a blank line if there is a carriage return at the end of the last line containing text. However, in Vim it does not show this blank

4条回答
  •  长发绾君心
    2021-02-13 20:27

    It seems that vim treats newline as a line terminator, while notepad treats it as a line separator: from http://en.wikipedia.org/wiki/Newline

    There is also some confusion whether newlines terminate or separate lines. If a newline is considered a separator, there will be no newline after the last line of a file. The general convention on most systems is to add a newline even after the last line, i.e., to treat newline as a line terminator. Some programs have problems processing the last line of a file if it isn't newline terminated. Conversely, programs that expect newline to be used as a separator will interpret a final newline as starting a new (empty) line. This can result in a different line count being reported for the file, but is otherwise generally harmless.

    If I recall correctly, on unix-y systems a text file must be terminated with a newline.

提交回复
热议问题