Toby's Emacs Keybindings


Emacs Commands

Key-Chord Command
C-x b Switch to another buffer
C-x C-f Open a new file
C-x f Search project for file
C-v Page down
M-v Page up
TAB Indent current line
C-k “Kill” from point to EOL
C-y “Yank” (paste) last Kill
C-w Kill current Region
C-SPC Set the “Mark” (One end of a Region)
F5 Save open buffers
C-g Abort command
M-x Search commands by name


Keystroke Command
C-x d Open Dired
C-x d <REGEX> Open Dired filterd by REGEX
( Toggle details
A Search marked file
B Byte-compile elisp files
D Delete marked files
L Load elisp files
Q Query Replace in marked entries
R Rename
T Touch marked files
X Shell Command on files
Z Compress marked files
^ Go up a directory
< Previous Dir (in this buffer)
> Next Dir
c Copy marked files
g Read all dirs aGain
i Insert subdirectory into this listing
C-u u Un-insert
m Mark an entry
s Symlink marked files
t Toggle marks
u Unmark file
U Unmark all files
: d Decrypt
: e Encrypt

Also great is the wdired command, which creates a dired listing that can be edited and saved. This makes for easy renames and file mode changes.


Key-Chord Command
C-x r w Save current window lay-out to a register
C-x r j Restore windows from register


(global-set-key (kbd "C-s")   'isearch-forward-regexp)
(global-set-key (kbd "C-r")   'isearch-backward-regexp)
(global-set-key (kbd "C-M-s") 'isearch-forward)
(global-set-key (kbd "C-M-r") 'isearch-backward)
(global-set-key (kbd "M-%")   'query-replace-regexp)

(global-set-key [(meta shift a)]       'ack)
(global-set-key [(meta super shift a)] 'ack-same)

Activate occur easily inside isearch:

(define-key isearch-mode-map (kbd "C-o")
  (lambda () (interactive)
    (let ((case-fold-search isearch-case-fold-search))
      (occur (if isearch-regexp isearch-string (regexp-quote isearch-string))))))


(global-set-key (kbd "C-c j") 'flyspell-check-previous-highlighted-word)
(global-set-key (kbd "s-s") 'ispell-word)



(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "M-z") 'zap-to-char)
(global-unset-key (kbd "M-SPC"))

(require-package 'avy)
(global-set-key (kbd "M-SPC")   'avy-goto-word-1)
(global-set-key (kbd "C-c SPC") 'avy-goto-word-1)

Frame/Window Properties

(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
(define-key global-map (kbd "C-=") 'text-scale-set)
(global-set-key (kbd "C-s-f")     'ns-toggle-fullscreen)

File and Buffer Switching

Commands to switch buffers:

(global-set-key (kbd "C-x C-i") 'ido-imenu)

(global-set-key (kbd "C-x M-f")   'ido-find-file-other-window)
(global-set-key (kbd "C-c y")     'bury-buffer)
(global-set-key (kbd "C-c r")     'revert-buffer)
(global-set-key (kbd "M-`")       'file-cache-minibuffer-complete)
(global-set-key (kbd "C-x C-b")   'ibuffer)

Commands to switch windows:

(windmove-default-keybindings) ;; Shift+direction
(global-set-key (kbd "C-x O")
                (lambda () (interactive) (other-window -1))) ;; back one
(global-set-key (kbd "C-x C-o")
                (lambda () (interactive) (other-window  2))) ;; forward two

(global-set-key (kbd "M-s-<left>")  'windmove-left)
(global-set-key (kbd "M-s-<right>") 'windmove-right)
(global-set-key (kbd "s-<left>")    'windmove-left)
(global-set-key (kbd "s-<right>")   'windmove-right)
(global-set-key (kbd "s-<down>")    'windmove-down)
(global-set-key (kbd "s-<up>")      'windmove-up)

The ace-window package will display numbers in the various open windows, if there are more than two. This can make things a bit easier to navigate when you have your screen split up into a bunch of different panes.


(require-package 'avy)
(require-package 'ace-window)
(global-set-key (kbd "C-x o") 'ace-window)
(global-set-key (kbd "M-p")   'ace-window)

(setq aw-keys '(?a ?o ?e ?u ?i  ?d ?h ?t ?n ?s))

For those occassions when you want the old window switching behavior:

(global-unset-key (kbd "<f3>"))
(global-set-key (kbd "<f3>") 'kmacro-start-macro-or-insert-counter)

On keyboards that have extra function keys, some handy short-cuts:

(global-set-key (kbd "<f14>") 'ace-window)
(global-set-key (kbd "<f17>") 'ace-window)

On larger screens, I like to divide me frame into thirds:

(defun split-in-thirds ()
  "Split the window vertically into three segments."

(global-set-key (kbd "C-x 6") 'split-in-thirds)

Getting Help

Prefer full apropos search over the default apropos-command:

(global-set-key (kbd "C-h a") 'apropos)

Keyboard and Mouse Set-up

  • State "ADOPTED" from [2017-09-22 Fri 09:23]
  • State "EXPERIMENTAL" from [2017-09-22 Fri 09:14]

Bind Mac modifier keys:

 ns-command-modifier   'meta        ; Apple/Command key is Meta
 ns-alternate-modifier 'super       ; Option is the Mac Option key
 ns-function-modifier  'hyper       ; 'super or 'hyper
 ns-pop-up-frames       nil

Make `super` + x the same as Meta-x:

(global-set-key (kbd "s-x") 'smex)

Mouse scrolling needs to calm down:

(setq mouse-wheel-scroll-amount '(1))
(setq mouse-wheel-progressive-speed nil)

Adjust the echo threshold for key-chords:

(setq echo-keystrokes 0.02)

Terminal Mode Affordances

Attempt to accomodate modifiers to arrow keys in the terminal:

(define-key input-decode-map "\e[1;5A" [C-up])
(define-key input-decode-map "\e[1;5B" [C-down])
(define-key input-decode-map "\e[1;5C" [C-right])
(define-key input-decode-map "\e[1;5D" [C-left])

(define-key function-key-map "\M-[ a"  [C-up])
(define-key function-key-map "\M-[ b"  [C-down])
(define-key function-key-map "\M-[ c"  [C-right])
(define-key function-key-map "\M-[ d"  [C-left])
(provide 'keybindings)

Author: Toby Tripp

Created: 2018-03-04 Sun 00:38