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!

Steve Francis
Founder
Steve is the founder of LogicMonitor.
Subscribe to our LogicBlog to stay updated on the latest developments from LogicMonitor and get notified about blog posts from our world-class team of IT experts and engineers, as well as our leadership team with in-depth knowledge and decades of collective experience in delivering a product IT professionals love.