To save a file in Vim without root permission using sudo
, you can use the :w !sudo tee %
command. This will write the contents of the current file to a new file with the same name, but with root permission.
For example, if you are currently editing the file /etc/hosts
and want to save your changes, you can use:
:w !sudo tee %Source:www.lautturi.com
This will write the contents of the /etc/hosts
file to a new file with the same name, but with root permission. You will be prompted for your password, and the changes will be saved to the file.
Alternatively, you can also use the :w !sudo tee >
command, followed by the path to the file you want to save. For example:
:w !sudo tee /etc/hosts > /dev/null
This will write the contents of the current file to /etc/hosts
with root permission.
You can find more information about saving files with root permission in Vim in the Vim documentation by typing :help :w_sudo
within Vim.