问题
Is it any keyboard shortcut or free addon in Visual Studio 2010 that allows to switch between header (C/C++ .h file) and implementation (C/C++ .cpp file)?
回答1:
Visual Studio does not have a built-in keyboard shortcut to switch back and forth. A macro is by far your best bet if you want to automate this with a single keyboard shortcut. For a list of suggested options, see the answers to a previous question.
The add-in Visual Assist X provides this feature with the shortcut Alt+O (however, add-ins are not supported by the Express editions of Visual Studio).
If you're trying to avoid using a macro, there is an alternative way to achieve a similar result, although it is a two-click process:
- To switch from header to implementation:
Right-click a.cpp file and choose "Go To Header File" from the context menu.
To switch from implementation to header: Right-click an identifier declared in the header and choose "Go To Definition" from the context menu.
回答2:
MS added this feature in Visual Studio 2013. It's a default keyboard shortcut Ctrl + K, Ctrl + O
To clarify: Keep Ctrl pressed, type K, type O, release Ctrl.
You can find the command this maps to from the customize-keyboard options as well (tested for VS2015):
回答3:
My workaround to this problem is a bit unorthodox but it might help others, so I'll share.
I use the window list. And I thought it would annoy the heck out of me doing it this way, but I've actually gotten quite used to it. It continues to apply, even in Visual Studio 2012, so I'm offering it as yet another alternative.
Once both the .cpp and .h files are open, I switch between them like this...
- To switch from .cpp to .h:
Alt+W, W, Down Arrow, Enter
- To switch from .h to .cpp:
Alt+W, W, Up Arrow, Enter
You can actually hold down the Alt
key while pressing the W
the second time, effectively making it: Alt+W, Alt+W, Down Arrow, Enter
(You don't have to release the Alt
key until you type the arrow key)
This works because the .cpp and .h files are typically adjacent alphabetically in the window list. It also works for .c and .h for the same reason. Breaking it down: Alt+W
goes to the "Window" menu, and the second W
activates the "Windows..." window list viewer. The active window will be selected in the list box, so pressing the up or down arrow key will move to the document that is before or after alphabetically, which is almost always the corresponding .h/.cpp file.
As yet another alternative, I should also mention that if you place the .cpp and .h files beside each other in the window tabs, then you can use: Ctrl+Alt+Page Up
, and Ctrl+Alt+Page Down
to switch between adjacent tabs in the tabbed window list.
I realize that you have to "prepare" by having both documents open, and this is less than ideal, but I typically have all my documents open anyway, and I use the Alt+W, W
shortcut a lot.
回答4:
Such shortcut key is added in CodeMaid. CodeMaid is an open source Visual Studio extension
Ctrl + M then ,
http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/
回答5:
In VS2010 - The keyboard shortcut "EditorContextMenu.CodeWindow.GoToHeaderFile" does the same thing as the right click menu. Unfortunately it doesn't work as a toggle to switch back again. (Though, you can use ctrl - to go navigate back if you started in the cpp).
来源:https://stackoverflow.com/questions/4183674/how-to-switch-between-header-and-implementation-in-vs2010