Marcin Biegun
Marcin Biegun

Reputation: 96

Visual Studio Code - how to add a vim editor command?

I'm trying to bind ":W" editor command to save the file just like ":w". I make a lot of this typos.

The vim plugin is: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim

This settings.json code doesn't work:

"vim.normalModeKeyBindingsNonRecursive": [
  {
    "before": [":","W"],
    "commands": [
      "workbench.action.files.save"
    ]
  }
]

Upvotes: 5

Views: 2083

Answers (1)

Jon
Jon

Reputation: 2584

Unfortunately this is not possible in vs code vim, but I ended up doing what bsaf suggested here and rebound : to ; so that I wouldn't accidentally be holding shift down while pressing w, which doesn't solve the problem you asked but it does solve the problem you mentioned in your post. You can do this by adding this to your settings.json file:

"vim.normalModeKeyBindings": [
  {
     "before": [";"],
     "after": [":"]
   }
]

You can still use : as normal, but now ; will also allow you to run editor commands.

Upvotes: 1

Related Questions