On my Red Hat machine, when I run the command echo $HOME
with my normal user account, I get /home/snrub
. When I run the command sudo vim foo.txt
and inside vim I type echo $HOME
I get /root
returned. I want it to return /home/snrub
instead so that it will parse my cool Vim plugins, even when I'm editing a file with sudo. According to the sudo manpage, the -E
or -H
options should work, but if I run sudo -E vim foo.txt
or sudo -H vim foo.txt
or sudo -EH vim foo.txt
they all still don't parse my home .vimrc file and return /root
when I type echo $HOME
.
I have also tried adding the following line to the sudoers file, and saving:
Defaults env_keep += "HOME"
Still not working. If I run sudo vim foo.txt
and then inside Vim type echo $HOME
it still says /root
. Similarly (and to verify that this is not strictly an issue with Vim), if I type sudo emacs foo.txt
and press Enter, then type Alt-X, type getenv
and press Enter, then type HOME
and press Enter, it will still return /root
. How do I make it return /home/snrub
?
!echo $HOME
?echo $HOME
and it returns /root.