折叠到除区域之外的定义的快捷方式 [英] Shortcut to collapse to definitions except regions

查看:102
本文介绍了折叠到除区域之外的定义的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vs2008中,我如何(可能带有宏)分配一个快捷键来折叠至定义,但保留区域展开(如果折叠则必须展开)?

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)?

编辑:我讨厌地区,但我的同事不喜欢(:因此,我希望这可以避免他们使用的地区.

I hate regions but my co-workers does not (: So I want this to avoid the regions used by them.

我读了杰夫的帖子.如果没有区域,我真正想做的就是Ctrl M + O.

I read jeff's post. Ctrl M + O is what I really want to do, if there were not regions.

推荐答案

我相信我已经最终得到了我一直在寻找的答案,而且我认为这也可能对您有所帮助, @Serhat.你说:

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:

我读了杰夫的帖子.如果没有区域,我真正想做的就是Ctrl M + O.

I read jeff's post. Ctrl M + O is what I really want to do, if there were not regions.

这正是我对自己的想法.我继续遵循这种思路,并致力于(暂时)摆脱#region.

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)

我创建了两个宏:

  1. 注释掉所有#region和#endregion指令.
  2. 取消注释所有//#region和//#endregion事件.

创建第一个宏:

  • 开始使用Ctrl+Shift+R录制宏,并按照以下步骤操作:
  • Ctrl+H,查找内容:#region,替换为://#region
  • Alt+A表示全部替换
  • Ctrl+H,查找内容:#endregion,替换为://#endregion
  • Alt+A表示全部替换
  • Ctrl+Shift+R
  • 结束宏的录制
  • 使用Alt+F8或工具"打开Macro Explorer.宏>宏浏览器
  • 将TemporaryMacro重命名为CommentRegionDirectives
  • Start recording a macro with Ctrl+Shift+R, and follow these steps:
  • Ctrl+H, Find what: #region, Replace with: //#region
  • Alt+A for Replace All
  • Ctrl+H, Find what: #endregion, Replace with: //#endregion
  • Alt+A for Replace All
  • End recording the macro with Ctrl+Shift+R
  • Open the Macro Explorer with Alt+F8 or Tools | Macros > Macro Explorer
  • Rename TemporaryMacro to CommentRegionDirectives

然后,创建第二个宏:

  • 开始使用Ctrl+Shift+R录制宏,并按照以下步骤操作:
  • Ctrl+H,查找内容://#region,替换为:#region
  • Alt+A表示全部替换
  • Ctrl+H,查找内容://#endregion,替换为:#endregion
  • Alt+A表示全部替换
  • Ctrl+Shift+R
  • 结束宏的录制
  • 使用Alt+F8或工具"打开Macro Explorer.宏>宏浏览器
  • 将(新的)TemporaryMacro重命名为UncommentRegionDirectives
  • Start recording a macro with Ctrl+Shift+R, and follow these steps:
  • Ctrl+H, Find what: //#region, Replace with: #region
  • Alt+A for Replace All
  • Ctrl+H, Find what: //#endregion, Replace with: #endregion
  • Alt+A for Replace All
  • End recording the macro with Ctrl+Shift+R
  • Open the Macro Explorer with Alt+F8 or Tools | Macros > Macro Explorer
  • Rename (this new) TemporaryMacro to UncommentRegionDirectives

现在,使用Ctrl + S将宏保存在宏资源管理器"中.

Now, save your macros in the Macro Explorer with Ctrl+S.

最后,将快捷键分配给两个宏:

Finally, assign shortcut keys to the two macros:

  • 打开工具|选项|环境+键盘
  • 在显示包含以下内容的命令"中,键入Directives.这应该显示两个宏,分别为"Macros.MyMacros.RecordingModule.CommentRegionDirectives"和"... UncommentRegionDirectives"
  • 突出显示CommentRegionDirectives条目,并在按快捷键:"框中键入Alt+/,然后单击Assign按钮
  • 突出显示UncommentRegionDirectives条目,并在按快捷键:"框中键入Alt+Shift+/,然后单击Assign按钮(默认情况下,这两个快捷键组合未分配任何内容)
  • 单击确定"保存快捷方式分配.
  • Open Tools | Options | Environment+Keyboard
  • In "Show commands containing:" type in Directives. This should show you your two macros, named "Macros.MyMacros.RecordingModule.CommentRegionDirectives" and "...UncommentRegionDirectives"
  • Highlight the CommentRegionDirectives entry and in the "Press shortcut keys:" box type Alt+/ then click the Assign button
  • Highlight the UncommentRegionDirectives entry and in the "Press shortcut keys:" box type Alt+Shift+/ then click the Assign button (by default these two shortcut combinations are not assigned to anything)
  • Click OK to save your shortcut assignments.

现在,当您遇到自动折叠的#region时,请按Alt+/注释掉#region指令,然后按标准的Ctrl+M+O折叠到定义(如果您选择).然后,在提交带有注释掉的#region的单元之前,只需按Alt+Shift+/取消注释#region,它们将被重新激活.

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.

最后,@ Serhat,再次感谢您的原始评论,这些评论使我排在了首位.

And finally, @Serhat, thank you again for your original comment which put me on this track in the first place.

在实践中,我很愿意忍受一点小麻烦. //#region后跟#//endregion视为连续注释,并且注释仍然折叠,但是至少其中没有隐藏代码.

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.

这是我从宏浏览器中提取的承诺宏文本: http://pastebin.ca/1688618 ,但如果您手动执行上述步骤,则不需要.

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.

这篇关于折叠到除区域之外的定义的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆