Table of Contents
- What It Does
- Differences from drag-stuff
What It Does
This is a package to move text around on Emacs. It uses basic functions to move words, lines, paragraphs, sentences and sexps forward and backward.
I’m an Evil user and write a lot of prose on Emacs. This package was inspired by this and this blog posts. It uses basic functions to move words, lines, paragraphs, sentences, and sexps both forward and backward. Being able to quickly reorganize my prose is extremely important for me.
This is my first attempt at publishing code, so criticism is more than welcome!
cool-motions.el somewhere in your Emacs path and replace
~/.emacs.d/lisp/cool-moves with the path to it. Here’s an example (the keybindings are optional):
(use-package cool-moves :load-path "~/.emacs.d/lisp/cool-moves" :config (general-define-key :keymaps 'override "<C-down>" 'cool-moves/paragraph-forward "<C-up>" 'cool-moves/paragraph-backward "C-S-j" 'cool-moves/line-forward "C-S-k" 'cool-moves/line-backward "C-M-n" 'cool-moves/word-forward "C-M-p" 'cool-moves/word-backwards))
Remember to replace
~/.emacs.d/lisp/cool-moves. The rest is
(add-to-list 'load-path "~/.emacs.d/lisp/cool-moves") (load "cool-moves") (general-define-key :keymaps 'override "<C-down>" 'cool-moves/paragraph-forward "<C-up>" 'cool-moves/paragraph-backward "C-S-j" 'cool-moves/line-forward "C-S-k" 'cool-moves/line-backward "C-M-n" 'cool-moves/word-forward "C-M-p" 'cool-moves/word-backwards)
Each of these commands move something either forward or backwards, and are named in predictable manner. This package have no default keybindings, but I’ll make some suggestions below.
Besides the keybindings there are no settings to be made.
I use general.el for my keybindings, so:
(general-define-key :keymaps 'override "C-S-j" 'cool-moves/line-forward "C-M-n" 'cool-moves/word-forward "C-S-k" 'cool-moves/line-backward "C-M-p" 'cool-moves/word-backwards "<C-up>" 'cool-moves/paragraph-backward "<C-down>" 'cool-moves/paragraph-forward)
If you don’t use General and don’t know how to create keybindings, this article might be helpful.
You can use a Hydra to make the commands easily accessible.
(defhydra hydra-text-motions (:color amaranth :hint nil :foreign-keys nil) " ^ ^Motions^ ------------------------- _l_: line ↓ _w_: word → _L_: line ↑ _W_: word ← _p_: par ↓ _c_: char → _P_: par ↑ _C_: char ← _s_: sentence → _x_: sexp → _S_: sentence ← _X_: sexp ← " ("<escape>" nil) ("u" nil) ("l" cool-moves/line-forward) ("L" cool-moves/line-backward) ("p" cool-moves/paragraph-forward) ("P" cool-moves/paragraph-backward) ("w" cool-moves/word-forward) ("W" cool-moves/word-backwards) ("c" cool-moves/character-forward) ("C" cool-moves/character-backward) ("s" cool-moves/sentence-forward) ("S" cool-moves/sentence-backward) ("x" cool-moves/sexp-forward) ("X" cool-moves/sexp-backward))
Differences from drag-stuff
drag-stuff is bigger, robuster and able to drag regions. Unlike cool-moves, it doesn’t move sentences or characters. When I try to use
drag-stuff-right on the first word of a line, it’s switched with the last word of the previous paragraph.
drag-stuff is clearly a good mode that does a lot with a single command, but in text editing predictability is a must and I don’t need the added complexity. I didn’t use any code from this package. My functions were largely inspired from the aforementioned blog post by Bozhidar Batsov.