Skip to content

Instantly share code, notes, and snippets.

@yuanotes
Last active December 19, 2015 01:19
Show Gist options
  • Save yuanotes/5875424 to your computer and use it in GitHub Desktop.
Save yuanotes/5875424 to your computer and use it in GitHub Desktop.
A simple script that wrap CommandT for vim to quickly index current project.
function! MyGetProjectPath(path)
python << EOF
import os
import vim
def get_project_dir(path):
find_project_file = False
while not find_project_file:
files = os.listdir(path)
if ".vimproj" in files:
find_project_file = True
elif ".git" in files and os.listdir(os.path.join(path, ".git")):
find_project_file = True
else:
path = os.path.dirname(path)
if path == os.getenv("HOME") or path == "/":
return None
return path
proj_dir = get_project_dir(vim.eval("a:path"))
if proj_dir:
vim.command("let g:vim_proj_dir=\"%s\"" % proj_dir)
else:
vim.command("let g:vim_proj_dir=0")
EOF
endfunction
function! MyCallCommandT()
let l:cur_dir = expand("%:p:h")
call MyGetProjectPath(l:cur_dir)
echo g:vim_proj_dir
if exists("g:vim_proj_dir") && !empty(g:vim_proj_dir)
execute "CommandT ".g:vim_proj_dir
else
execute "CommandT ./"
endif
endfunction
nnoremap <silent> <Leader>t :call MyCallCommandT()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment