I have the MS Powershell extension installed in VS Code. Other language extensions, e.g. Python, have the ability to assign a keybinding for creating a new file (python.createNewFile). I don't see this option in the Powershell extension. There isn't even an option with Ctrl-Shift-P.
EDIT:
Expanding on the Python example, using a keybinding sequence for python.createNewFile will create a new file that already has Python syntax highlighting defined. I don't have to create the file, then save it with a .py extension to achieve this. I can get right into the scripting. I'd like to be able to do the same with Powershell.
The only options I have at the moment are to Ctrl + N, Ctrl + S, and give it a file name with a .ps1 extension, or Ctrl + N and choose "Powershell" from the Select a Language list.
Is there another way to do this? A macro or something? There are other Powershell extensions, but as far as I can tell the only way to know the abilities they provide, is to install each one.
You can place an adapted version of the following in your
keybindings.jsonfile:View>Command Palette...or press Ctrl+Shift+P), commandPreferences: Open Keyboard Shortcuts (JSON); searching forkeyb jsonshould be enough to to locate it.Thereafter, pressing Shift+F12 will open a new, untitled file and set its language mode to PowerShell, which entails:
PowerShell-specific syntax highlighting of code in the file.
The suggested file name when first saving will have extension
.ps1Additionally, if you have the PowerShell extension installed (which is advisable for a rich PowerShell authoring and debugging experience):
Optional reading: How to discover Visual Studio Code's available API commands:
As of this writing, the official documentation only describes a subset of all built-in commands, in Built-in commands, which seems to be focused on commands that optionally accept or require arguments, i.e. have parameters.
However, as the linked topic notes, a current list of all (publicly available) built-in commands can be gleaned from:
Interactively, via the GUI, using the view that the
Preferences: Open Keyboard Shortcutscommand palette entry (Ctrl+K, Ctrl+S) opens:language modethere.Alternatively, via the virtual JSON-based view of the same information that opens in an editor tab, by choosing
Preferences: Open Default Keyboard Shortcuts (JSON)from the command palette.workbench.action.editor.changeLanguageModeThat said, neither of these views reveal the arguments (parameter names) supported by these commands,[1] except - in the latter view only - if bound keyboard shortcuts happen to use arguments (
"args"properties).workbench.action.editor.changeLanguageMode- which seems like the logical command to use - is purely a UI-based command and therefore doesn't accept arguments; see next point.While the Built-in commands topic does describe the specific arguments a given command supports, that description is sometimes lacking, requiring digging into the source code, which is indeed how the specific parameter name (
languageID) was discovered in the case at hand.[1] Neither does the Gist you mention in a comment, whose results are based on authoring a dummy extension (and seemingly includes non-public commands, prefixed with
_). The results there are a snapshot of the available commands at a given point in time. Fellow users have provided updated snapshots over time, but using the methods described above is preferable, as they are guaranteed to be current for a given Visual Studio Code installation.