Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 751
McClAnalytics Avatar asked Jan 13 '17 17:01

McClAnalytics


1 Answers

It looks like it is currently not possible to directly set the language for a file. The workbench.action.editor.changeLanguageMode command does not take any arguments, but instead uses the quick picker to get the language after the initial command call (github). Extensions do not have a way of manipulating this either.

Here is a related issue asking for this to be exposed to the API.

like image 91
dada1134 Avatar answered Nov 15 '22 08:11

dada1134