0

I am trying to execute some custom settings based on the directory on startup. For this I am trying:

autocmd VimEnter /path/to/dir/* :source /custom.vim

When I now execute:

cd /path/to/dir
vim

I would expect the config to have been loaded. This does not seem to work. However, this works:

autocmd VimEnter * :source /custom.vim

Is there a way to load a config once on startup based on the directory that vim was started in?

Note: I am aware of Applying settings to a directory tree only but would prefer to make it work this way.

eclipse
  • 123
  • 3

1 Answers1

2

Try this one:

augroup DIR_CONFIG | au!
    au VimEnter * if getcwd() == expand('~/temp') | source my.vim | endif
augroup END

PS, as @eclipse has mentioned in the comments one could just add to vimrc:

if getcwd() == expand('~/temp') | source my.vim | endif
Maxim Kim
  • 13,376
  • 2
  • 18
  • 46