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.
I find Ctrl + M, Ctrl + O is really useful to collapse everything.
Have you read Jeff's blog post about regions? There's a few more useful shortcuts he lists.
Why do you want to keep these expanded, do you really need the region if you don't want it collapsed?
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:
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 theAssign
buttonAlt+Shift+/
then click theAssign
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 standardCtrl+M+O
for Collapse to Definitions (if you so choose). Then later, before committing that unit with the commented-out #regions, just hitAlt+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.