move cursor automatically from terminal to code editor in VS Code |technorchid|

 Q: How to move the cursor automatically from terminal to code editor in VS Code when the run is complete in Terminal?

problem description:

I want to start writing code in VS code editor. When the terminal window is not in focus I want the cursor to move automatically to the VS Code editor. I see in the VS Code documentation that there is a 'focus' configuration option that can be set to true to achieve this. But I can't find any documentation that tells me how to switch the focus to the VS Code editor when the terminal window is not in focus. How do I do this?

A: I assume it's possible using the IonIDE extension.

This plugin will automatically switch the editor to the active window on startup and close it when you exit. You can configure the plugin to open the editor on startup, but as far as I know, it's not possible to configure the editor to switch to the active window when a terminal is open. You can, however, configure the plugin to automatically open a new terminal and attach it to the active editor on startup.



Here's how: Go to VS Code settings (code.vscode/launch.json). In the section "Terminal", find the "active" setting. There is a "Switch to active window" setting next to it. Set it to true. That's it. If you are already using the extension, you might have to tweak it slightly. The "Switch to active window" setting might be called "Switch to active window or tab" in the setting file. The "Active window" setting might be called "Active window".


I found some messages on VS Code GitHub The previous focus settings have been moved into the "focus" section. You use the "focus" section to only focus on specific configuration settings or to shove the whole available configuration into one place. So, to force focus to code, just set focus to code. { "name": "code", "type": "editor", "request": "focus", "focus": { "when": "terminal && editor", "type": "paragraph" } } or, if you use the ionide extension, you can also use: { "name": "ionide", "type": "editor", "request": "focus", "focus": { "when": "terminal && editor" }, "active": false } "autofocus": { "when": "terminal && editor" } "focus": { "when": "terminal && editor", "active": false } But it didn`t work for me, so maybe I was using the wrong setting. Reference: https://github.com/Microsoft/vscode/issues/5802#issuecomment-284917587 { "name": "code", "type": "editor", "request": "focus", "focus": { "when": "terminal && editor", "type": "paragraph" }, "active": false } "autofocus": { "when": "terminal && editor" } "focus": { "when": "terminal && editor", "active": false } "focus": { "when": "terminal && editor", "active": false }


The working configuration is: { "name": "code", "type": "editor", "request": "focus", "focus": { "when": "terminal && editor", "type": "paragraph" }, "active": false } "autofocus": { "when": "terminal && editor" } "focus": { "when": "terminal && editor", "active": false } "focus": { "when": "terminal && editor", "active": false } "focus": { "when": "terminal && editor", "active": false } "autofocus": { "when": "terminal && editor" } or, if you use the ionide extension, you can also use:
{ "name": "ionide", "type": "editor", "request": "focus", "focus": { "when": "terminal && editor" }, "active": false } "autofocus": { "when": "terminal && editor" } "focus": { "when": "terminal && editor", "active": false }


Previous
Next Post »