zed icon indicating copy to clipboard operation
zed copied to clipboard

Vim Mode: use `gd` to jump to caller

Open hamza72x opened this issue 1 year ago • 6 comments

Check for existing issues

  • [X] Completed

Describe the feature

Hey!

Thanks for the project. I have almost switched to Zed for some of my workflow (Go + Rust). I have a small feature request is that:

If I do gd on function name, it should opencaller of the function, if there is only one caller of the function. If there are more than one caller of that function, then it can open Find All Occurrences, even though we already have gA for that.

This feels very fast way to navigate. I am not sure if there is already a key-binding for such action.

Attaching a screencast (VSCode + Vim Plugin):

https://github.com/zed-industries/zed/assets/48919542/7d9e7bb4-83e8-41d5-a9bb-58275ee36ec2

Similarly, it can/may also work with struct / class / variable

Thanks again.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

hamza72x avatar Feb 26 '24 08:02 hamza72x

We already have a PR for that (except the Vim binding): https://github.com/zed-industries/zed/pull/6924 But it seems a bit stale.

mrnugget avatar Feb 26 '24 09:02 mrnugget

Didn't see that, closing then. Thanks.

hamza72x avatar Feb 26 '24 09:02 hamza72x

That PR is not related to VIM mode, so re-opening this one. But I think that should also solve this one. Keeping this open, so that we can validate with Vim mode and close later, if that makes sense.

hamza72x avatar Feb 26 '24 10:02 hamza72x

Yeah, I think the scope for this one would be to add a vim keybinding if that's not done in the original PR.

mrnugget avatar Feb 26 '24 12:02 mrnugget

Never heard of that use of gd before, I've always used ^o to jump back to my previous location(s). (in Neovim)

jansol avatar Feb 26 '24 12:02 jansol

@jansol sorry, the title was slightly misleading. It's about opening the caller of the function/class/variable.

hamza72x avatar Feb 26 '24 13:02 hamza72x

@hamza72x gd isn't for going to caller if I'm not mistaken, stands for Go To Definition, then gD stands for Go To Declaration.

This is at least how neovim lsp keymappings work:

 vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)

Reference: https://github.com/neovim/nvim-lspconfig

vricop avatar Mar 07 '24 08:03 vricop

@vricop I was referring to VSCode+Vim Extension's default behaviour.

hamza72x avatar Mar 08 '24 17:03 hamza72x

@vricop I was referring to VSCode+Vim Extension's default behaviour.

@hamza72x That’s weird the VSCode-neovim plugin does the same neovim does. Maybe it’s a vanilla vim thing. It doesn’t make sense to me imho thought.

vricop avatar Mar 08 '24 18:03 vricop

Tested with latest Zed Preview, working with custom keybindings. By default it's mapped to gA -> Reference

[
    {
        "context": "Editor && vim_mode == normal && !VimWaiting && !menu",
        "bindings": {
            "g d": "editor::FindAllReferences"
        }
    }
]

And ofc, Thanks everyone who worked on this. 💐💐

hamza72x avatar Mar 11 '24 09:03 hamza72x