Home > Net >  Is there a way to enable keyboard shortcuts only when specific file types are opened
Is there a way to enable keyboard shortcuts only when specific file types are opened

Time:09-22

I have a custom keyboard shortcut shift R enter which I only want to be enabled when working on .sql files. Is it possible to disable the shortcut when any other file type is open

CodePudding user response:

There is a context clause for language IDs. For example:

{
  "key": "alt c",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.newComponentFolderAndFiles" },
  "when": "editorTextFocus && editorLangId == sql"
}

So it is enabled for sql files (if that is the language ID) only. To see the language it click on the language mode in the lower right-hand corner of the vscode window. You use the version that is in parens, like SQL (sql). Use the version as it appears in the parens: sql.

To enable for multiple filetypes you can do this:

"when": "editorTextFocus && resourceExtname =~ /\\.(html|css|scss)"

See conditional operators for when clauses.

  • Related