VIMs SUDO SAVE
###################

Started writing a file and forgot to sudo, thus cant save it because missing permissions?

Well here is the command to sudo the save:

:w !sudo tee %

To make that easier put this in your ~/.vimrc (for every user that uses vim, no need to do that on root user):

cmap w!! w !sudo tee > /dev/null %

Now if you mess up just type:

:w!!

For an indepth WTF is going on, check this out: http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work

Note: after running this command, it might say there is a newer version of the file, and press L to load that. Press L and hit Enter if it asks that

Leave a Reply

Your email address will not be published. Required fields are marked *