stevGates
stevGates

Reputation: 952

How can I swap focus when I run Python code in VSCode without using the mouse?

When I run a code without debug (Ctrl+F5) the cursor stays in the terminal. How do I change the settings so that the focus stays in the editor after running the code?

Upvotes: 1

Views: 1295

Answers (1)

Scott McPeak
Scott McPeak

Reputation: 12749

Title question: "How can I swap focus [...] without using the mouse?"

Answer: Use command "View: Focus First Editor Group", which by default is bound to Ctrl+1.

Body question: "how [...] after running any code the focus stays in the editor ?"

Answer: One way is, in launch.json, to set console to externalTerminal. Then the output will appear in a new window, and after you press a key to dismiss it, the VSCode focus will remain where it was when you pressed Ctrl+F5.

If you don't have a launch.json file yet, VSCode will make one for you with "Debug → Open Configurations". Here is the launch.json my VSCode created when I did that, and I then subsequently edited:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      //"console": "integratedTerminal"
      "console": "externalTerminal"
    }
  ]
}

Upvotes: 2

Related Questions