Mar
18
Save as root in vim
Do you ever finish up editing a config file only to realize you forgot to open it with sudo
and therefore can't save? This simple one liner from Peteris Krumins’ blog is a godsend.
:w !
tells vim to pass the entire file in the buffer to stdin
of the next command. The command tee writes stdin
to a file. The character %
tells vim to pass the current file name so you end up using tee
running as root to write the vim buffer back to the original file.