Last active
July 15, 2017 15:34
-
-
Save rleger/ee476395ff53240f1628b7a557c397cd to your computer and use it in GitHub Desktop.
Vimrc configuration for FZF
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
" Vimrc configuration for FZF | |
" | |
" Key bindings | |
" | |
" Override C-P to include preview window | |
nnoremap <C-p> :call fzf#vim#gitfiles('', fzf#vim#with_preview('right:60%'))<CR> | |
" Current buffer tags | |
nnoremap <C-r> :BTags<cr> | |
" Most recent files | |
nnoremap <C-e> :FZFMru<cr> | |
" Ignore files in Gitignore | |
let $FZF_DEFAULT_COMMAND = 'ag -g ""' | |
" Match the theme on the FZF window | |
let g:fzf_colors = | |
\ { 'fg': ['fg', 'Normal'], | |
\ 'bg': ['bg', 'Normal'], | |
\ 'hl': ['fg', 'Comment'], | |
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], | |
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], | |
\ 'hl+': ['fg', 'Statement'], | |
\ 'info': ['fg', 'PreProc'], | |
\ 'prompt': ['fg', 'Conditional'], | |
\ 'pointer': ['fg', 'Exception'], | |
\ 'marker': ['fg', 'Keyword'], | |
\ 'spinner': ['fg', 'Label'], | |
\ 'header': ['fg', 'Comment'] } | |
" [[B]Commits] Customize the options used by 'git log': | |
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' | |
" [Tags] Command to generate tags file | |
let g:fzf_tags_command = 'ctags -R' | |
" [Commands] --expect expression for directly executing the command | |
let g:fzf_commands_expect = 'alt-enter,ctrl-x' | |
" | |
" FZF Most recent files | |
" | |
command! FZFMru call fzf#run({ | |
\ 'source': reverse(s:all_files()), | |
\ 'sink': 'edit', | |
\ 'options': '-m -x +s', | |
\ 'down': '40%' }) | |
function! s:all_files() | |
return extend( | |
\ filter(copy(v:oldfiles), | |
\ "v:val !~ 'fugitive:\\|NERD_tree\\|^/tmp/\\|.git/'"), | |
\ map(filter(range(1, bufnr('$')), 'buflisted(v:val)'), 'bufname(v:val)')) | |
endfunction | |
" | |
" FZF Tags in current buffer | |
" | |
function! s:align_lists(lists) | |
let maxes = {} | |
for list in a:lists | |
let i = 0 | |
while i < len(list) | |
let maxes[i] = max([get(maxes, i, 0), len(list[i])]) | |
let i += 1 | |
endwhile | |
endfor | |
for list in a:lists | |
call map(list, "printf('%-'.maxes[v:key].'s', v:val)") | |
endfor | |
return a:lists | |
endfunction | |
function! s:btags_source() | |
let lines = map(split(system(printf( | |
\ 'ctags -f - --sort=no --excmd=number --language-force=%s %s', | |
\ &filetype, expand('%:S'))), "\n"), 'split(v:val, "\t")') | |
if v:shell_error | |
throw 'failed to extract tags' | |
endif | |
return map(s:align_lists(lines), 'join(v:val, "\t")') | |
endfunction | |
function! s:btags_sink(line) | |
execute split(a:line, "\t")[2] | |
endfunction | |
function! s:btags() | |
try | |
call fzf#run({ | |
\ 'source': s:btags_source(), | |
\ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index', | |
\ 'down': '40%', | |
\ 'sink': function('s:btags_sink')}) | |
catch | |
echohl WarningMsg | |
echom v:exception | |
echohl None | |
endtry | |
endfunction | |
command! BTags call s:btags() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment