zed icon indicating copy to clipboard operation
zed copied to clipboard

Vim mode: Go To Definition only adds to jumplist if the jump is 10 lines or more

Open danielcressman opened this issue 8 months ago • 2 comments

Summary

If you use editor::GoToDefinition on a symbol whose definition is less than 10 lines away, ctrl-o does not jump to the location that was jumped from, whereas vim does.

Description

Steps to reproduce:

  1. Using vim mode
  2. Define a symbol and use it somewhere within 10 lines below its definition.
  3. Use the gd or ctrl-] shortcut to jump to definition.
  4. Immediately use the ctrl-o shortcut to "jump out" on the jumplist

Expected Behavior: Jumps back to the symbol which you used gd on Actual Behavior: Jumps back to the previous entry in the jumplist

It seems like the relevant code is here: https://github.com/zed-industries/zed/blob/9c1b2afa492755a1e8cb0a77f929845941c97cdc/crates/editor/src/editor.rs#L11923-L11928

And it seems that this is necessary because as written, otherwise j and k commands (among others) would also be added to the jumplist. I have verified this by doing e.g. 11k followed by ctrl-o and that jumps back to the location I 11k'ed from. This is also different to vim/neovim behavior.

Ideally, I think there would be no arbitrary limit on the line distance. This would require the changes being discussed in https://github.com/zed-industries/zed/issues/17592 to be made first, and then the MIN_NAVIGATION_HISTORY_ROW_DELTA constant would be unnecessary. HOWEVER, that is assuming that the reason that limit exists is only for vim mode and not other features.

Would appreciate some help on this, as I frequently use gd for distances smaller than 10.

Zed Version and System Specs

Zed: v0.185.10 (Zed) OS: macOS 15.3.2 Memory: 32 GiB Architecture: x86_64

danielcressman avatar May 07 '25 20:05 danielcressman

related: https://github.com/zed-industries/zed/issues/29431

B4rc1 avatar May 08 '25 00:05 B4rc1

Clicking seems to exhibit the same behaviour too. It looks like Zed treats all navigations as jumps as long as they go further than 10 lines. I think Zed should instead implement the same jumplist behaviour as vim when in vim mode. In vim, a navigation is a jump if and only if it is one of the jump commands: https://vimdoc.sourceforge.net/htmldoc/motion.html#jump-motions

timmclean avatar May 08 '25 03:05 timmclean

Thanks for reporting. I can reproduce it. We should clearly follow Vim’s default behavior.

smitbarmase avatar Jun 17 '25 15:06 smitbarmase