Vim: Saving a read only file when you forgot to sudo

Often you’ll forget that you weren’t on sudo when you started editing a file, you’ll try to save it and will complain that it’s in folder for which you do not have permissions to save it. Instead of discarding the changes you can still save it as sudo.

:w !sudo tee % > /dev/null