wrote:
> Hi,
>
> [Please CC me...]
>
> I'm wondering if anyone has any tips for how to efficiently jump
> between tags in Vim? I'll outline my scenario.
>
> At the moment, pressing CTRL-] on a function definition works great,
> and vim will jump to that tag, switching to a new file in the same
> window if need be. What I'm after is trying to find out if Vim can
> instead detect if a window displaying a buffer with that tag in it is
> open and to switch focus to that instead?
>
> For example: If I have a split window which looks like this:
>
> +----------------------+
> | | |
> | 1 | 2 |
> | fileA | fileB |
> +----------------------+
>
> And I am in window 2. If selecting a tag with CTRL-] meant jumping to
> a definition resulted in fileA in window1, I'd want Vim to switch the
> focus to window 1 instead and jump to the correct tag, rather than Vim
> currently opening fileA in window2.
>
> Likewise, going back the other way instead, pressing CTRL-T should put
> me back in window2, in this example.
>
> If this is possible, it might be nice to consider whether the CTRL-]
> can also detect files open in other *tabs* and switch to any windows
> in that.
>
> TIA!
Of course this can be achieved:
nnoremap! <Ctrl-]> :call <SID>SmartTagSearch()<CR>
function! s:SmartTagSearch()
if {file opened in current tab}
" switch to that window
" locate the tag
else
normal! <C-]>
endif
endfunction
Brief steps implementing s:SmartTagSearch() :
1. expand() to get the word under the cursor(tag name)
2. taglist() to get the target file name of the tag
3. tabpagebuflist() + bufname() to see if that file is opened in the
current tab, if so the window number is determined
4. :exe + :normal ^W^W to switch to that window
5. use the {cmd} got in 1. to locate the tag
Taking all tab pages into account is no problem either, just introduce
tabpagenr() and :gt
<Ctrl-t> is just the other way round.
This should work, theoretically. But I haven't tried it.
Plus: what does the "CC" mean?
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment