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%

Then type:


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
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.