Transposition

Sacha Chua writes here about developing microhabits. It’s an article close to my heart, in fact, it’s the reason that I write the Emacs workout. Sacha’s article was inspired in turn by this tweet from Frederik Appelburg

Using transpose-chars is a litmus test. If you care enough to save keystrokes to internalize C-t, then you must be a power user.

I agree with Frederik: I use C-t all the time for that very reason (in fact I’ve written elsewhere that my litmus test is do you use M-c to capitalise words?).
But Frederik got me thinking about M-t. How often do I have to transpose a word?

Transpose two lines, yes, transpose a sentence. Well, when I’m editing stories, I do this a lot. But I rarely find myself transposing words.
Emacs has five built in transpose commands:

C-t transpose-chars Transpose the two letters.
M-t transpose-words Switch two words.
C-x C-t transpose-lines Switch two lines.
transpose-sentences Switch two sentences.
transpose-paragraphs Switch two paragraphs.

The trouble is, there is no key binding for the last two, the ones I’m most likely to use. Well, Emacs was made to be customised, it says so in the name. I could have added a couple of extra key bindings, but for various reasons I chose to use aliases, and so I added the following code to my .emacs file.

1 (defalias 'ts 'transpose-sentences)
2 (defalias 'tp 'transpose-paragraphs)

Now I just move the cursor between two sentences or paragraph, hit M-x ts or M-x tp and that’s it.

It’s such a simple customisation, and one I should have done years ago. But there you go: you have to work hard to be lazy.

1 Comment

  1. Xi says:

    Hi,
    Thanks for your article, I think I also need to make such a workout sheet too soon 🙂
    I find that it is challenging to embrace transportation features into my heart, each time the intuition is to modify the words by deleting and retyping, instead of using transportation, because the brain has to firstly decide whether the case can be done by transportation or not, especially for C-t cases.
    I will give it a try again, hopefully my brain will like it :).

    Like

Leave a Comment