This is a critical trick for using VIM.
Here's the scenario: you've opened up a file that you don't have write permissions for. You've taken all this time to make all these edits, then you
:wq to get outta there and BOOM!
You forgot, you needed to sudo to edit the file.
I do this all the time when editing
What's the solution?
Turns out it's really simple:
:w !sudo tee %>/dev/null
That's it. It'll prompt you for your password, and you'll be able to write the file and quit. Lifesaving technique here.
If you're interested in how this works, I have a quick explanation over at my blog.
Hope this tip was useful for you!
If you're interested in Linux, VIM, Python, Django, React Native, and many other things, follow me here on dev.to or on Twitter @connorbode.
I'll keep posting the stuff I find useful!