If you ever worked on an SSH session on a remote machine and tried to edit a file that requires super user permissions you might be familiar with the following scenario:
sudo vim ...paste your changes and save. Hopefully everything went smoothly and you did not lose your changes.
No more! Next time this happens try this:
:w !sudo tee %
I hope it saves you some frustration.