Skip to content
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

Keys after commands in key bindings #9029

Open
edemaine opened this issue May 15, 2024 · 2 comments
Open

Keys after commands in key bindings #9029

edemaine opened this issue May 15, 2024 · 2 comments

Comments

@edemaine
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I'm trying to define nice key bindings for LaTeX Workshop's various commands. The one I'm working on now is latex-workshop.wrap-env, which wraps the selection in \begin{}...\end{} and puts multiple cursors on the two }s so you can type the environment name. This is naturally an operation for Visual Mode, but afterwards I want to be in Insert Mode. The only way I know to do that is to type <Esc>i.

Describe the solution you'd like
I'd like to bind keys to execute a command and then simulate some keystrokes.

Describe alternatives you've considered
It seems that after keys are executed before commands instead of after, which is when I want these keys to execute. This is what I tried:

    "vim.visualModeKeyBindingsNonRecursive": [
      {
        "before": [ "\\", "b" ],
        "commands": [ "latex-workshop.wrap-env" ],
        "after": [ "<Esc>", "i"],
      }
    ],

Probably both times to execute keys are useful, so in addition to after we could have another property (afterCommands?).

Additional context
I'm worried that the commands are executed asynchronously and it's not easy to know when they're done. But hopefully that isn't the case? I could try to implement this if you agree it's useful and could give some pointers on where this happens.

@flczcy
Copy link

flczcy commented May 25, 2024

"commands": [command...]

Here, I guess only for command in VS Code and extension, so you need to find command of vim extension in VS Code.

Try this:

{ "before": [ "\\", "b" ], "commands": [ "latex-workshop.wrap-env", "extension.vim_insert"  ]}

// or

{ "before": [ "\\", "b" ], "commands": [ "latex-workshop.wrap-env", "extension.vim_escape", "extension.vim_insert"  ]}

You can find vim extension command in Keyboard Shortcuts Panel.

image

@edemaine
Copy link
Contributor Author

Thank you! I didn't realize all these commands existed because they aren't listed in Ctrl-Shift-P.
{ "before": [ "\\", "b" ], "commands": [ "latex-workshop.wrap-env", "extension.vim_escape", "extension.vim_insert" ]} works well.

This seems like a pretty good solution, so perhaps we should just mention the existence of these commands in documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants