Ever started editing a document only to find out that when trying to save it
:wq, you forgot to open it with sudo? Vim knows what to do and gives you a hint saying “add ! to override”.
Instead of having to save it to a temp directory
:w ~/temp then exiting and having to move it to the real location. Use the following the next time:
:w ! sudo tee %
This invokes the write function
:w and opens a new shell
! and pipes your files contents via standard out into the program
tee with sudo privileges.
tee is an amazing program which outputs the contents of stdin to stdout and to a file. In this case the filename is the vim shortcode
Enjoy a new way to save your vim files.