Save file in vi using sudo

If you edit a file with vi as normal user, but need superuser rights to save it, you can use this sequence to save it using sudo:

:w !sudo tee %

/hat tip to @nistude Show archive.org snapshot

Matthias Marschall Over 12 years ago