Visual Studio hotkey to switch between code behind and source file?
Asked Answered
S

10

90

I use the Shift + F7 often to switch between source and design view.

Does anyone know of a hotkey to switch between the source file and its code behind file, e.g. between (Default.aspx and Default.aspx.cs)?

Scabble answered 26/11, 2008 at 9:13 Comment(2)
The correct answer is https://mcmap.net/q/235029/-visual-studio-hotkey-to-switch-between-code-behind-and-source-file by stackoverflow.com/users/717267/eduardo-cuomo.Jacquard
F7 does not work in VS 2022. Any suggestion ?Zoogloea
D
104

F7

Dickinson answered 26/11, 2008 at 9:19 Comment(9)
Is that possible to switch from code behind file to source file in Source view(when I switch using shift+F7 it switches me to Design view and I need press shift+F7 twice and it hangs my VS2010)Atheroma
@Vladimirs, as outlined in one of the answers below, if you set F7 to trigger View.ToggleDesigner it will cycle between code behind and markup source views. No designer nonsenseNewly
This is not the correct answer. F7 is great if you want to see the designer :P see @Atheroma answer below. View.ToggleDesigner gives the best working solution. f7 does not work for what the original question was.Doering
Depends on configurationProchora
Depends on which version of Visual Studio you are on. I am on VS 2010 and this solution does not work.Setting View.ToggleDesigner to F7 toggles between Code and Design. I think the original question seeks to know the toggle between Code and Source.Clawson
As per WickyNilliams above, the @Atheroma answer near bottom worked great for me on VS2013. F7 toggles between code and markup!Sperry
Think this answer is out of date and does not work in recent versions. In VS 2013 F7 will only switch from the .aspx to the .cs but NOT the other way round.Washko
On VS 2013, View.ToggleDesigner switches from aspx to aspx.cs and if I press again, it switches from aspx.cs to aspx, but it chooses the design view (which I do not want).Elsyelton
Works on fresh Visual Studio 2022 setup. Shift F7 to switch backSarraute
P
96

In the VS2010 the following works:

  1. Go to: Tools > Options > Keyboard

  2. Search for "View.ToggleDesigner" in "Show Commands Containing".

  3. Add new shortcut to "Global" with F7.

Prochora answered 30/9, 2013 at 14:37 Comment(13)
This is the correct way to do it. F7 now toggles between code behind and markup source view, no designer :)Newly
This is the correct way. the previous answers do not work in every scenario.Doering
What version of Visual Studio? I am using VS2013, and I only have a View.ToggleDesigner command that fits that search.Automation
I think it's now called View.ToggleDesignerWashko
The very fact that it's incorrectly called "ToggleDesigner" is precisely why I've never even tried this option to solve this problem. This has nothing to do with the designer!Washko
Fair warning: this does not work for website projects (though it does work for web applications). Otherwise, it's the best solution.Automation
Unfortunately, it switches to design view for me when I come back to the aspx file.Elsyelton
This worked for me in Visual Studio 2015 as well. Thanks!Presence
@EduardoCuomo: Thanks, It works for me. I am using Visual Studio 2012. I was looking for this. thanks again.Pachton
I'd upvote 20 as well. So simple and this is something I've wanted since VB6 and there it snuck into the product without me even knowing it.Sloven
I wrote a simple AutoHotkey script to double click on the XAML button to close the designer. Adjust to fit your screen resolution and window configuration. I assigned the hotkey Ctrl-Shift-X: ^+x:: if (WinActive("ahk_exe devenv.exe")) { Click, 195, 560, 2 } returnLowson
Can confirm this worked for me in Visual Studio 2019.Brendonbrenk
Can confirm this worked for me in Visual Studio 2022 :)Boastful
B
44

Yep just F7

Look at this poster for C# VS2008 shortcuts

You can also bind it to any combination of keys you like, go to tools, options (show all settings) environment, keybord, Show Commands for View.ViewCode and change to your liking.

Added by Rob Cooper:

For 2005 Users: Visual C# 2005 Keyboard Shortcut Reference Poster

For 2010 Users: Visual C# 2010 Keyboard Shortcut Reference Poster

Edit 08 Sept 2014

There don't seem to be posters beyond 2010 but there is a website for VS2012, VS2013 and VS14: Visual Studio Shortcuts

Bier answered 26/11, 2008 at 9:34 Comment(2)
Dude, why you have not got a +1 for the poster link, I do not know. Far more useful than just the one keystroke. +1 from me.Intellect
I didn't want to vote you up but Rob Cooper made me do it :-)Callas
C
23

For those trying to do this (switch from the code view to markup view) in VS2012, I had to go Tools > Options > Keyboard, then select

  • Keyboard Mapping Scheme as "(default)"
  • View.ToggleDesigner as the command
  • Use new shortcut in "Text Editor"
  • Set the shortcut key to F7

This results in F7 switching both ways from the markup view to the code view and vice versa.

Before doing this I had to use Shift+F7 twice to get to markup from the code view.

Checkbook answered 3/12, 2013 at 4:38 Comment(4)
Thank you. The only true "toggle" answer I see on this page.Tangy
This does in fact work for VS2015, but I'd also add that you do not need to change the Keyboard Mapping Scheme.Wholewheat
You must also actually enable the Web Forms designer for this to work. I was trying to get rid of it and just toggle between the ASPX and codebehind. Once I reenabled it, the above steps worked.Stinking
This was the answer that worked for me with VS 2017. Thank you!Plumbic
F
10

In VS 2013 it is

  1. Tools > Options > Environment > Keyboard

  2. Type "View.Toggle" or "View.ToggleDesigner" (the command could be either depending on the version of VS) in Show Commands Containing:

  3. Make Sure Use new shortcut in: is set to Global

  4. Put cursor in Press shortcut keys: box

  5. Hit F7 then the Assign button

Fluffy answered 21/10, 2014 at 15:47 Comment(1)
In VS 2008, hitting F7 at that point (or elsewhere, to do the usual "build solution" command) had no effect, until I closed the TrackIR 4 application (C:\Program Files (x86)\NaturalPoint\TrackIR4\TrackIR.exe). F7, F9 and F12 appear to all be trapped by some versions of that application. forums.naturalpoint.com/viewtopic.php?t=12544&p=57648Jonson
G
9

In case F7 does not work for you, go to "Tools - Import and Export settings - Reset all settings" and choose "Web development" template to reset to.

Geithner answered 26/2, 2012 at 22:20 Comment(7)
Or set F7 to View.ToggleDesigner. It's a misnomer action, it actually toggles source/code behind.Newly
@Newly Not necessarily. My coworker updated his settings without changing to Web Development template and F7 would toggle between code behind and the actual designer view.Automation
View.ToggleDesigner changes its behaviour according to if you've got Design View enabled (and set as default) or not.Washko
@Automation same thing happens for me.Algebraist
@Washko do you know how to disable Design View?Algebraist
@AlexanderPuchkov To disable design view in Visual Studio, go to Tools > Options > HTML Designer > General and uncheck the "Enable" boxWashko
After I disabled design view like you describe, View.ToggleDesigner switches from aspx to aspx.cs but not the other way around (vs2013).Elsyelton
A
4

Just drop the shift key, it's just F7.

Aeniah answered 26/11, 2008 at 9:17 Comment(0)
M
3

When in code view use shift-F7 to get to the designer. When in the designer use F7 to get back to code.

Morbid answered 23/4, 2009 at 10:17 Comment(0)
N
1

Try Ctrl + PageUp to toggle between design view and code behind.

Nipissing answered 26/11, 2008 at 14:27 Comment(2)
CTRL+PageUp does not toggle between design view and code behind, but it DOES toggle between the three: source/split/design views. Nice!Scabble
That's actually what I ended up in this question looking for! Thanks!!Mancunian
Q
0

Shift + F7 works for me when class Form1 is first in namespace.

Quasimodo answered 23/11, 2023 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.