Getting root permission to change a file without leaving Vim
You know when you open a file on Vim and after making changes and trying to save the file, Vim tells you that you need
root permission to do so?
This is what most people do to solve it:
- Copy the content of the file to my clipboard
- Close Vim
- Re-open it with
- Paste it and try to save it again
Well, turns out there's an easier way to achieve the same thing:
:w !sudo tee %
Thanks to my friend Diogo Lisboa for teaching me this!