Getting root permission to change a file without leaving Vim
You know when you open a file on Vim and after some changes you realise you'd need root
permission to save the changes?
I used to think that there isn't other way other than:
- Copy the content of the file
- Close Vim
- Re-open it with
sudo
- And finally paste it again
It might be a bit harder if you're using Vim on a remote SSH session.
Well, it will no longer be a problem. Today I learned a neat way to achive the same thing:
viml:w !sudo tee %
Thanks my friend Diogo Lisboa for the tip.