How many times have you opened a file in vi which is owned by root, made changes, and then couldn’t save it because you didn’t sudo first? Sure, you could save it to an alternate location and then copy it into place, but the following is a handy trick:
:w !sudo tee % |
This will save your file in place provided you have sudo privileges.
Enjoy!