How to save a file in vim without sudo vim filename

You can find more on that Here but it basically involves

:w !sudo tee %

This will pipe vim’s file buffer through tee after sudo’ing

 

So if ever you have opened the file already made a bunch of changes and then get rebuked with a Permission denied (or similar) you can simply execute the above and voila, the file is saved 🙂