zed
zed copied to clipboard
key bindings that can run multiple actions
Describe the feature
Support binding sequences of multiple actions to a single keystroke.
using workspace::SendKeystrokes is a hack.
What are your thoughts on how workspace::SendKeystrokes could be made more native?
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
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"].
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"
],
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:
- Move cursor to end of line
- insert
; - 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, in the meantime:
"space a ;": [
"workspace::SendKeystrokes",
"m ` shift-a ; escape ` `"
],
m`to mark before jumpshift-ato jump to end of line in insert mode;add the semicolonescapeback to normal mode``to jump back to marked location