[TxMt] Re: Select word and replace with different word

Allan Odgaard mailinglist at textmate.org
Thu Mar 13 06:12:51 UTC 2014

On 12 Mar 2014, at 21:37, Ross Ahmed wrote:

> I often have a list of birds like this […] I need to convert them 
> into their abbreviated codes […]
> My current strategy is to just manually replace each bird name with 
> their
> code. I was hoping to make 5 selections (multiple cursors, one cursor 
> for
> each bird name), and convert them to their codes in one keystroke. 
> Does this
> sound possible?

Since a lookup table is required to transform the bird names, there is 
no good way around writing code for this task.

But a simple command can do this, I attached an example. Double-click to 

After that, you can press F3 to convert bird names in your selection or 
document (if there is no selection).

You can augment the list in the bundle editor and/or change the key 
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<string>#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -wKU

Birds = {
  'Mallard'       => 'BA',
  'Redshank'      => 'MA',
  'Ringed Plover' => 'RK',
  'Turnstone'     => 'RP',  

regexp = Regexp.new('\b(' + Birds.keys.join('|') + ')\b')
STDOUT << STDIN.read.gsub(regexp) { |m| Birds[m] }
	<string>Convert Birdnames</string>

More information about the textmate mailing list