Stuff I’m now deleting from my configuration that others might find useful. GNU GPL v3 with exception of the AHK script at the end; please attribute to me and let me know if it was useful.
Some nice maps for editing lisp.
(define-key evil-window-map (kbd "u") 'winner-undo)
(evil-define-key 'normal emacs-lisp-mode-map (kbd ")") 'paredit-forward-up)
(evil-define-key 'normal emacs-lisp-mode-map (kbd "(") 'paredit-backward-up)
;; these two are better outside of evil leader map because
;; often want to type them more than once
(evil-define-key 'normal emacs-lisp-mode-map (kbd "H") 'paredit-forward-barf-sexp)
(evil-define-key 'normal emacs-lisp-mode-map (kbd "L") 'paredit-forward-slurp-sexp)
;; something I often find myself wanting to do
(evil-define-key 'normal emacs-lisp-mode-map (kbd "o") 'spw/evil-lisp-open-below)
(defun spw/evil-lisp-open-below ()
(interactive)
;; don't do it if we're in a comment, or the only thing before us on
;; this line is blank space, and if we're right at the beginning of
;; an sexp move forward one first
(if (looking-at "(") (forward-char 1))
(if (or (evil-in-comment-p)
(looking-back "^[:blank:]*"))
(call-interactively 'evil-open-below)
(paredit-forward-up)
(new-line-dwim)))
Use escape to get out of as much stuff as possible.
;; escape quits
(bind-key "<escape>" 'isearch-cancel isearch-mode-map)
(define-key minibuffer-local-map (kbd "ESC") 'abort-recursive-edit)
(define-key minibuffer-local-ns-map (kbd "ESC") 'abort-recursive-edit)
(define-key minibuffer-local-completion-map (kbd "ESC") 'abort-recursive-edit)
(define-key minibuffer-local-must-match-map (kbd "ESC") 'abort-recursive-edit)
(define-key minibuffer-local-isearch-map (kbd "ESC") 'abort-recursive-edit)
(bind-key "<escape>" 'helm-keyboard-quit helm-map)
(bind-key "<escape>" 'helm-keyboard-quit helm-comp-read-map)
Hacks to evil-god-state so it can be used in things like the Org-mode agenda. Didn’t make it into upstream, for good reason.
;; god-mode doesn't work well in special-mode buffers such as
;; the Org agenda. These buffers bind functions
;; other than `self-insert-command` to letter and number
;; keys, and god-local-mode intercepts key presses by
;; remapping `self-insert-command` to its own function.
;; So it fails to get a grip in special-mode buffers.
;; This is okay when one isn't using Evil
;; because in such modes bindings aren't generally
;; prefixed with C- and M-: there's little reason to use god-mode.
;; However, I want to use evil-god-state from the Emacs
;; state in Org agenda buffers. So manually remap all the keys.
(let ((map god-local-mode-map)
(keys '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k"
"l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v"
"w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G"
"H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R"
"S" "T" "U" "V" "W" "X" "Y" "Z" "0" "1" "2"
"3" "4" "5" "6" "7" "8" "9" "0")))
(dolist (key keys)
(define-key map (kbd key) 'god-mode-self-insert)))
(define-key god-local-mode-map (kbd ",") (lambda ()
(interactive)
(setq last-repeatable-command evil-god-last-command)
(repeat 1)))
(defadvice evil-execute-in-god-state
(before evil-execute-in-god-state-from-visual-state activate)
"When in visual state, get out of visual state
and restore the selection before firing up god-mode. This avoids
visual state bindings conflicting with god-mode"
(when (evil-visual-state-p)
(if (< (point) (mark))
(exchange-point-and-mark))
(forward-char 1)
(evil-exit-visual-state)
(let ((activate-mark-hook nil)) ; stop visual mode from firing
(activate-mark))))
Some text objects for Org-mode. As TODOs indicate, not quite finished.
;; TODO: make the following work well with counts i.e. selecting more than one subtree or list item
;; TODO: item text objects should not include subitems
(evil-define-text-object evil-org-outer-subtree (count &optional beg end type)
"An Org subtree. Uses code from `org-mark-subtree`"
:type line
(save-excursion
;; get to the top of the tree
(org-with-limited-levels
(cond ((org-at-heading-p) (beginning-of-line))
((org-before-first-heading-p) (user-error "Not in a subtree"))
(t (outline-previous-visible-heading 1))))
(decf count)
(when count (while (and (> count 0) (org-up-heading-safe)) (decf count)))
;; extract the beginning and end of the tree
(let ((element (org-element-at-point)))
(list (org-element-property :end element)
(org-element-property :begin element)))))
(evil-define-text-object evil-org-inner-subtree (count &optional beg end type)
"An Org subtree, minus its header and concluding line break. Uses code from `org-mark-subtree`"
:type line
(save-excursion
;; get to the top of the tree
(org-with-limited-levels
(cond ((org-at-heading-p) (beginning-of-line))
((org-before-first-heading-p) (user-error "Not in a subtree"))
(t (outline-previous-visible-heading 1))))
(decf count)
(when count (while (and (> count 0) (org-up-heading-safe)) (decf count)))
;; extract the beginning and end of the tree
(let* ((element (org-element-at-point))
(begin (save-excursion
(goto-char (org-element-property :begin element))
(next-line)
(point)))
(end (save-excursion
(goto-char (org-element-property :end element))
(backward-char 1)
(point))))
(list end begin))))
;;; text object bindings
(define-key evil-outer-text-objects-map "*" 'evil-org-outer-subtree)
(define-key evil-inner-text-objects-map "*" 'evil-org-inner-subtree)
(define-key evil-inner-text-objects-map "-" 'evil-org-inner-item)
(define-key evil-outer-text-objects-map "-" 'evil-org-outer-item)
(evil-define-text-object evil-org-outer-item (count &optional beg end type)
:type line
(let* ((regionp (org-region-active-p))
(struct (progn
(re-search-backward "^<span class="createlink"><a href="/cgi-bin/ikiwiki.cgi?do=create&from=blog%2Fentry%2Feviltricks&page=%3Aspace%3A" rel="nofollow">?</a>:space:</span>*- ")
(org-list-struct)))
(begin (org-list-get-item-begin))
(end (org-list-get-item-end (point-at-bol) struct)))
(if (or (not begin) (not end))
nil
(list begin end))))
(evil-define-text-object evil-org-inner-item (count &optional beg end type)
(let* ((regionp (org-region-active-p))
(struct (progn
(re-search-backward "^<span class="createlink"><a href="/cgi-bin/ikiwiki.cgi?do=create&from=blog%2Fentry%2Feviltricks&page=%3Aspace%3A" rel="nofollow">?</a>:space:</span>*- ")
(org-list-struct)))
(begin (progn (goto-char (org-list-get-item-begin))
(forward-char 2)
(point)))
(end (org-list-get-item-end-before-blank (point-at-bol) struct)))
(if (or (not begin) (not end))
nil
(list begin end))))
(defun evil-org-meta-return (arg)
(interactive "P")
(let ((org-M-RET-may-split-line nil))
(if (org-table-p)
(org-table-insert-row 4)
(org-end-of-line)
(if arg (org-insert-heading-respect-content) (org-meta-return)))
(evil-insert-state 1)))
(defun evil-org-backwards-meta-return (arg)
(interactive "P")
(let ((org-M-RET-may-split-line nil))
(if (org-table-p)
(call-interactively 'org-open-line)
(beginning-of-line)
(if arg (org-insert-heading-respect-content) (org-meta-return)))
(evil-insert-state 1)))
(evil-define-key 'normal org-mode-map "go" 'evil-org-meta-return)
(evil-define-key 'normal org-mode-map "gO" 'evil-org-backwards-meta-return)
(add-hook 'org-mode-hook (lambda ()
(setq-local evil-cross-lines t)))
More bindings for Org-mode. I prefer these to evil-org.el
’s.
(dolist (state '(normal visual))
(evil-define-key state org-mode-map (kbd "M-j") 'org-metadown)
(evil-define-key state org-mode-map (kbd "M-k") 'org-metaup)
(evil-define-key state org-mode-map (kbd "<") 'org-metaleft)
(evil-define-key state org-mode-map (kbd ">") 'org-metaright)
(evil-define-key state org-mode-map (kbd "M-h") 'org-metaleft)
(evil-define-key state org-mode-map (kbd "M-l") 'org-metaright)
(evil-define-key state org-mode-map (kbd "M-J") 'org-shiftmetadown)
(evil-define-key state org-mode-map (kbd "M-K") 'org-shiftmetaup)
(evil-define-key state org-mode-map (kbd "M-H") 'org-shiftmetaleft)
(evil-define-key state org-mode-map (kbd "M-L") 'org-shiftmetaright)
(evil-define-key state org-mode-map (kbd "^") 'org-beginning-of-line)
(evil-define-key state org-mode-map (kbd "$") 'org-end-of-line))
(evil-define-key 'normal org-mode-map (kbd "<tab>") 'org-cycle)
(bind-key "J" 'org-agenda-goto-date org-agenda-mode-map)
(bind-key "j" 'evil-next-line org-agenda-mode-map)
(bind-key "k" 'evil-previous-line org-agenda-mode-map)
;;; evil surround pairs
(defun evil-surround-org-pairs ()
(push '(?= . ("=" . "=")) evil-surround-pairs-alist)
(push '(?~ . ("~" . "~")) evil-surround-pairs-alist))
(add-hook 'org-mode-hook 'evil-surround-org-pairs)
;;; get out of editing a source block
(add-hook 'org-src-mode-map (lambda () (evil-local-set-key 'normal (kbd "Z Z") 'org-edit-src-exit)))
Finally here’s an AutoHotkey script which was the best way to make caps
lock escape when tapped and control when held on Windows. Check out
xcape
to do the same on a UNIX system.
; caps lock is both control and escape
; Author: fwompner gmail com
#InstallKeybdHook
SetCapsLockState, alwaysoff
Capslock::
SetCapsLockState, alwaysoff
Send {LControl Down}
KeyWait, CapsLock
Send {LControl Up}
if ( A_PriorKey = "CapsLock" )
{
Send {Esc}
}
return