it is easy:
:w !sudo tee %
that is it!
I don't know others. But when i use vim to edit a file, i alway forget that i may not have the needed permission to save it.
So quite often that after i did all my changes and found i can't save them, i have to exit vim and use 'sudo vim' to do it again.
This command really come in handy. But, what is tee?
tee is a command that displays or pipes the output of a command and copies it into a file or a variable. It is primarily used in conjunction with pipes and filters.
To know more about tee, check this: