Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It is not enough to just check vim's
'ro'
option and only write a buffer when it is unset. For one,'ro'
may be (or become) unset even when the file is unwritable. By default, vim also unsets'ro'
after writing a readonly buffer, regardless of whether the file permissions have changed or not (see also theZ
flag from the'cpo'
option). Even when unset, vim will prompt (or error if'confirm'
is unset) every time to write a buffer whose file has insufficient permissions to do a simple write (i.e. a write w/o resorting to acp
ormv
of the file), which can quickly become annoying when the writing is done frequently/automatically.Additional Comments
In the future, consider allowing the user to opt-into forcefully writing readonly buffers. There could also be an option to ignore any resulting errors in this case as well. These options might not be very safe though, and they would require
W
to be absent from'cpo'
.