7

I am sourcing a local vimrc using the plugin from the first response here: Vim: apply settings on files in directory

Now what i'd like to do is to add the curren path of this local vimrc file to vims path.

I do know that %:p:h gives me the path of the current file. But it is of the file being opened not of the config file being soucred.

let s:local_path = expand('%:p:h')
exec "set path+=".s:local_path

Does anyone know how to get the path of the file being sourced?

Community
  • 1
  • 1
RedX
  • 14,749
  • 1
  • 53
  • 76

1 Answers1

8

Instead of %, just use the special <sfile>; in a script (but not inside a function within a script!), it is expanded to the file name of the sourced script:

:let s:local_path = expand('<sfile>:p:h')
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324