HOME

Toby's Emacs Keybindings

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

Dired

Keystroke Command
C-x d Open Dired
C-x d <REGEX> Open Dired filterd by REGEX
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.

Registers

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

Searching/Replacing

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

Spelling

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

Navigation

(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 'ace-jump-mode)
(autoload 'ace-jump-mode "ace-jump-mode")
(global-set-key (kbd "M-SPC") 'ace-jump-mode)
(global-set-key (kbd "C-c SPC") 'ace-jump-mode)

Frame/Window Properties

(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
(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

The switch-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 'switch-window)
(global-set-key (kbd "C-x o")   'switch-window)

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

(global-unset-key (kbd "<f3>"))
(global-set-key (kbd "<f3>") 'other-window)

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

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

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

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

(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

Bind Mac modifier keys:

(setq
 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: 2015-02-04 Wed 10:55

Emacs 24.3.1 (Org mode 8.2.10)

Validate