Picked this little tidbit up today, don’t know why it took me so long to figure it out….

If you are editing a file without sudo, and you need sudo in order to save and you don’t want to reopen the file because you’ve already made the edits, simply use this vim command:

:w !sudo tee %

It’s so simple too, uses that awesome little utility of tee to just pipe it back into the file and then vim recognizes that the file has changed on disk and prompts you to reopen it.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.