It happens to everyone: you edit a config file in vim, try to save, and get a permission error. Quitting and typing everything again is the slow way out.
:w !sudo tee % > /dev/null
:w !cmd does not write to the file but sends the buffer to a command. sudo tee % then writes it to the current file name as root, and the redirect hides tee’s echo. Vim will say the file changed on disk. Choose L to load it again.
Caveat: it is reported not to work in Neovim, which cannot show the sudo password prompt. For files you edit as root often, sudoedit is the safer habit, because you edit a copy as yourself and it saves with the right permissions.
Further reading: Vim documentation
Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more