Sometimes I start editing configuration files in /etc
using Vim, but forget to use sudo
to start Vim. The inevitable result then is that after finishing my edits I encounter the dreaded notice that I don't have the permission to save the file.
Mostly the edits are small enough that I just exit Vim and do the whole thing again as root. I could of course save to a location I can write to and then copy as root, but that is also somewhat annoying.
But I'm sure there is an easier way to become root or use sudo
from inside Vim, without having to discard the changes. If the method would not rely on sudo
being set up for the user that would be even better.
sudoedit
instead ofvim
for all admin editing. It's one way to never run into this problem anymore :). +1 for Gilles' answer.