From 3361a065c48e384b3cb39db73c225e3502840ded Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 30 Jul 2015 15:59:29 +0900 Subject: [PATCH] Updated Examples (vim) (markdown) --- Examples-(vim).md | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Examples-(vim).md b/Examples-(vim).md index 5ad5988..a210723 100644 --- a/Examples-(vim).md +++ b/Examples-(vim).md @@ -98,7 +98,54 @@ command! -bar FZFTags if !empty(tagfiles()) | call fzf#run({ ### Jump to tags in the current buffer -https://github.com/junegunn/fzf/issues/243#issuecomment-123719357 +```vim +" ---------------------------------------------------------------------------- +" BTags +" ---------------------------------------------------------------------------- +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=pattern --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(), + \'down': '40%', + \'options': '+m -d "\t" --with-nth 1,4.. --tiebreak=begin', + \'sink': function('s:btags_sink')}) + catch + echohl WarningMsg + echom v:exception + echohl None + endtry +endfunction + +command! BTags call s:btags() +``` ### Search lines in all open vim buffers