From 6b2906b02c05b6f7e47d7c3facca02396a0f176d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 9 Aug 2015 22:49:37 +0900 Subject: [PATCH] Updated Examples (vim) (markdown) --- Examples-(vim).md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Examples-(vim).md b/Examples-(vim).md index dc91292..676d432 100644 --- a/Examples-(vim).md +++ b/Examples-(vim).md @@ -87,15 +87,47 @@ function! s:all_files() endfunction ``` -### Jump to tags +### Jump to tags (simple) ```vim -command! -bar FZFTags if !empty(tagfiles()) | call fzf#run({ +command! -bar Tags if !empty(tagfiles()) | call fzf#run({ \ 'source': "sed '/^\\!/d;s/\t.*//' " . join(tagfiles()) . ' | uniq', \ 'sink': 'tag', \ }) | else | echo 'Preparing tags' | call system('ctags -R') | FZFTag | endif ``` +### Jump to tags + +This version better handles same tags across different files. + +```vim +function! s:tags_sink(line) + let parts = split(a:line, '\t\zs') + let excmd = matchstr(parts[2:], '^.*\ze;"\t') + execute 'silent e' parts[1][:-2] + let [magic, &magic] = [&magic, 0] + execute excmd + let &magic = magic +endfunction + +function! s:tags() + if empty(tagfiles()) + echohl WarningMsg + echom 'Preparing tags' + echohl None + call system('ctags -R --excmd=number') + endif + + call fzf#run({ + \ 'source': 'cat '.join(map(tagfiles(), 'fnamemodify(v:val, ":S")')), + \ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index', + \ 'down': '40%', + \ 'sink': function('s:tags_sink')}) +endfunction + +command! Tags call s:tags() +``` + ### Jump to tags in the current buffer ```vim