Saving a read-only file in VIM

Since I use Digital Ocean and Linode cloud VPS, I need to use VIM a lot when I need to update configuration files on server. And this happens to me a lot. Trying to save a read-only file after modifying lots of lines. It is a frustrating situation. Then I found this blog post http://www.geekyboy.com/archives/629. You can actually save a read-only file in VIM!

This is the command :w !sudo tee %

You may read detail explanation on how the command works here. http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work/7078429#7078429

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s