0

When I use sudo vim on a file it fails with:

$ sudo vim test
Error detected while processing /home/dcampbe1/.vimrc:
line   12:
E117: Unknown function: vundle#begin
line   13:
E492: Not an editor command: Plugin 'VundleVim/vundle.vim'
line   14:
E492: Not an editor command: Plugin 'bundle/vim-colors-solarized'
line   15:
E492: Not an editor command: Plugin 'tpope/vim-fugitive'
line   16:
E492: Not an editor command: Plugin 'w0ng/vim-hybrid'
line   17:
E492: Not an editor command: Plugin 'airblade/vim-gitgutter'
line   18:
E492: Not an editor command: Plugin 'vim-airline/vim-airline'
line   19:
E492: Not an editor command: Plugin 'vim-airline/vim-airline-themes'
line   20:
E492: Not an editor command: Plugin 'jreybert/vimagit'
line   21:
E492: Not an editor command: Plugin 'valloric/youcompleteme'
line   22:
E492: Not an editor command: Plugin 'scrooloose/nerdtree'
line   23:
E117: Unknown function: vundle#end
line   26:
E185: Cannot find color scheme 'hybrid'
line  149:
E471: Argument required
Press ENTER or type command to continue

However when I run vim on the same file it opens up correctly with my correct vundle config. I need to use sudo vim quite often due to many files being owned by root instead of by my user. I'm fine with the normal root config being used when run sudo vim, however I'm surprised that sudo vim tries to go into my vundle config and somehow fails.

Does anyone have an idea of what's going on? Either a fix where running sudo vim just goes to the normal root vim or goes to my own configured vim in .vimrc works.

  • 1. Did you copy your own .vimrc into /root? 2. Recommended practice is to use sudoedit (a.k.a. sudo -e) instead of running vim as root. – jw013 May 30 '18 at 20:46
  • No I haven't. I don't want everyone who runs root to use my vimrc since multiple people have different setups. Thing is I recently upgraded to 18.04 and now I cannot but on my 16.04 version on ubuntu it's fine – Dorilds May 31 '18 at 13:31
  • Now that you mention Ubuntu I wonder if your issue is related to this question. However, have you tried sudoedit as suggested? Not only is sudoedti recommended over sudo vim, it should avoid this problem you are having because sudoedit runs $EDITOR as you instead of as root so your normal user configuration should work. – jw013 May 31 '18 at 15:31
  • Yup sudoedit works like a charm. – Dorilds May 31 '18 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.