mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-18 16:45:38 -05:00
Updated Examples (vim) (markdown)
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user