I opened a file in readonly mode; is there a way to get out of readonly mode?
In addition to Michael Mrozek's answer, you can add a line to your
.vimrc that allows you to write to a file that you have neglected to open with elevated permissions:
" Allows writing to files with root priviledges cmap w!! w !sudo tee % > /dev/null
If the file is read only, you have only to enter :w!!, you will be prompted for your password and then the file will be successfully written to.
:set noro does the job, it doesn't check if the file is opened by another vim instance or updates the file if changed externally.
In order to make it editable and check for swap files (which is the default opening a file with vim) just use the edit command (:help edit):
Note, if the file has been manipulated ever since (even outside of vim), it will update the changes in the current buffer (which I find normally desirable).
Here I go, although a bit late, maybe you already solved your doubt ;) I haven't seen in any of the comments a way I know with vim, so, I add it:
Once you are editing a file, you press
:wq, and you see the annoying message "E45 'readonly' option is set (add ! to override)"
You can type
:w !sudo tee %
wwrites the buffer,
!sudocalls the shell with sudo,
teeredirects the output of
vim :wto the output with tee, and
%is the current filename
And that should do the trick. Note that this will prompt to reload the file in vim, for what you have to press L