# for regular use, keep this alias
alias v='nvim'
# replace sudo with this functiom
sudo() {
# check if next argument is 'v'
if [[ "$1" == "v" ]] ; then
# remove 'v' from the argument list
shift
# call sudo -E nvim on remaining arguments
command sudo -E nvim "$@"
# exit the function with the return value of the
# sudo nvim -E command
return $?
fi
# now check if first argument is a different alias; if so,
# $expansion will be the alias definition if one exists,
# or else it will be the empty string
local expansion="${BASH_ALIASES[$1]}"
if [[ -n "$expansion" ]] ; then
# remove the alias from the argument list
shift
#if the expansion has variables in it,
#we need to expand those variables, not
#just the $expansion variable itself,
#so we use eval
eval "command sudo $expansion \"\$@\""
# exit the function with its return value
return "$$?"
fi
# if we got here, what follows sudo is a
# normal command, so we execute sudo with the
# rest of the arguments as is
command sudo "$@"
}