It’s a simple trick in Vim:
stackoverflow.com/a/7078429
For the lazy: :w !sudo tee > /dev/null %

How does the vim "write with sudo" trick work?
Many of you have probably seen the command that allows you to write on a file that needs root permission, even when you forgot to open vim with sudo:
:w !sudo tee %
The thing is that I don't get ...
Stack Overflow