简体   繁体   中英

In VSCode, Exit Vim Insert Mode on Save

I use VSCode with the VSCodeVim extension. When in Insert Mode, I can press "CMD-S" to save. When I do, I would also like to exit Insert Mode automatically instead of pressing "ESC" as well.

Is this possible?

I was looking for a solution similar to this issue as well.

It appears that multiple commands cannot be mapped to key bindings in vscode; however, I've found an extension, macros , that let's you do this.

If you use the below steps with the macros extension, I believe that you'll have the solution you're looking for, until vscode implements something to address this feature request.

Step one, edit user settings with the below:

"macros": {
    "saveAndExitVimInsertMode": [
        "workbench.action.files.save",
        "extension.vim_escape"
    ]
}

Step two, edit keyboard bindings:

    {
    "key": "cmd+s",
    "command": "macros.saveAndExitVimInsertMode"
    }

VSCodeVim extension supports insert mode key bindings. Here is a link to the extension readme that describes this feature.

Here is a snippet you could put in your settings.json.

"vim.insertModeKeyBindingsNonRecursive": [
    {
        "before": [ "<C-s>" ],
        "commands": [
            { "command": "workbench.action.files.save" },
            { "command": "extension.vim_escape" }
        ]
    }
],

After reloading your vscode window you can pressing ctrl + s to exit insert mode and save the file.

open Show Command Palette ( Ctrl + Shift + P ). enter 'open keyboard shortcut' , search 'extension.vim_escape' and edit it to be 2 times caps lock key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM