VSCode – run selected text in Terminal

I always liked how Powershell ISE has this feature where I can select the command and press F8 to run it in the command window. It saves a lot of copying and pasting thru and from the windows.

When developing in VSCode, I need to find the same way.

A quick googling has found me the solution.

The best thing is, no extension is needed.

Here it is.

Step 1

Press Ctrl + K + S, to open File > Preference > Keyboard Shortcut and search for workbench.action.terminal.runSelectedText

Step 2

Press the + button on the left, and provide the key bindings we want. In my case, I use Ctrl + Alt + X. Ensure there are no overlapping keybindings.

And there you have it.

Let’s try it

So what you can do now is to select any line from your code, and press the shortcut key and it will automatically be executed in the active Terminal window.

It should work well now. Thank me later for time saved 😉

Share

You may also like...