Friday, December 23, 2011

TextWrangler Saved Pattern Reordering

TextWrangler has the ability to save your search-and-replace regular expressions.

You can usually find this by opening the Find/Search dialog (Command-F) and notice the 'g' dropdown on the right:



As of TextWrangler 3.5.3 (2890), there is no method for reordering these saved search patterns.

I have found that I want my most-recently added patterns near the top, since I intend on using them most frequently.  In order to do this, you need to open an XML file which contains these values:

$HOME/Library/Preferences/com.barebones.textwrangler.PreferenceData/Grep Patterns.xml

Here, you'll find an array of <dict> entries. For example, I have:


<dict>
  <key>ReplacePattern</key>
  <string></string>
  <key>SearchPattern</key>
  <string>(?&lt;![ \t\r])[ \t]+$</string>
  <key>Title</key>
  <string>Trailing Spaces</string>
  <key>UniqueID</key>
  <string>BD891F29-F04A-4951-B66C-40CE64A590FD</string>
 </dict>
<dict>
<key>ReplacePattern</key>
<string>\1 \(</string>
<key>SearchPattern</key>
<string>\b(if|for|while|switch)\(</string>
<key>Title</key>
<string>Space if|for|while|switch</string>
<key>UniqueID</key>
<string>6555C867-BBF4-4DC3-B2C0-B51EA7B64486</string>
</dict>


To rearrange them in TextWrangler, simply rearrange the entire <dict>...</dict> sections as you prefer and save!

Update 2012-02-09:

If you have access to a plist editor (free with Apple's Xcode or other alternatives online), this XML plist format can be rearranged with those tools a little safer. Find one that accepts simple drag-and-drop and you're set!

No comments:

Post a Comment