zed icon indicating copy to clipboard operation
zed copied to clipboard

Multiple commands with the same key (vim_mode), how to achieve it if possible

Open viniciuspalma opened this issue 1 year ago • 1 comments

Check for existing issues

  • [X] Completed

Describe the feature

I currently have this keymap on neovim, where I scroll down but at the same time centralize the cursor:

vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "<C-d>", "<C-d>zz")

How could I achieve the same on zed?

I tried something like:

      "ctrl-u": ["vim::ScrollUp", "editor::ScrollCursorCenter"],
      "ctrl-d": ["vim::ScrollDown", "editor::ScrollCursorCenter"]

But without success, there's a way to execute multiple commands in the same keybinding?

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

No response

viniciuspalma avatar Feb 02 '24 10:02 viniciuspalma

I dont think this is possible at the moment, but maybe my info is out of date here. cc @ConradIrwin

JosephTLyons avatar Feb 05 '24 18:02 JosephTLyons

This is currently not possible, but it is the number one feature request for vim at the moment :D. We're tracking it here: #7033.

If you'd like to pair with me on building it, please book time here: https://calendly.com/conradirwin/pairing!

ConradIrwin avatar Feb 06 '24 01:02 ConradIrwin

@ConradIrwin

This was closed as completed, but I can't work out how to actually do it. I feel I've tried everything:

"ctrl-u": ["vim::ScrollUp", "editor::ScrollCursorCenter"],
"ctrl-d": ["vim::ScrollDown", "editor::ScrollCursorCenter"],

"ctrl-u": ["workspace::SendKeystrokes", "ctrl-u z z"],
"ctrl-d": ["workspace::SendKeystrokes", "ctrl-d z z"],

"ctrl-u": ["workspace::SendKeystrokes", ": scroll up enter z z"],
"ctrl-d": ["workspace::SendKeystrokes", ": scroll down enter z z"],

"ctrl-u": ["workspace::SendKeystrokes", ": scroll up enter : scroll cursor center enter"],
"ctrl-d": ["workspace::SendKeystrokes", ": scroll down enter : scroll cursor center enter"]
  
"ctrl-u": ["DispatchActions", ["vim::SrollUp"], ["editor::ScrollCursorCenter"]],
"ctrl-d": ["DispatchActions", ["vim::SrollDown"], ["editor::ScrollCursorCenter"]]

🤷‍♂️😀

christofferbergj avatar Mar 18 '24 12:03 christofferbergj

@christofferbergj Ugh, sorry this is so hard to use!

We currently don't have a "noremap" equivalent so you can't override an existing key and call that keys definition (yet...).

One workaround for now would be to do this in two passes, one to set a new definition for ctrl-d/ctrl-u and then the other to add the zz:

      "ctrl-shift-u": "vim::ScrollUp",
      "ctrl-shift-d": "vim::ScrollDown",
      "ctrl-u": ["workspace::SendKeystrokes", "ctrl-shift-u z z"],
      "ctrl-d": ["workspace::SendKeystrokes", "ctrl-shift-d z z"

ConradIrwin avatar Mar 18 '24 15:03 ConradIrwin

@ConradIrwin

Thanks! That works! I use Vim bindings but have never really delved into understanding how the different mapping modes actually work.

But this makes sense. Hope a "noremap" equivalent will make its way into Zed eventually. 👍

christofferbergj avatar Mar 19 '24 10:03 christofferbergj

 "ctrl-shift-u": "vim::ScrollUp",
 "ctrl-shift-d": "vim::ScrollDown",
 "ctrl-u": ["workspace::SendKeystrokes", "ctrl-shift-u z z"],
 "ctrl-d": ["workspace::SendKeystrokes", "ctrl-shift-d z z"

Would love to make the same bindings, but when using "n" in search mode, mapping it to "n" -> "n zz"

But, seems like it is not possible at the moment to map a key binding to vim::MoveToNextMatch (or previous match)?

@ConradIrwin thank you so much for the previous suggestion, but why is it not possible to urse the MoveToNextMatch/MoveToPrevMatch command in the binding?

qborisb avatar Apr 17 '24 10:04 qborisb

Hmm. It should be possible...

You'll need to do the same intermediate-mode thing I talked about above:

 "ctrl-shift-n": "vim::MoveToNextMatch",
 "n": ["workspace::SendKeystrokes", "ctrl-shift-n z z"],

ConradIrwin avatar Apr 17 '24 16:04 ConradIrwin

@ConradIrwin I get the following warning if I use vim::MoveToNextMatch:

Screenshot 2024-04-18 at 14 32 10

qborisb avatar Apr 18 '24 12:04 qborisb

@qborisb I think that I maybe gave you the instructions a bit too soon. The vim::MoveToNextMatch action shipped in Zed v0.131.x which went to stable yesterday. If you upgrade does it work?

ConradIrwin avatar Apr 19 '24 01:04 ConradIrwin