Introduction

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!

Solution

Don’t discard your changes and start from scratch!

Try this instead:

:w !sudo tee%

Then type:

O

to move on. Since the file is still open read-only. Just exit normally with :q!

Thanks to Adam for his great post!

http://www.geekyboy.com/archives/629

 

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.