Bozhidar Batsov is back with another great post on recent additions to Emacs, This time it’s about transposing things in Emacs. Most experienced Emacs users are familiar with transpose-chars and transpose-words. I’ve heard it suggested the that the use of these is mostly restricted to “power users” but I’ve been using them almost as long as I’ve been using Emacs. Perry Metzger made a comment on Irreal—I can’t find it now—extolling transpose-chars and how much more efficient it is than making the switch by hand.
I use those two commands all the time, usually several times a day. Batsov says that another useful transposition command is transpose-sentences but that few people discover it. I found it simply by assuming that it must exist and using Meta+x to find it. There’s also transpose lines, which I seldom use because it usually offers surprising results in visual-line-mode.
In addition to these commands there are some others. Take a look a Batsov’s post for more details. The point of his post is how much more useful some of these commands are when combined with Tree-sitter. The transpose-sexps command, which I always thought of as useful mostly for Lisp languages, gains a lot of power when Tree-sitter is brought to bear to define what “a balanced pair” means in whatever mode you’re using in the current buffer.
Finally, there is transpose-paragraphs. While I’ve never used it, it’s obviously useful for prose editing but gains new powers with Tree-sitter that can give a meaning to “paragraph” in the mode of the current buffer.
Every Emacs user should take a look at Batsov’s post. There’s a lot of good information in it.