Describe the bug
Reading from stdin (i.e. vim -) causes vim to mark the buffer as modified. This prevents a user from quitting with :q, and instead must resort to :q!. This behavior runs contrary to what is documented under :h --, which states that "The buffer will not be marked as modified, so that it's easy to exit".
This also prevents vim from opening to stdin in readonly mode, i.e. ls | vim -R - causes vim to exit with the error W10: Warning: Changing a readonly file, followed by Vim: Error reading input, exiting.... This entirely prevents the view command from reading from stdin.
To Reproduce
Run any command that produces output on stdout and pipe to vim -.
Examples:
echo "hello" | vim - # Opens with the string "hello", but must be closed with :q!
echo "hello" | vim -R - # Fails to open vim
echo "hello" | view # Fails to open vim
The behavior can also be reproduced by running vim - alone, typing in some text, then sending the EOF signal, for example:
vim - # Enter
this is a test # Enter
# ctrl-d
The bug does not occur when using the previous example with vim -R -, in which case the buffer is not marked as modified, and behavior is as expected.
Expected behavior
Vim should open with the contents of stdin. The buffer should not be marked as modified.
Environment:
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Thanks for the response Gary. Embarrassingly, I believe I may have been missing the ending dash when opening vim in readonly mode in my personal tests.
Nonetheless, the behavior still contradicts the documentation
—
You are receiving this because you commented.
To avoid marking the file as modified when r'eading from stdin, use view rather than vim as the pager command.
—
You are receiving this because you commented.
Fixed by ebdf3c9.
:h -- was updated to include this paragraph:
—
You are receiving this because you commented.