In vs2008, how can I (possibly with a macro) assign a shortcut key to collapse to definitons but leave regions expanded (they must expand if collapsed)?
EDIT: I hate regions but my co-workers does not (: So I want this to avoid the regions used by them.
I read jeff's post. Ctrl M + O is what I really want to do, if there were not regions.
CTRL + M + O will collapse all.
Simply press the Alt + Shift + Right Arrow keys instead. If you want to collapse all groups in a worksheet, press the Alt + Shift + A keys on your keyboard. This shortcut will collapse all groups in the active worksheet. You can also use this shortcut to expand all groups in a worksheet.
(Ctrl+M, Ctrl+P) - Removes all outlining information for the entire document. (Ctrl+M, Ctrl+U) - Removes the outlining information for the currently selected user-defined region. Not available in Visual Basic. (Ctrl+M, Ctrl+O) - Collapses the members of all types.
I believe I have finally got the answer that I've been looking for, and I think it might help you as well, @Serhat. You said:
I read jeff's post. Ctrl M + O is what I really want to do, if there were not regions.
That was exactly what I was thinking to myself. I continued that line of thought and worked on a way to (temporarily) get rid of the #regions.
This isn't a complete solution, but I'm so glad to have something that I'm on the verge of jumping up and down. I will try to make these directions as easy as possible, although I daresay it may simply be easier to post the actual content of the macros I've created. (see link at bottom)
I've created two macros:
Create the first macro:
Ctrl+Shift+R
, and follow these steps:Ctrl+H
, Find what: #region
, Replace with: //#region
Alt+A
for Replace AllCtrl+H
, Find what: #endregion
, Replace with: //#endregion
Alt+A
for Replace AllCtrl+Shift+R
Alt+F8
or Tools | Macros > Macro ExplorerThen, create the second macro:
Ctrl+Shift+R
, and follow these steps:Ctrl+H
, Find what: //#region
, Replace with: #region
Alt+A
for Replace AllCtrl+H
, Find what: //#endregion
, Replace with: #endregion
Alt+A
for Replace AllCtrl+Shift+R
Alt+F8
or Tools | Macros > Macro ExplorerNow, save your macros in the Macro Explorer with Ctrl+S.
Finally, assign shortcut keys to the two macros:
Directives
. This should show you your two macros, named "Macros.MyMacros.RecordingModule.CommentRegionDirectives" and "...UncommentRegionDirectives"Alt+/
then click the Assign
buttonAlt+Shift+/
then click the Assign
button (by default these two shortcut combinations are not assigned to anything)Now, when you are faced with auto-collapsed #regions, hit Alt+/
to comment out the #region directives, and hit the standard Ctrl+M+O
for Collapse to Definitions (if you so choose). Then later, before committing that unit with the commented-out #regions, just hit Alt+Shift+/
to uncomment the #regions and they will be reactivated.
And finally, @Serhat, thank you again for your original comment which put me on this track in the first place.
In practice there is one little hiccup that I am quite willing to live with. //#region
followed by #//endregion
counts as a contiguous comment and comments are still collapsed, but at least there is no code hidden in there.
Here is the promised macro text I extracted from the Macro Explorer: http://pastebin.ca/1688618, although it shouldn't be required if you manually follow the steps I outlined above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With