[TxMt] Transpose chars and transpose words
Juan
juanfc at lcc.uma.es
Sun Feb 11 18:04:26 UTC 2007
I have been using different approaches to Transpose chars and
transpose words in AlphaX for a long time.
The usual way is really annoying, it swaps the chars around the
cursor. In the Cocoa (emacs-like) version it is also not symmetric:
if you do it two times the result is not the original (!)
Usually you notice you made a mistake after you have written the
chars. It is annoying to need to position yourself between the last
two chars to swap them.
The approach I use (and many Alpha users) is
transpose the last really chars, though spaces or parenthesis, etc
could be in between the cursor and the last two chars!
transpose word in this way is even better, since it also can swap
function arguments, etc.
Here I send the source for this to commands:
---------------------------- transpose chars ^T (v)SelecText|line (^)
ReplaceSel
#!/usr/bin/env ruby
sel = ENV['TM_SELECTED_TEXT']
if sel != nil
sel = sel.dup
sel.gsub!(/^(\w)(.*)(\w)$/u, '\3\2\1')
print sel
exit 0
end
left = ENV['TM_CURRENT_LINE'][0, ENV['TM_LINE_INDEX'].to_i]
right = ENV['TM_CURRENT_LINE'][ENV['TM_LINE_INDEX'].to_i .. -1]
left.gsub!(/(\w)(\W*)(\w)(\W*)$/u, '\3\2\1\4')
print left + right
----------------------
---------------------------- transpose chars ^-Opt-T (v)SelecText|
line (^)ReplaceSel
#!/usr/bin/env ruby
sel = ENV['TM_SELECTED_TEXT']
if sel != nil
sel = sel.dup
sel.gsub!(/^(\w+)(.+?)(\w+)$/u, '\3\2\1\4')
print sel
exit 0
end
left = ENV['TM_CURRENT_LINE'][0, ENV['TM_LINE_INDEX'].to_i]
right = ENV['TM_CURRENT_LINE'][ENV['TM_LINE_INDEX'].to_i .. -1]
left.gsub!(/(\w+)(\W+)(\w+)(\W*)$/u, '\3\2\1\4')
print left + right
--------------------------------
More information about the textmate
mailing list