-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vim mode multi-key mappings #5337
Comments
Vim mode without the ability to remap multi-key bindings is very limiting indeed. Another use-case: In normal mode, I want to remap |
@albertorestifo you may have already figured this out but you can achieve go to definition already with the following snippet:
|
The Not working example:
|
This previously enabled things like `d g g` to work, but we can fix that instead by not clearing out pending vim state on change. Either way, it is unnecessary and causes some user-confusion (zed-industries/community#176), so remove this code for now; and use comments to organize the file a bit instead.
Multi-character key-bindings should mostly "just work" if you separate keys with a space in the key. The main thing I know is broken is that you can't (in insert mode) map You should not need to specify the first key in the context for the second. This is only required in the builtin That said, it is quite fiddly to get the context correct at the moment (which I'd like to work on) but in the meantime: The main context for things is: {[{
"context": "Editor && VimControl && !VimWaiting && !menu"
"bindings": [
// put key-bindings here if you want them to work in normal & visual mode
"c d": "editor::Change
]
}, {
"context": "Editor && vim_mode == normal && (vim_operator == none || vim_operator == n) && !VimWaiting",
"bindings": [
// put key-bindings here if you want them to work only in normal mode
]
}, {
"context": "Editor && vim_mode == visual && !VimWaiting && !VimObject"
"bindings": [
// visual, visual line & visual block modes
],
}, {
"context": "Editor && vim_mode == insert",
"bindings": [
// insert mode *CAVEAT* about using printable characters above.
],
]} Also please do open issues if there are common plugins you use that define keybindings you want (or just keybindings for vim stuff that we're missing) – ideally you don't have to make too many changes to the file! |
This worked for
but if you want to type |
For reference this works for me:
|
Nice! I like |
I added a bunch of keybinds, and they're all working (amazingly fast and well compared to vs code!). My only issue is what @washanhanzi said, I now have to double type My new keybinds![ { // normal & visual mode "context": "Editor && VimControl && !VimWaiting && !menu", "bindings": {} }, { // normal mode "context": "Editor && vim_mode == normal && (vim_operator == none || vim_operator == n) && !VimWaiting", "bindings": { "g d": "editor::GoToDefinition", "space space": "command_palette::Toggle", "space b d": "pane::CloseActiveItem", "space b n": "pane::ActivateNextItem", "space b p": "pane::ActivatePrevItem", "space c l": "editor::ToggleComments", "space f s": "workspace::Save", "space f S": "workspace::SaveAll", "space j f": "project_symbols::Toggle", // not quite right, since it's full project "space p s": "TODO", // go to project "space q a": "pane::CloseAllItems", "space q o": "pane::CloseInactiveItems", "space q w": "workspace::CloseWindow", "space q q": "zed::Quit", "space s d": "pane::SplitDown", "space s l": "pane::SplitLeft", "space s r": "pane::SplitRight", "space s u": "pane::SplitUp", "space t i": "editor::ToggleInlayHints", "space t n": "workspace::NewTerminal", "space t t": "terminal_panel::ToggleFocus", "space w d": [ "workspace::ActivatePaneInDirection", "Down" ], "space w l": [ "workspace::ActivatePaneInDirection", "Left" ], "space w r": [ "workspace::ActivatePaneInDirection", "Right" ], "space w u": [ "workspace::ActivatePaneInDirection", "Up" ], "space w w": "workspace::ActivateNextPane", } }, { // visual, visual line & visual block modes "context": "Editor && vim_mode == visual && !VimWaiting && !VimObject", "bindings": {}, }, { // insert mode "context": "Editor && vim_mode == insert", "bindings": { "j k": "vim::NormalBefore" } } ] |
You can use |
We call buffer symbols an |
@calebmeyer thanks for sharing these! I'm going to add outline::Toggle and project_symbols::Toggle to the default map. Vim doesn't use I've already begun repurposing the
Also a quick note that in your file |
In the preview version of Zed, doing something like this: {
"context": "Editor && vim_mode == insert",
"bindings": {
"j k": "vim::NormalBefore",
"k j": "vim::NormalBefore"
}
}, Actually ends up typing |
|
Thanks for the report on Preview. I'll at least revert to the gpui1 behavior, but I wonder if I can figure out how to teach the input handler about pending keys so we can have our cake and eat it to. |
Add support for mapping `jk` to escape in vim mode. This changes the behaviour of the keymatches when there are pending matches. Before: Even if there was a pending match, any complete matches would be triggered and the pending state lost. After: If there is a pending match, any complete matches are delayed by 1s, or until more keys are typed. Release Notes: - Added support for mapping `jk` in vim mode ([#2378](https://github.com/zed-industries/community/issues/2378)), ([#176](https://github.com/zed-industries/community/issues/176))
This should be shipped in v0.119.16-pre. |
I've added support for
[
{
"context": "Editor && vim_mode == insert",
"bindings": {
"j k": "vim::NormalBefore"
}
}
]
This works similarly in normal mode, for example if you have: [
{
"bindings": {
"shift-escape": null,
"ctrl-enter": "menu::ShowContextMenu",
", w": "workspace::Save"
}
}
]
With that done, I think we can close this out. There is a related feature request to support mapping from one sequence of keys to another sequence of keys, but we should track that separately! |
I have |
@LORE-D-NATO If you just keep typing it should do the right thing, for example if you type There does seem to be a small bug right now where if you type |
@ConradIrwin Yes, typing a second letter other than |
I didn't want to resurrect this for another individual issue, so let me know if this is the inappropriate place to put this, but I am having trouble getting certain chained functionality similar to above, specifically Something like this:
Works great, but something like this:
does not. Am I doing something horribly wrong here? |
@jparr721 There should be (but I don't think there is) an issue for what you're talking about, which is being able to bind one keystroke to many actions (or more keystrokes). It is in the backlog of the Vim channel notes https://zed.dev/channel/vim-393, but would be good to have tracked on Github too. That said, we do already support things like Then Its a little convoluted, but that way we don't have to have separate bindings for each action and object. In order for any of this work you do have to use Zed in Vim mode |
The new keymaps worked like a charm! Thanks for the followup here. |
is it possible to override the 1000ms delay time waiting on a second keypress (especially for a specific context)? using jk is really awkward with the 1000ms delay when actually typing a "j" or "k". For example, i would normally escape from visual mode with jk, but i also need to be able to navigate lines inside visual mode, so I set the delay interval very small to enable jk escape while keeping the ability to navigate visual blocks |
@eneiford not right now, but if you’d like to pair with me on building it, feel free to book time at https://calendly.com/conradirwin/pairing. We should just be able to add a new setting for this. |
@ConradIrwin, I have a similar (but slightly different) use-case for reducing the 1000ms delay time. I normally use "bindings": {
"cmd-j": "pane::ActivatePrevItem",
"cmd-k": "pane::ActivateNextItem",
} While My current workaround is "bindings": {
"cmd-[": "pane::ActivatePrevItem",
"cmd-]": "pane::ActivateNextItem",
} |
There's no currently easy way to do this unfortunately. A few things we could consider improving on the Zed side that might help:
I think 3. should be easy, and is probably a good place to start; but 2. would be nice to have too. (1. seems further away from feasible) |
Yes, each of these solutions would work fine for me. |
Please do! Or if you'd like to just fix them PRs are also welcome – if you'd like to work together you can book time here: https://calendly.com/conradirwin/pairing |
Anyone knows how to make the above mapping work? I've tried various combination, don't seem to work at all. |
@cyfyifanchen You either need to use the workspace::SendKeystrokes action to convert one set of keys to another: https://zed.dev/docs/key-bindings#remapping-keys Or (for this specific case), you can use the target actions directly ( Line 195 in 2f6cb49
|
@ConradIrwin beautiful! |
is it possible to save the file on leaving the insert mode? Basically i want to leave the insert mode to Normal with "j k" and the file to be save automatically. |
@venkatb-zelar yes! You could do something like this:
You could also look into the Zed |
still not a viable solution.. I mean, if you really want to type is there a way to reduce vim delay timeout? normally i set this value in .vimrc to 400ms |
any updates? in neovim I use 250 timeout, and default 1000 is too much for me |
If you want to work on this with me: https://calendly.com/conradirwin/pairing |
Is your feature request related to a problem? Please describe.
I normally remap keys in vim or vim-mode in other editors so that I can use
jk
in insert mode to exit insert mode instead of escape, but I don't see any way to do this from the docs, and it did not work to try to hack it with:Describe the solution you'd like
I'd like to somehow be able to bind j then k to Escape in insert mode.
Describe alternatives you've considered
I tried the config hack above to no avail, and I also considered retraining to ctrl-c, which is the default alternate binding, but I'd rather be able to use something on the home row.
Mockup
For example, I'd love to be able to write the following:
The text was updated successfully, but these errors were encountered: