开发者

How to perform multiple find and replace in TextMate besides macro?

开发者 https://www.devze.com 2023-01-16 03:48 出处:网络
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 t

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 h开发者_Python百科elp. 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.


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! :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号