I looked at .vimrc configuration file does not load when editing with 'sudo' , but the accepted answer doesn't work for me. I have put a test line echo "it works!"
into my ~/.vimrc
. When I edit a file as user, it works. When I edit a file as root it doesn't. I have linked .vimrc
and .vim
to the same in /root
; so that, they show up there. I have tried sudoedit
, sudo vim
and su
then vim
, but nothing works.
I have done some more testing and found that vim -u /home/colin/.vimrc
works while I'm root except that it doesn't find the color scheme. But, vim -u /root/.vimrc
fails with:
E282: Cannot read from "/root/.vimrc"
So, then I tried to cat .vimrc
and ls .vim
while root in /root
, and got
Too many levels of symbolic links
Once I got the Too many levels of symbolic links
, I simply recreated the links. However, when the links were first created, I was in fact able to cat
and ls
them as root user from \\root
. So, I don't really know what the problem was or how it was really solved.
Here is what I did though:
su
vim -u /home/colin/.vimrc
works but can't load plugins vim -u /root/.vimrc
failed with error message cd ~
(which took me to \\root
since su
in step 1 made me root) cat .vimrc
and ls .vim
both failed and complained Too many levels of symbolic links
rm -r .vimrc .vim
ln -s /home/colin/.vimrc ./.vimrc
ln -s /home/colin/.vim ./.vim
exit
All I did is just create two simple soft links. Since you will not change the name of the .vimrc
or .vim
files, all you need is just add two pointers to your local user's configuration file. Try this in your terminal:
sudo ln -s ${HOME}/.vimrc /root/.vimrc;
sudo ln -s ${HOME}/.vim /root/.vim;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.