Created
April 9, 2024 12:25
-
-
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
This file contains 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
" 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