alienbogart / cool-moves

Simple commands to move text around on Emacs
23 stars 0 forks source link

[[https://gfycat.com/ClassicUnevenEquestrian][See it in action]].

This is my first attempt at publishing code, so criticism is more than welcome!

+BEGIN_SRC emacs-lisp

(use-package cool-moves :load-path "~/.emacs.d/lisp/cool-moves" :config (general-define-key :keymaps 'override "" 'cool-moves/paragraph-forward "" '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))

+END_SRC

** Without use-package Remember to replace =~/.emacs.d/lisp/cool-moves=. The rest is straightforward.

+BEGIN_SRC emacs-lisp

(add-to-list 'load-path "~/.emacs.d/lisp/cool-moves") (load "cool-moves")

(general-define-key :keymaps 'override "" 'cool-moves/paragraph-forward "" '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)

+END_SRC

+BEGIN_SRC emacs-lisp

(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 "" 'cool-moves/paragraph-backward "" 'cool-moves/paragraph-forward)

+END_SRC

If you don't use General and don't know how to create keybindings, [[https://www.masteringemacs.org/article/mastering-key-bindings-emacs][this article]] might be helpful. ** Suggested Hydra You can use a [[https://github.com/abo-abo/hydra][Hydra]] to make the commands easily accessible.

+BEGIN_SRC emacs-lisp

(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 ←

"

("" 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))

+END_SRC