1

I have my .vimrc with some global/local configurations, but when I am working in a project, I know that I often create configs (settings, mapping, command, abbreviations, etc.) specifically for this project.

I usually create a session to make them accessible in the directory where I use them with:

:mks!

That create a Session.vim file where my specific configurations are (see :help mksession).

I am asking myself if there is a better/simpler way to do so for my use case (if it's possible, a way to load directly my saved settings when I open a file with vim in the same directory).

1 Answers1

2

Off the top of my head perhaps something like this in your vimrc...

let g:localconffile = '.myvimconf'

func! LoadLocalConfig() abort let l:fname = expand('%:p:h') . '/' . g:localconffile if filereadable(l:fname) exe "source " . l:fname endif endfunc

augroup localconf autocmd! au VimEnter * call LoadLocalConfig() augroup END

This will look for a file named .myvimconf in the directory of the file being opened and if it's found it will load it (like an additional vimrc file).

VimEnter is going to trigger this only when you first open Vim. If you want this to happen for each file opened we'd use something like BufReadPost.

This is just the basic idea. You may want to refine and tighten it up. First let's see if it's even the kind of thing you're looking for.

B Layer
  • 19,834
  • 2
  • 30
  • 57