johtela / vscode-modaledit

Configurable Modal Editing in VS Code
https://johtela.github.io/vscode-modaledit/docs/README.html
Other
89 stars 8 forks source link

Binding Shift+Enter #3

Closed suhr closed 4 years ago

suhr commented 4 years ago

It would be nice to be able to bind Shit+Enter.

johtela commented 4 years ago

All Vim emulators are based on the type hook of VS Code. That basically sends the extension a single ASCII character that was pressed. Since Shift+Enter produces the same ASCII code as Enter alone \n, there is no way to bind it to a different command.

It is possible, however, to bind Shift+Enter using the standard VS Code key bindings (Ctrl+K, Ctrl+S). But then you can only bind to a single command, not to a sequence as in ModalEdit.

I'll keep this issue open, since I've been thinking of improvement to add a new command to ModalEdit that would have the same effect as typing a command sequence in normal mode. That could be useful also in other use cases, but would also allow you to define a binding in ModalEdit and "call" it from VS codes standard keybindings.

johtela commented 4 years ago

Added new command modaledit.typeNormalKeys to version 1.3. It allows you to run normal mode commands through key bindings. Assuming that you have bound \n to lineBreakInsert command, and I to a command that switches to insert mode, you can combine and bind them to Shift+Enter by adding this section to your VS Code keybindings.json:

    {
        "key": "shift+enter",
        "command": "modaledit.typeNormalKeys",
        "when": "modaledit.normal",
        "args": {
            "keys": "\nI"
        }
    ,