Susam Profile picture
8 May, 3 tweets, 3 min read
The famous Vim sudo-write trick: You open a file, edit it, and save it only to get the E45 error message. You now realize that only root can edit the file. What do you? Start over? No, instead try this:

:w !sudo tee "%"

Learnt it from vim.fandom.com/wiki/Su-write?… back in 2005.

#vim
How does :w !sudo tee "%" work?

:w !{cmd} - Executes {cmd} with all lines in buffer as standard input.

% - Expands to current filename. Quotes around it keep it as a single argument even if the filename contains whitespace.

tee {file} - Copies stdin to stdout and {file}.

#vim
For more information on the command :w !sudo tee "%", enter the following commands in Vim:

:help :w_c
:help current-file
:help :_%

Also, enter the following command in shell:

man tee

I hope this was fun!

#vim #unix #linux #shell #programming

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Susam

Susam Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @susam

11 Apr 20
How do you feel about all the viral brain teasers being circulated on social media? Here is how I feel about them: xkcd.com/169/ Image
But here is how I really react to them: xkcd.com/356/ Image
Can't help myself from being nerd-sniped regardless of how frivolous these brain teasers are.
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(