vim & ctags: how to jump to the definition in new window

1,175 views
Skip to first unread message

张正宇

unread,
Sep 21, 2016, 7:19:03 AM9/21/16
to v...@vim.org
Hello list!

I am reading some source code with vim & ctags these days. You know
sometimes people just forget those input/output parameters while diving
into functions ...

So, is there some good way to open a new window to view the definition
after I press 'G+] ' while keep the previous file shown?

All I want is a 'Cover Flow' style. For example, after I press 'G+]' in
file A, a new window split up from A's to show file B. When I press
'G+]' again in file B, file A is hidden and replaced by B, while a new
file C will show up in B's former window. And file D,E,F,G...


Thanks!
zzy

signature.asc

Marc Weber

unread,
Sep 21, 2016, 8:47:49 AM9/21/16
to vim_use
<c-w> s then use :tjump or such -> you can write a mapping easily such
as :nnoremap <f3> <c-w>s:tjump<space>

Marc Weber

Bryan Richter

unread,
Sep 21, 2016, 9:30:52 AM9/21/16
to v...@vim.org
On Wed, Sep 21, 2016 at 10:49:48AM +0800, 张正宇 wrote:
> Hello list!
>
> I am reading some source code with vim & ctags these days. You know
> sometimes people just forget those input/output parameters while
> diving into functions ...
>
> So, is there some good way to open a new window to view the
> definition after I press 'G+] ' while keep the previous file shown?

The split version of 'g ]' is 'CTRL-W g ]'. The commands versions of
those keybindings are :tselect and :stselect.

> All I want is a 'Cover Flow' style. For example, after I press 'G+]'
> in file A, a new window split up from A's to show file B. When I
> press 'G+]' again in file B, file A is hidden and replaced by B,
> while a new file C will show up in B's former window.

Here's a sample workflow. It could be made easier with some custom
commands...

" Begin with a fresh tab page while in file A

:tab split

" Split and view a definition.

CTRL-W g ]

" Now A and B are visible. From file B, jump further forward.

:only
CTRL-W g ]

" Further... (C and D become visible)

:only
CTRL-W g ]

" Now backwards! (B and C are visible again)

:only
:below split
:pop

" ...
"
" Leave the 'Cover Flow' view

:tabclose
signature.asc

张正宇

unread,
Sep 22, 2016, 2:28:13 AM9/22/16
to marco-...@gmx.de, b...@chreekat.net, vim...@googlegroups.com
Hi Bryan & Marc
Thanks for your reply. `Ctrl-W g ]` seems to be a good start. I will do
some homework on vim and try to figure out my own 'cover flow' solution
(maybe learn to write a shabby plugin script? :P)


Thanks!
zzy

signature.asc

张正宇

unread,
Sep 28, 2016, 4:27:34 AM9/28/16
to vim...@googlegroups.com
As I said, I struggled to write a plugin. Request for comment!

https://github.com/freemandealer/CodeCoverFlow

Thanks
zzy

signature.asc

Nicola

unread,
Sep 28, 2016, 6:33:44 AM9/28/16
to vim...@googlegroups.com
You've brilliantly solved your own problem, so this may be a bit late, but…
using the commands and mappings described in :h preview-window might get
you close to your workflow. Off the top of my head, assuming you start from
a single window:

:ptag or <c-w>} or <c-w>g} (to open a tag in the preview window)
<c-w><c-x> (to exchange windows)
:se nopreviewwindow (to turn the preview window into a normal window)
<c-w><c-o> (to close the other window)

and repeat.

Nicola


张正宇

unread,
Sep 28, 2016, 9:20:18 PM9/28/16
to nvitac...@gmail.com, vim...@googlegroups.com
Hi Nicola
Thanks for your reply. It is never to late to know new things :)

My plugin is just a simple wrapper of something similar to preview
window - most of my want is a new window, isn't it? The rest is to
create a bidirectional flow between these windows.


All the best!
zzy

signature.asc
Reply all
Reply to author
Forward
0 new messages