If you use fugitive.vim , then I may have an option for you.
Put the following in the ~/.vimrc file:
set viminfo+=! if !exists('g:PROJECTS') let g:PROJECTS = {} endif augroup project_discovery autocmd! autocmd User Fugitive let g:PROJECTS[fnamemodify(fugitive#repo().dir(), ':h')] = 1 augroup END command! -complete=customlist,s:project_complete -nargs=1 Project cd <args> function! s:project_complete(lead, cmdline, _) abort let results = keys(get(g:, 'PROJECTS', {})) " use projectionist if available if exists('*projectionist#completion_filter') return projectionist#completion_filter(results, a:lead, '/') endif " fallback to cheap fuzzy matching let regex = substitute(a:lead, '.', '[&].*', 'g') return filter(results, 'v:val =~ regex') endfunction
Overview
The idea is that at any time fugitive activates a buffer that the script stores the project directory path in the g:PROJECTS dictionary. Adding ! in 'viminfo' will store capitalized global variables in the viminfo file, thereby making detected projects saved. Once the fugitive discovers the project, the command :Project can be used to :cd into this directory with completion.
Notes and Warnings
- I have not tested this code. Use as is.
- Fugitive.vim required
- Optional Projectionist.vim completion, if available
- Remember to add paths to
g:PROJECTS other ways - You must visit the repository so that it can be detected
- Unable to clear missing project directories
- Vim has no concept of "project", so there is only so much that can be done
source share