I write text files in markdown format, in Visual Studio Code. I have a powershell script (.ps1) that I use to convert a markdown file (.md) to a pdf file.
Currently, I have to go to the .ps1 file to execute every time I want to generate the pdf-file. I would like to run the .ps1 file without leaving the markdown file, preferably with a hotkey (f5?). Can anyone explain how to do this?
CodePudding user response:
You can achieve this by configuring a custom VS code keybinding.
- Open keybindings.json document. To do this, use
ctrl shift p
and then selectPreferences: Open Keyboard Shortcuts (JSON)
. - Create an entry to run your script (see example below).
This example will run the Powershell script C:\Users\paolo\hello-world.ps1
when f5
is pressed:
{
"key": "f5",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "powershell C:\\Users\\paolo\\hello-world.ps1\u000D" }
}
although do note that f5
is already configured to run debugging, so I wouldn't use that.