Become root inside vim
Scenario
- When you editing file(file which required root permission to edit) via vim without
sudo, vim won't allow you to save the file - For an example
vim /etc/hosts
- When doing changes vim says

- When saving file vim syas

Solution
- To overcome this problem you can type following command in vim
:w !sudo tee %
- Then vim will prompt for sudo password

- Finally hit
Lto load the changes into vim

Written by eranga bandara
Related protips
1 Response
Put the following into vimrc for convenient if you always forgot sudo.
"Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#