VimPlugin: vim-localvimrc

From wikinotes

project-specific vimrc files.

  • all directories in the current CWD are checked for a .lvimrc file to load
  • they are loaded in order of rootmost-CWD
  • you are asked for confirmation before loading, allowlists can be created

Documentation

github https://github.com/embear/vim-localvimrc

Configuration

" allowlist directories so they do not re-confirm each time
let g:localvimrc_whitelist=[
    '/home/user/project1/',
    '/opt/project2/',
    '/usr/local/projects/vim-[^/]*/'
]

" disable sandboxing (if you need to use functions, autocmd, etc..)
let g:localvimrc_sandbox = 0

Sample Script

The .lvimrc appers to be loaded every time a buffer is opened.
You'll need to follow a pattern like syntax-files to prevent it from being loaded multiple times.

let b:handle = 'my-unique-handle'
let g:lvimrc_read = get(g:, 'lvimrc_read', [])

" exit if already sourced
if (index(g:lvimrc_read, b:handle) >= 0)
    finish
endif

" ... your functions, commands, etc.

" mark file as sourced
call add(g:lvimrc_read, b:handle)