visual-studio-code

How can I create a custom keybinding to change syntax highlighting to a specific language in Visual Studio Code?


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

Based on the above default keybinding to trigger the 'Select Language Mode' drop down, I'm assuming that I should be able to pass in another parameter (or refine the "command" string) in a custom keybindinds.json string to force the selection of a specific language's syntax file.

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

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

What additional parameter can I pass in to force workbench.action.editor.changeLanguageMode to select 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


Solution

  • You can do it with extension:

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

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