Skip to content

Instantly share code, notes, and snippets.

@dekz
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekz/76bbc1dd9583faca7aa0 to your computer and use it in GitHub Desktop.
Save dekz/76bbc1dd9583faca7aa0 to your computer and use it in GitHub Desktop.
" 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