pom421
pom421

Reputation: 1964

Is there a way that saving file in VS code triggers the return in Vim normal mode?

I start using the VSCodeVim plugin in VS Code.

I regularly save my file with Cmd-S (in Mac).

Following the philosophy of Practical Vim book, I consider this save point moment as a break in my thinking process. It would be cool if when I type Cmd-S, Vim returns in Normal mode.

Is there a way ?

Upvotes: 2

Views: 474

Answers (2)

Soham Dasgupta
Soham Dasgupta

Reputation: 5199

If anyone is still looking for this, here is an updated answer.

{
  "key": "cmd+s",
  "command": "runCommands",
  "args": {
    "commands": ["workbench.action.files.save", "extension.vim_escape"]
  },
  "when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode != 'Normal' && isMac"
},
{
  "key": "ctrl+s",
  "command": "runCommands",
  "args": {
      "commands": ["workbench.action.files.save", "extension.vim_escape"]
  },
  "when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode != 'Normal' && isWindows"
}

Upvotes: 2

pom421
pom421

Reputation: 1964

I found a solution.

In keybindings.json, add :

  {
    "key": "cmd+s",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "workbench.action.files.save",
        "extension.vim_escape"
      ]
    },
    "when": "editorTextFocus && vim.active && vim.mode != 'Normal'"
  }

We need to add an extra extension, because VS Code doesn't handle internally to trigger multiple commands. So add multi-command extension.

Upvotes: 2

Related Questions