sudo and vim
For all those who started modifying a system file and got stuck with permission errors when trying to save their modifications, here's the magic command:
:w !sudo tee %
And if you're afraid that you may not always remember that, you can set the following mapping in your .vimrc
:
" Force saving files that require root permission
cmap w!! w !sudo tee > /dev/null %
Then, you can simply use:
:w!!
Source: this SO question.
Written by Benjamin Chrétien
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#