I make a wrapper for vim. I call this script ~/bin/vi (I'm used to typing vi instead of vim, anyway):
Code:
#!/bin/bash
precommand=
for i in "$@" ; do
if [ -f "$i" -a ! -w "$i" ] ; then precommand="sudo " ; break ; fi
done
exec ${precommand}vim "$@"
This script runs vim with sudo if any file mentioned on the command line isn't writable.
For the way I work, this isn't risky. Everything (with a few minor exceptions) outside of $HOME isn't user-writable. So the only safety against accidentally doing something stupid is knowing what I'm editing--no matter whether I typed sudo or not.
Bookmarks