zed icon indicating copy to clipboard operation
zed copied to clipboard

key bindings that can run multiple actions

Open maan2003 opened this issue 1 year ago • 5 comments

Describe the feature

Support binding sequences of multiple actions to a single keystroke.

using workspace::SendKeystrokes is a hack.

maan2003 avatar Sep 11 '24 14:09 maan2003

What are your thoughts on how workspace::SendKeystrokes could be made more native?

Moshyfawn avatar Sep 14 '24 01:09 Moshyfawn

like instead of value of key binding being a single action it should be multiple actions, exact format will be weird because we have already use array for action argument

maan2003 avatar Sep 14 '24 07:09 maan2003

One complexity I want to note is that async nature of many actions. For example triggering ["Format Buffer", "Save Buffer", "Close Buffer"] requires the creation of a silent "async wait" step between each of those. While other multi-action binds wouldn't necessarily need to wait ["Save Buffer", "Switch to Terminal"].

notpeter avatar Dec 03 '24 21:12 notpeter

I ran into this today. When you use Editor::ConvertToSnakeCase (or the other case conversions), it leaves the updated text selected.

I'm a vim mode user (and came via spacemacs), so I use space as my leader and do leader c s (for Convert to Snake case). But binding it directly means that I had to do escape leader c s escape j to move to the next line (which I often also want to change to snake case), or I would end up with a selection and accidentally kill the text I just updated.

Like the OP says, I can work around it with SendKeystrokes, but if there is ever another command that has a similar name, my keybinding may stop working:

            "space c s": [
                "workspace::SendKeystrokes",
                "cmd-shift-p convert snake enter escape"
            ],

calebmeyer avatar Apr 25 '25 18:04 calebmeyer

SendKeystrokes would solve most of my needs if it were able to return the cursor to the original position. For example, I would like to bind a key that does:

  1. Move cursor to end of line
  2. insert ;
  3. move back to where I had been

SendKeystrokes works well for 1 and 2, but it can’t (or I haven’t found a way to) do 3.

That said, I agree that SendKeystrokes feels like a hack: I would prefer to build these sort of macros with the actual command/action names, not the keys they happen to be bound to.

claytonrcarter avatar Jun 05 '25 00:06 claytonrcarter

@claytonrcarter, in the meantime:

"space a ;": [
  "workspace::SendKeystrokes",
  "m ` shift-a ; escape ` `"
],
  • m` to mark before jump
  • shift-a to jump to end of line in insert mode
  • ; add the semicolon
  • escape back to normal mode
  • `` to jump back to marked location

fresh2dev avatar Oct 30 '25 04:10 fresh2dev