当我在 Visual Studio 2005 中保存文件时是否可以运行宏?

发布于 2024-08-28 00:47:40 字数 265 浏览 2 评论 0原文

当我在 Visual Studio 2005 中保存文件时,我希望还运行一个更新版权的宏(通过正则表达式搜索和替换)。

我对正则表达式并不陌生,但我对 VB/VBA 和 Visual Studio 宏不熟悉,所以我具体需要帮助的是:

  1. 让宏在保存时运行,最好是在按 CTRL-S 之后运行,但是在它实际写入文件之前,以便实际保存搜索和替换的结果,而不必保存两次

  2. 从 VB/VBA 宏内部调用正则表达式的搜索和替换

When I save a file in Visual Studio 2005, I'd like to have a macro also run that updates a copyright (through a regular expression search and replace).

I'm not new to regular expressions, but I am new to VB/VBA and Visual Studio macros, so what I need help with specifically is:

  1. getting a macro to run upon save, preferably after I press CTRL-S but before it actually writes the file so that the results of the search and replace are actually saved without having to save twice

  2. calling search and replace for a regular expression from inside the VB/VBA macro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬シ愛 2024-09-04 00:47:40

您可以录制、重命名和分配宏。这就是我所做的。

  1. 菜单:/Tools/Macros/Record Temporary Macro
  2. Ctrl-Shift-H - 调出解决方案范围搜索并替换
  3. 在此查找选项下对话框选择正则表达式。请注意,这些语法与您在 System.Text.RegularExpressions 中找到的语法略有不同。
  4. Alt 然后 F 然后 L - 文件全部保存
  5. 使用菜单打开宏编辑器:/tools/macros/macro explorer
  6. 右键单击​​临时宏以编辑。
  7. 在此宏的项目资源管理器中右键单击以重命名临时宏并保存
  8. 分配给组合键:这是一个 链接 将其分配给组合键

因此,您可以录制几乎您想要的内容。然后对其进行调整,并将其分配给组合键。一定要先尝试你的正则表达式,并注意如果你的解决方案中的任何内容是只读的,将会有一个对话框打断你。

You can record, rename, and assign a macro. Here's what I did.

  1. Menu: /Tools/Macros/Record Temporary Macro
  2. Ctrl-Shift-H - brings up the solution wide search and replace
  3. Under find options in this dialog select regular expressions. Note these will be slightly different in syntax than what you find in System.Text.RegularExpressions.
  4. Alt then F then L - file save all
  5. Open the macro editor with Menu: /tools/macros/macro explorer
  6. Right click the temporary macro to edit.
  7. In the Project Explorer of this macro right click to rename the temporary macro and save
  8. Assign to a key combination: Here’s a link to assign it to a key combination

So the idea is you can record something that is almost what you want. Then tweak it, and assign it to a key combination. Definitely try your regex first and note that there will be a dialog interrupting you if anything in your solution is read-only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文