Save a file in Vim after editing and only realizing it's read only when saving
If you've used Debian or any other type of Linux or Unix-like for editing files on your server, at some point you will have done a whole bunch of editing without seeing the "READ ONLY" warning, and then... you try to save.
Sometimes, throwing an exclamation point on your w is enough:
:w!
http://uw714doc.sco.com/en/FD_create/Stopping_vi.html
having to search for something as simple as this is what I get for using the ZZ shortcut all the time.
Does not always work.
That is, you should sudo vi document.txt up front when needed.
But if you've done all this editing you don't want to lose, all is not lost! Save it to your user directory:
:w! ~/tempfile.txt
And then just copy over that mean readonly file, using sudo this time:
sudo mv ~/tempfile.txt meanreadonly.txt
Resolution
More like this
- Saving a read-only file after making a lot of changes before finding out
- Including a file in a bash script: that's what dot file does
- Fighting with Drupal.org's CVS: nothing known about module files and sticky tags not valid
- Update or commit: See what's changed in a version-controlled file with svn diff
- Resolve a conflict to use local files after a merge goes bad in git pull


Comments
A Better Way
:w !sudo tee %
http://www.cyberciti.biz/faq/vim-vi-text-editor-save-file-without-root-permission/
Post new comment