Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I opened a file in readonly mode; is there a way to get out of readonly mode?

share|improve this question
What are the limitation in readonly mode that are bothering you? If it's just that you want to write the file, even though you opend it read only, then adding a! to the w command will do the trick, as Michael stated. – Bananguin Apr 4 '13 at 11:59
@user1129682 it's just the inconvenience of remembering to put an exclamation mark after w every time I want to save. heh – wrongusername Apr 4 '13 at 20:01

You could do this:

:set noro

That unsets the read-only flag, but if the underlying file is still not writable by you then vim still will be unable to write to it.

share|improve this answer

You can run chmod from within vim:

:!chmod +w %

! means run a shell command, and % is the current filename. You can also just force the file write:

share|improve this answer

Type :q! to quit without saving anything (since this is a read-only file).

share|improve this answer

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.

share|improve this answer

re-open your files with necessary privileges. for example:

sudo vim FILE_NAME

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.