8

Is there a shortcut to set the focus easily to the editor where my code is? I don‘t want to cycle through anything or hide something else, I want a direct shortcut to jump with the focus to the editor. My focus is anywhere in VS and I want to set it to the editor.

Example scenario: I‘m writing code (focus is in the text editor) and then press F5 to run the code. The Output View opens and gets the focus and even keeps it even if the program has terminated. I now want to switch the focus back to the editor without using the mouse. Or I switch focus to the Solution Explorer with Ctrl+Alt+L to look something up and then want to go back to coding without touching the mouse.

I‘m using Visual Studio Professional 2017 if it makes any difference.

8 Answers 8

1

In VS2022 I think it's set to Esc by default.

The keyboard command is Window.ActivateDocumentWindow, which can be found here if you wanted to assign it to a different keyboard shortcut:

Tools > Options > Environment > Keyboard > Window.ActivateDocumentWindow

New contributor
James Lieu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 1
    Thanks, gonna change the accepted answer to this. This is better than Ctrl+Tab or Ctrl+F6 (at least with VS2022, reading other answers it seems the command was there before but had no default shortcut) and it is the most complete one for my question.
    – bugybunny
    2 days ago
10

You can simply do it by hitting one of the following

  • Ctrl + Tab
  • Ctrl + F6
0
3

There is no such shortcut for Visual Studio, but you might create one with the help of this AutoHotKey script:

SetTitleMatchMode, 2
#IfWinNotActive, Visual Studio
F4::WinActivate, Visual Studio

I have chosen here the F4 key, but you may choose any other key.

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group.


A solution for returning to the text-editor while Visual Studio has the focus is by using the hotkey Ctrl+Tab.

6
  • 1
    That‘s disturbing that VS hasn‘t a keybinding for this, wtf?! Seems like something that would be used a lot. I‘m gonna see if there‘s already an open issue or create one (if that‘s possible for VS).
    – bugybunny
    Oct 9, 2018 at 12:37
  • I don't think the VS group will willingly add a hotkey that works outside of VS.
    – harrymc
    Oct 9, 2018 at 12:38
  • Ok, this clears up that you misunderstood the question :p I was just googling before I even tried it because it seems that you only bring the VS window to the front/focus it. I want a part of VS focused while I‘m inside VS. I‘ve updated the question shortly before or after you gave your answer to include an example.
    – bugybunny
    Oct 9, 2018 at 12:40
  • 1
    No fun when the question changes while I'm typing. Is this shortcut a solution : Ctrl-Tab? Explain why if not.
    – harrymc
    Oct 9, 2018 at 12:48
  • I didn‘t change the question. I just added an example to clarify what I mean since the other user answered something completely unrelated imo. Now that I‘m reading it again I can see how you understood it, sorry. Ctrl+Tab works lol. I didn‘t even think about that. Eclipse had a direct keybinding for it so I was looking for exactly something like that
    – bugybunny
    Oct 9, 2018 at 13:06
3

I find the the action workbench.action.focusActiveEditorGroup

So bind something with that, like ctrl+q

To make the shortcut work through terminal add it to setting.json

// setting.json

"terminal.integrated.commandsToSkipShell": [
    "workbench.action.focusActiveEditorGroup",
 ]
2
  • 1
    This answer is for VS Code, as opposed to Visual Studio. But I came here looking for an answer for VS Code, so... good? Mar 5, 2020 at 16:33
  • funny :) i like the idea that i help you eventually
    – pery mimon
    Mar 5, 2020 at 18:37
1

Editor management

Ctrl+F4, Ctrl+W Close editor
Ctrl+K F Close folder
Ctrl+\ Split editor
Ctrl+ 1 / 2 / 3 Focus into 1st, 2nd or 3rd editor group
Ctrl+K Ctrl+ ←/→ Focus into previous/next editor group
Ctrl+Shift+PgUp / PgDn Move editor left/right
Ctrl+K ← / → Move active editor group

From https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf

And for other Operating Systems - https://code.visualstudio.com/docs/getstarted/keybindings

3
  • This doesn’t answer my question…? I mean (will update the question if it wasn’t clear) that the focus is in the output view and I want to my code in the text editor to edit code again.
    – bugybunny
    Oct 9, 2018 at 12:23
  • A clearer question would be favorable then. Oct 9, 2018 at 12:24
  • 2
    You provided shortcuts for Visual Studio Code, but the question is asking about Visual Studio. (VS Code != Visual Studio) Jun 19, 2019 at 23:46
1

I've found myself craving such a shortcut key too just now.

Harrymc mentioned Ctrl+Tab in his post. While that seems to do the trick, if I were to double-hit it by accident, it'll jump to another editor tab.

So I thought I'd try to find a more fool-proof way.

I noticed that focus could be returned to the last edited file somewhat tediously via the menu-system, with "Window >> Windows... >> Activate".

So I've personally settled for automating those steps via AutoHotKey. In this script example, I'll bind it to "Alt+."

#IfWinActive ahk_exe devenv.exe
!.::
Send, !w
Send, w
Send, {Enter}
return
#If
1
  • This works great! Slight improvement: change the last two sends to just "Send, 1" and then it won't open up the "Windows" dialog.
    – marchica
    Aug 13, 2019 at 18:02
1

I'm on VS2019: using ESC sets focus back to the editor.

However, if the pane is set to auto-hide (not pinned), it doesn't seem to hide unless your mouse cursor is outside of the pane.

0

Tools > Options > Environment > Keyboard > Window.ActivateDocumentWindow

Set any hotkey you want.

1
  • I don’t understand what the user is supposed to do here.  Can you clarify? … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Aug 20, 2020 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.