====== VIM - Saving a file as root ====== Forgot to edit a file as sudo user? Want to overwrite a file without quitting. :w !sudo tee % * **:w** - write a file. * **!sudo** - Call shell with sudo command, * **tee** - The output of write command redirected using tee. * **%** - The % is nothing but current filename. **tee** command is run as root and it takes standard input (or the buffer) and writes it to a file represented by %. This will prompt to reload the file again - hit **L** to load changes within vi itself. ---- ===== Update ~/.vimrc file ===== Append to ~./.vimrc file: command W :execute ':silent w !sudo tee % > /dev/null' | :edit! Save and close the file. Test, by opening a priviledged file without using sudo. Example: vi /etc/hosts Edit the file, and write as a privileged file with custom command, just type: w: sudo will require that you authenticate yourself, so enter your password when prompted.