Howard Abrams has a nice video on transposing words in Emacs. You might think that there’s not much to say about the subject: just type 【Meta+t】 and you’re done. Of course there’s also the fact that you can use it to “pull” a word towards the end of the line by repeated invocation of the command or by using a prefix number but that’s also well known.
Abrams explores an interesting edge case. What if you’re at the end of the line? He’s got an actual use for that. Suppose you’re typing along and realize you forgot a word
The brown fox
Rather than backing up and inserting the missing word, you can just type it at the end
The brown fox quick
and then type 【Meta+t Meta+t】 and quick
gets inserted in the proper place.
That’s a nice trick that takes advantage of a side effect of transpose-words
and you can use it as is. But Abrams shows how to advise transpose-words
so that it handles this case with a single invocation. That means you just type 【Meta+t】 as usual and Emacs does the right thing.
The video is only 8 minutes so you can watch it whenever you have a few minutes. Very nice. Even if you don’t add the advise, it’s worth knowing the trick.