除了宏之外,如何在 TextMate 中执行多次查找和替换?

发布于 2024-09-19 01:54:44 字数 245 浏览 9 评论 0原文

我有几个正则表达式来查找和替换 TextMate 文档中的文本。我希望能够让它们批量运行。我制作了一个宏并且它有效,但是对宏的任何微小修改都意味着重新录制宏。我似乎无法修改 TextMate 界面中的正则表达式。由于某种原因它是只读的。

我可以把它变成命令吗?有人知道怎么做吗?我尝试阅读有关命令的 TextMate 帮助,但没有太大帮助。看来我需要先了解 shell 脚本或某种类型的知识(我没有)。任何有关该方向的建议都会很棒。

提前致谢。

I have several regular expressions to find and replace text in documents in TextMate. I would like to be able to have them run in a batch. I made a macro and it worked, but any tiny modifications to the macro means re-recording the macro. And I can't seem to modify the regex within the TextMate interface. It's read-only for some reason.

Can I make it into a command? Does anyone know how? I tried to read the TextMate help about commands, but it wasn't much help. It seems I need prior knowledge of shell scripts or some sort (which I have none). Any advise in the direction would be great.

Thanx in advance.

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

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

发布评论

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

评论(1

逆光飞翔i 2024-09-26 01:54:44

首先,可以编辑宏。由于这对您来说是最简单的解决方案,因此您可以这样做:

  1. 记录一个新宏并将其保存在 TheBundleOfYourChoice
  2. Reload Bundles 中,通过“Bundles”> > “捆绑编辑器”> “重新加载捆绑包”
  3. 在 TextMate 中打开文件“~/Library/Application Support/TextMate/Bundles/TheBundleOfYourChoice.tmbundle/Macros/NameOfYourMacro.tmMacro”(如果按 Command-Shift-G,您可以访问任何路径 - 包括隐藏路径)在“打开文件”对话框中)
  4. 将宏的 XML 表示形式更改为您的需要
  5. 再次重新加载捆绑包
  6. 使用更新的宏

此解决方案对您来说可能是最简单的,因为它不需要您学习脚本语言,并且应该是可以进行微小的更改。然而,另一种非常合理的方法是选择您选择的脚本语言并简单地构建一个命令来运行您的正则表达式。您可以使用 perl、python、ruby、bash 等。一个简单的解决方案应该是 bash 和 sed。 sed 是一个小工具,其唯一目的是处理文本,应该是您的理想选择。 bash 是默认的脚本语言,所以应该没问题。你会以某种方式弄清楚并学到很多东西。尝试一下! :)

First, it's possible to edit macros. Since this is the easiest solution for you, here is how you do it:

  1. Record a new Macro and save it in TheBundleOfYourChoice
  2. Reload Bundles via "Bundles" > "Bundle Editor" > "Reload Bundles"
  3. Open the file "~/Library/Application Support/TextMate/Bundles/TheBundleOfYourChoice.tmbundle/Macros/NameOfYourMacro.tmMacro" in TextMate (you can access any path - including hidden ones - if you press Command-Shift-G while in the "Open File" dialog)
  4. Change the XML-representation of the Macro to your needs
  5. Reload Bundles again
  6. Use updated Macro

This solution may be the easiest for you, because it doesn't require you to learn a scripting language and should be OK for minor changes. However another very reasonable approach is choosing a scripting language of your choice and simply build a command, which runs your regular expressions. You can use perl, python, ruby, bash and so forth. A simple solution should be bash with sed. sed is a small tool, whose only purpose is to process text and should be ideal for you. bash is the default scripting langauge, so should be no problem either. You will figure it out somehow and learn a lot. Give it a try! :)

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