skip to Main Content

Good Evening,

I’m trying to bind multiple actions for the same key based on the file extension of the current buffer in VSCode.

If i do it with one binding, it works perfect, but if i add a second one, with the same key, it overwrites the first one.

This is an example:

{"before": ["key"],"commands": [{command_1},{command_2},{etc}],"when":"resourceExtname == .ext1"}

If i do this, it works as expected, but if i then add another binding for the same key with another extension:

{"before": ["key"],"commands": [{command_3},{command_4},{etc}],"when":"resourceExtname == .ext2"}

It uses everytime the commands for .ext2 files, the first keybind gets overwritten.

I’m not sure if this can be achieved somehow, or by limitation of VSCode you can’t bind more than one action to the same key.

Any help would be welcome, thanks in advance!

EDIT: Forgot to add that those are bindings for the VIM plugin in VSCode.

EDIT 2: It seems to be a limitation of the Vim plugin, but one of the devs provided a workaround that indeed works, so, i’m closing it. https://github.com/VSCodeVim/Vim/issues/4765

2

Answers


  1. Chosen as BEST ANSWER

    It seems to be a limitation of the VIM plugin, but one of the devs provided a workaround, just tested it and it works, so i'm closing this.

    This is the workaround: https://github.com/VSCodeVim/Vim/issues/4765


  2. You should use the editorLangId in the when expression

    {
      "before": ["key"],
      "commands": [{command_1},{command_2},{etc}],
      "when":"editorLangId == typescript"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search