2

Let's say I have the following:

['cart', 'horse']

Is there a quick way to swap the two so I have the following:

['horse', 'cart']

I'm referring to the actual text and not reordering an array programmatically. For example, I usually do something like this:

  1. Highlight and cut " 'horse'"
  2. Delete the trailing comma
  3. Paste " 'horse'" before "'cart'"
  4. Delete the leading space
  5. Add ", " after "'horse'"

I find myself needing to do this type of thing frequently, so I'm wondering if TextMate has some type of built-in functionality/bundle for accomplishing this.

Thanks.

robertwbradford
  • 6,181
  • 9
  • 36
  • 61
  • Brilliant selection of example case. – hughes Jul 07 '11 at 18:47
  • Thanks, I figured it would emphasize the point :) – robertwbradford Jul 07 '11 at 19:51
  • do you have many rows like this--is that your motivation to simplify/automate this task? If so, TM has an excellent "column-select" function, so that e.g., you can do steps 1-5 only one but have it apply to all other rows below. – doug Jul 07 '11 at 22:10
  • Thanks, @doug. I'm aware of this (option key), but in this case the motivation is to simplify the steps listed regardless of the number of columns. – robertwbradford Jul 08 '11 at 13:55

1 Answers1

2

When I have to do something like this, I will use regular expressions in the Search & Replace dialog.

Search for: '(.*)', '(.*)'

Replace with: '$2', '$1'

And make sure that the "Regular Expression" box is ticked. There may be a bundle that can help out with this, but I often find it easier to write a quick regex to reorder/rearrange.

Bill Turner
  • 3,695
  • 1
  • 20
  • 26
  • Thanks, @Bill. After highlighting two values to swap I was able to record a macro with the following steps: [1] Opened the Find dialog box. [2] Used "(.*), (.*)" as the search term (without quotes), "$2, $1" as the replace term (without quotes), and checked "Regular Expression" [3] Clicked "Replace". I then saved the macro and assigned a keyboard shortcut. Works like a charm! – robertwbradford Jul 11 '11 at 16:25