0

Here's my existing bind I'm looking to improve:

nnoremap <Leader>L :so $MYVIMRC<CR>:runtime! after/plugin/*.vim<CR>:runtime! after/ftplugin/*.vim<CR>

This doesn't work to source <cwd>/.vimrc.

How do I add that (probably just :so .vimrc), and more importantly, what is the order in which that actually gets sourced on startup, so I can replicate that?

1 Answer 1

1

I think you're suggesting that <cwd>/.vimrc gets loaded automatically. It usually doesn't (exceptions noted below). Only one .vimrc file gets loaded and that's normally going to be $HOME/.vimrc. You'll know which one gets picked up because that's what you see in $MYVIMRC. In other words $MYVIMRC is normally set once the .vimrc location has been determined as opposed to $MYVIMRC dictating what Vim will load.

There are a couple ways to subvert this:

  • As noted in Mass's comment there actually is an option to read .vimrc from the current directory! Read :h 'exrc', though, as it strongly discourages use of this option for security reasons (though if you set 'secure' as well it's apparently less dangerous).
  • If you are so inclined you can pre-set $MYVIMRC in which case the standard vimrc location rules don't apply. See :h .vimrc for a complete description of all of this.

In any case, if you want to load .vimrc from your working directory in your mapping then you're right that you simply add :so .vimrc.

FYI there are two ways to see what has been loaded and in what order:

  • Start Vim with this flag -V2<outfile>. In outfile you will see some verbose output that includes all sourced files.
  • If Vim is already running do :scriptnames to display sourced files.
4
  • It is plausible (though highly ill-advised) that OP has "set exrc," in which case ./.vimrc would be sourced.
    – Mass
    Commented Sep 16, 2017 at 18:04
  • Yes you're right! I have set exrc and set secure in my vimrc. I had forgotten that i use this.
    – Steven Lu
    Commented Sep 17, 2017 at 20:47
  • I am going to try to eliminate this. mainly i just need project specific vimrcs to configure ALE.
    – Steven Lu
    Commented Sep 17, 2017 at 20:49
  • Wow. I thought @Mass was going out on a limb with his theory given how vehemently :help 'exrc' warns against using it. Never say never, eh? For accuracy's sake I'd like to mention this in my answer, crediting you, but don't want to be seen as trying to steal rep....if you write an answer I'll link to it from mine.
    – B Layer
    Commented Sep 17, 2017 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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