Skip to content

Instantly share code, notes, and snippets.

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 Konfekt/429eb0f4d9a17e31235f49c4716ffddb to your computer and use it in GitHub Desktop.
Save Konfekt/429eb0f4d9a17e31235f49c4716ffddb to your computer and use it in GitHub Desktop.
A mapping that uses FZF to list all files in a Git repo and takes a count to restrict to those altered in last <count> commits
" A mapping that uses FZF to list all files in a Git repo and takes a count to restrict to
" those altered in last <count> commits.
nnoremap <silent><expr> g. v:count ? ':<c-u>' . v:count . 'GFilesAltered<cr>' : ':<c-u>GFiles<cr>'
command! -count=1 GFilesAltered call fzf#vim#files('', fzf#vim#with_preview( {
\ 'source': 'git log HEAD --max-count=<count> --diff-filter=MA --name-only --pretty=format: | ' . s:filter,
\ 'options': '--multi --prompt "Files altered in last <count> commits: "',
\ } ))
" If Fugitive is installed, there's a fallback, here's a possible fallback
" to list all files in the current work dir outside of a git repository:
" fall back to fzf#MyFiles outside git repository
if exists('*FugitiveGitDir')
nnoremap <silent><expr> <plug>(gdot) ...
nnoremap <plug>(cmf) :<c-u>call fzf#MyFiles()<cr>
nmap <expr> g. empty(FugitiveGitDir()) ? "\<plug>(cmf)" : "\<plug>(gdot)"
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment