How to create a custom key binding to change syntax highlighting to a specific language in Visual Studio code?

{ "key": "ctrl+k m",              
       "command": "workbench.action.editor.changeLanguageMode" },

Based on the aforementioned default key join, in order to release “Select Language Mode”, I assume that I should be able to pass another parameter (or refine the “command” line) in the user keybindinds.json line to force the choice of a specific language syntax file.

In SublimeText 3, my custom .json keybinding for switching to SQL syntax highlighting looked like this:

{"keys": ["alt+s"], "command": "set_file_type",
    "args": {"syntax": "Packages/SQL/SQL.sublime-syntax"}}

What additional parameter can I pass to force me to workbench.action.editor.changeLanguageModeselect a specific language identifier?

https://code.visualstudio.com/docs/languages/identifiers

https://github.com/Microsoft/vscode/blob/2e2b47a4944ad1dfc7bbc58756c91aa3188cfa04/src/vs/workbench/browser/parts/editor/editorStatus.ts

+4
source share
2 answers

It looks like it is currently not possible to directly set the language for the file. The command workbench.action.editor.changeLanguageModedoes not accept any arguments, but instead uses a quick selector to get the language after the initial invocation of the command ( github ). Extensions also do not have the ability to manipulate this.

Here is a related issue requiring this to be shown in the API.

+1
source

You can do this with the extension:

{
    "key": "ctrl+shift+8",
    "command": "changeLanguageMode.change",
    "args": "sql"
}

https://marketplace.visualstudio.com/items?itemName=usernamehw.change-language-mode

0

Source: https://habr.com/ru/post/1666738/


All Articles