zed
zed copied to clipboard
Multiple commands with the same key (vim_mode), how to achieve it if possible
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
I dont think this is possible at the moment, but maybe my info is out of date here. cc @ConradIrwin
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
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 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
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. 👍
"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?
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 I get the following warning if I use vim::MoveToNextMatch:
@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?