when you type :wq!
you get E212: Can't open file for writing.
If that happens to you , simply type
:w !sudo tee %
you will be asked for your sudo password
enter your password and
press enter when asked
vi/vim will detect that the file has been changed and ask whether you want
it to be reloaded.)
As a shortcut, you can define your own command.
Put the following in your /etc/vimrc
command W w !sudo tee % > /dev/null
and then in future simply type