-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Information
VIM version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Sep 05 2025 19:44:46)
Included patches: 1-16, 647, 678, 697
Operating System: Linux (Ubuntu 24)
What went wrong
When opening a Rust file via a relative path (for example vim ../handlers/index.rs) and immediately saving the file, Vim reports the following error on the first save:
"-stdin-" E212: Can't open file for writing
After this happens:
- The buffer is marked as modified even though I did not edit anything
- I cannot quit with
:q - I need to press
utwice to clear the changes
Saving the file a second time works normally.
This issue does not happen if I first cd into the directory and then open the file (for example cd handlers && vim index.rs).
I have searched through both open and closed issues and could not find an existing report describing this behavior.
Reproducing the bug
- Start Vim from a directory that is not the Rust project root
- Open a Rust file using a relative path, e.g.:
vim ../handlers/index.rs - Immediately run
:w - Observe the error:
"-stdin-" E212: Can't open file for writing - Run
:changes, The output of:changesis:
change line col text
4 2 0 pub mod index;
3 4 0 -invalid-
2 4 0 -invalid-
1 3 0 pub mod logs;
The two -invalid- entries correspond exactly to the two undo steps required to clear the modified state. I did not manually edit the buffer.
Additional observations
- This only happens when the file is opened via a relative path and Vim’s current working directory is not the Rust project root.
- It looks like ALE’s Rust integration (rustfmt) may fall back to stdin-based formatting when the project root cannot be determined.
- This stdin-based formatting appears to replace the entire buffer, leaving it in a modified state and triggering the E212 error on the first save.
:ALEInfo
Error case:
Good case: