Vim Scoops / Lessons / E45: 'readonly' option is set

E45: 'readonly' option is set

E45 means Vim opened the file read-only, so :w refuses. Use :w! to save anyway. If you don't have permission to write the file, :w !sudo tee % saves it with sudo.

The keys

KeysWhat they do
:w!Save anyway
:set noreadonlyTurn read-only off, then :w as normal
:w !sudo tee %Save a file you need sudo for
:w ~/notes.txtSave a copy somewhere you can write

Files open read-only when you start Vim with view or vim -R, when you pick O at a swap file warning, or when you don't have permission to write the file.

In that last case :w! fails too, with E212. That's when the sudo trick, or saving a copy elsewhere, comes in.

Related

Want all of Vim, in order? Vim Scoops is a free game that starts at h j k l and builds up to macros.

Play the full game