I am root on the machine, and have my .vimrc at /root/.vimrc. Vim ignores this, even though

# echo $HOME

If I do

# vim -u /root/.vimrc some-file-to-edit

vim still ignores it. Setting export MYVIMRC=root/.vimrc has no effect.

Vim sources my file without problems if I start vim and type :source /root/.vimrc.

Note VIMINIT is unset.

What could be preventing vim from sourcing my .vimrc when starting up?

I'm happy to supply any other information that may be helpful, just let me know what.

EDIT 1: excerpt from running vim -V filename:

finished sourcing $VIM/vimrc
fchdir() to previous dir 
sourcing "$HOME/.vimrc"
Searching for "filetype.vim" in "/root/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,/root/.vim/after"
Searching for "/root/.vim/filetype.vim"

The full output is long, so this is just an excerpt to show the line that verifies sourcing of /root/.vimrc.

EDIT 2: output from running :scriptnames after vim normally*

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: /usr/share/vim/vim74/syntax/syntax.vim
  4: /usr/share/vim/vim74/syntax/synload.vim
  5: /usr/share/vim/vim74/syntax/syncolor.vim
  6: /usr/share/vim/vim74/filetype.vim
  7: ~/.vimrc
  8: /usr/share/vim/vim74/indent.vim
  9: /usr/share/vim/vim74/ftplugin.vim
 10: /usr/share/vim/vim74/syntax/nosyntax.vim
 11: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
 12: /usr/share/vim/vim74/plugin/gzip.vim
 13: /usr/share/vim/vim74/plugin/matchparen.vim
 14: /usr/share/vim/vim74/plugin/netrwPlugin.vim
 15: /usr/share/vim/vim74/plugin/rrhelper.vim
 16: /usr/share/vim/vim74/plugin/spellfile.vim
 17: /usr/share/vim/vim74/plugin/tarPlugin.vim
 18: /usr/share/vim/vim74/plugin/tohtml.vim
 19: /usr/share/vim/vim74/plugin/vimballPlugin.vim
 20: /usr/share/vim/vim74/plugin/zipPlugin.vim
 21: /usr/share/vim/vim74/indent/python.vim
 22: /usr/share/vim/vim74/ftplugin/python.vim
 23: /usr/share/vim/vim74/syntax/python.vim

Again, seems to be sourcing /root/.vimrc (item 7). Soo... line 8 makes me suspicious: my problem is that the indent settings in my vimrc aren't reflected. Maybe they are being superceeded...

EDIT 3: Placing my file in ~/.vim/after/...

Moving my file to the following locations had no effect on the output of scriptnames:

  • ~/.vim/after/indent.vim
  • ~/.vim/after/indent.vim/myscript.vim
  • ~/.vim/after/indent/myscript.vim
  • ~/.vim/after/syntax/myscript.vim
  • ~/.vim/after/indent/myscript.vim
  • ~/.vim/after/myscript.vim

And, while moving my to

  • ~/.vim/after/plugin/.vimrc

did change the output of :scriptnames, causing my file to be sourced after item 20 (see above), it seems my indent settings are still getting overridden (probably by item 21).

Use of the after directory doesn't work how I imagined (see my list of attempts). Only after/plugins/ seems to be considered.

Is there a way to ensure that the file is sourced after everything?

  • 5
    What's the output of :scriptnames when you run vim normally?
    – muru
    Apr 24, 2016 at 20:43
  • "I am the root on the machine" -> youtube.com/watch?v=7HG2w0_WyOU
    – VanLaser
    Apr 25, 2016 at 10:16
  • @muru thanks for the comment -- see EDIT2 Apr 27, 2016 at 21:14
  • 2
    You probably need to use a ~/.vim/after/indent.vim or ~/.vim/after/indent/foo.vim if you want to override those.
    – muru
    Apr 27, 2016 at 21:16
  • Thanks again @muru. Some progress, but vim doesn't seem to take ~/.vim/after/indent/foo.vim into consideration. I experimented with different locations under ~/.vim/after/..., but for the most part, files therein are ignored see EDIT 3 Apr 27, 2016 at 22:04

2 Answers 2


You can see what Vim does on startup with vim -V. Does it touch the file? Is there any errors?

Safe for errors, my only guess is that filename contains non-ASCII character that looks like "c"; you might not notice it if you always autocomplete the name of the file instead of typing it out in its entirety.


Here is what worked for me:

First opening vim normally and doing :scriptnames showed that, in fact, my ~/.vimrc was sourced. Other scripts were just overridding my indent settings.

Moving just the lines pertaining to indentation from my ~/.vimrc into a new file at ~/.vim/after/ftplugin/python.vim solved the problem. The filename is crucial, and it is only executed when reading python files.

Alternatively put the file in ~/.vim/after/ftplugin/python/some-name.vim.

  • Both your and Alexander Batischev answers helped. I noticed that vim was searching /root/.vim/ which woke me up to the fact I was launching via sudo. To get my settings loaded, sudo -E vim ... to use my environment.
    – bvj
    Apr 9, 2019 at 20:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.