My Quick Notes

Ain't Nobody Got Time to Read

April 25, 2025

Vim - Save file as root without reopening file

File requires root permission to be written, but sometimes we forget to add sudo before vim command. The result is after editing the file with a lot of changes, :w cannot save them.

This can be avoided by adding a simple command to $HOME/.vimrc:

cmap w!! w !sudo tee > /dev/null %

Then when we type :w!!, it will be mapped to :w !sudo tee > /dev/null %, which will let we save the file with sudo without re-opening the file.

PreviousHow to prevent focus stealing in KDE Plasma
NextHow to properly exit Bevy app on Android

Comments