Save a file in vi as the superuser

If you’ve opened a file in vi for which you don’t have write privileges, you can save the file as the superuser (if your user is in the sudoers list) by running the following vi command:

[code]:w !sudo tee %[/code]

After doing so, vi will detect that the file has changed and ask if you want to reload it.

Leave a Reply