A simple but annoying one. You open a configuration file with no intent to change anything, then you think I’ll just change that .. and this.. and 20 minutes later when you go to save you realise you opened the file read-only! Argghhh!
Don’t discard your changes and start from scratch!
Try this instead:
:w !sudo tee%
to move on. Since the file is still open read-only. Just exit normally with :q!
Thanks to Adam for his great post!
Saving a read-only file edited in vi / vim