Alex Rivera | Logout

Save file as root after editing as non-root

Asked 2010-12-19T17:29:33.537
25

Ok so this happens to me all the time. There has to be a better solution. Let's say you do vim /etc/somefile.conf and then you do i but realize you are not sudo and you can't write. So then I lose my changes by doing :q then sudo !! and make my changes again. Is there a better way to do this?

Edit
Report

2 Answers

1

Save the file elsewhere (like your home folder) and then sudo mv it to overwrite the original?

answered 2010-12-19T17:32:43.940
0

When vim starts up, the statusbar says [readonly], and the first time you try to edit, it says W10: Warning: Changing a readonly file and pauses for a full second. This is enough warning for me to quit and say sudoedit /etc/somefile.conf.

You can enforce this with a plugin: Make buffer modifiable state match file readonly state.

answered 2010-12-19T17:32:31.167

Your Answer