VS Code has a built in feature that allows you to send code directly from the editor to the terminal. By default, it is not assigned to any shortcut. You can assign it to a shortcut by adding the following to your
- Open the command pallet using cmd + shift + p.
Preferences: Open Keyboard Shortcuts (JSON)
- Then edit the
// Send selected bash code to terminal
"when": "editorTextFocus && !findInputFocussed && !replaceInputFocussed && editorLangId == 'shellscript'"
when key ensures that this shortcut is only active when you are working on a Shell Script file. Here is an example of the shortcut in action.