Quickly transpose sentences and paragraphs using key bindings in Emacs
Emacs has several fantastic functions that offer you superpowers when it comes to text editing.
Not all of these functions come with default key bindings.
To make editing prose more efficient, I added a few key bindings for transposing sentences and paragraphs.
Transpose sentences
The Emacs function transpose-sentences works great and is very useful when editing prose. By default it has no key bound to it.
First we need to make sure Emacs understands that sentences ends with a single space:
(setopt sentence-end-double-space nil)
In a brilliant post Sandra explains that in Emacs, key bindings can be different for lowercase and for uppercase chars.
We can utilize this method to construct an easy-to-remember key
binding for transpose-sentences
:
(global-set-key (kbd "C-S-t") #'transpose-chars)
(global-set-key (kbd "C-t") #'transpose-sentences)
The default key binding for transpose-chars
is C-t
.
I don't use that function very often, this config moves that to
C-S-t
, making room for binding transpose-sentences to
C-t
.
If you frequently use the transpose-chars
function, it is
perhaps better to turn the two around, C-t
to transpose chars,
and C-S-t
to transpose sentences.
Transpose paragraphs
Unfortunately, we can't use this method to load M-t and M-S-t with different key bindings.
Looking for a key binding that may be used within and outside org
mode, I came to C-c M-t
:
(global-set-key (kbd "C-c M-t") #'transpose-paragraphs)
(define-key org-mode-map (kbd "C-c M-t") #'transpose-paragraphs)
It is a little awkward to type C-c M-t
, but it nevertheless
works faster than M-x transpose-paragraphs
.
Made with ♥ by a human — no cookies, no trackers.
Proud member of the 250kb.club,
the no-JS.club,
the Blogroll.Club,
and the Bukmark.Club.
Don’t let a billionaire’s algorithm control what you read — use an RSS feed reader.
Most recent pages All tags Sitemap RSS of Gophersite