简体   繁体   中英

.vimrc configuration file does not load when editing as root

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:

  1. su
  2. vim -u /home/colin/.vimrc works but can't load plugins
  3. vim -u /root/.vimrc failed with error message
  4. cd ~ (which took me to \\root since su in step 1 made me root)
  5. cat .vimrc and ls .vim both failed and complained Too many levels of symbolic links
  6. rm -r .vimrc .vim
  7. ln -s /home/colin/.vimrc ./.vimrc
  8. ln -s /home/colin/.vim ./.vim
  9. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM