Last active
August 29, 2015 14:13
-
-
Save dekz/76bbc1dd9583faca7aa0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" find file in git repo | |
function! ChooseFile() | |
let dir = expand("%:h") | |
if empty(dir) | let dir = getcwd() | endif | |
let root = system("cd " . dir . " && git rev-parse --show-toplevel") | |
if v:shell_error != 0 | echo "Not in a git repo" | return | endif | |
let root = root[0:-2] | |
let selection = system("cd " . root . " && git ls-files -co --exclude-standard | choose") | |
if empty(selection) | echo "Canceled" | return | end | |
echo "Finding file..." | |
exec ":e " . root . "/" . selection | |
endfunction | |
" shortcut | |
nnoremap <leader>f :call ChooseFile()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment