Ir para conteúdo principal

Getting root permission to change a file without leaving Vim

Lucas Caton

Lucas Caton


You know when you open a file on Vim and after some changes you realise you'd need root permission to save the changes?

I used to think that there isn't other way other than:

  • Copy the content of the file
  • Close Vim
  • Re-open it with sudo
  • And finally paste it again

It might be a bit harder if you're using Vim on a remote SSH session.

Well, it will no longer be a problem. Today I learned a neat way to achive the same thing:

:w !sudo tee %

Thanks my friend Diogo Lisboa for the tip.

Post atualizado em 10/2/2017, 10:00:00 AM