Last Updated: October 07, 2020
·
5.153K
· underhilllabs

vim :w!!

Place the following in your .vimrc file

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

Then when you need to make changes to a system file, you can override the read-only permissions by typing :w!!, vim will ask for your sudo password and save your changes.

6 Responses
Add your response

Great tip!

This plugin: https://github.com/tpope/vim-eunuch allows similar behaviour.

over 1 year ago ·

works perfectly, thanks

over 1 year ago ·

This is a great tip! Thanks for saving me so many (:q! sudo !!)s

over 1 year ago ·

I prefer cmap w!! w !sudo tee %

over 1 year ago ·

This is gold, thanks

over 1 year ago ·

Excellent.

over 1 year ago ·