This is part of the Emacs Starter Kit.
(define-key key-translation-map (kbd "s-3") (kbd "#")) ;;; For fix MACOS # symbol
(global-set-key [f1] 'menu-bar-mode)
(global-set-key [f2] 'cua-mode)
(require 'highlight-symbol)
(global-set-key [f3] 'highlight-symbol-next)
(global-set-key [(control f3)] 'highlight-symbol-at-point)
(global-set-key [(shift f3)] 'highlight-symbol-prev)
(global-set-key [(meta f3)] 'highlight-symbol-list-all)
(provide 'init-highlight-symbol)
(global-set-key [f4] 'bookmark-bmenu-list)
(global-set-key [(shift f4)] 'bookmark-set)
(global-set-key [(control f4)] 'bookmark-jump)
(global-set-key [(meta f4)] 'bs-show)
(global-set-key [f5] 'occur)
(global-set-key [f6] 'hs-toggle-hiding)
(global-set-key [(shift f6)] 'hs-show-all)
(global-set-key [(control f6)] 'hs-hide-all)
(global-set-key [f7] 'neotree-toggle)
(global-set-key [f8] 'ffip)
(global-set-key [(control f8)] 'projectile-ibuffer)
(global-set-key [(meta f8)] 'projectile-switch-project)
(global-set-key (kbd "C-x C-;") 'direx-project:jump-to-project-root)
(global-set-key (kbd "C-M-d") 'duplicate-line)
(global-set-key (kbd "C-l") 'copy-line-or-region)
(global-set-key (kbd "M-<delete>") 'delete-word)
(global-set-key (kbd "C-<delete>") 'backward-delete-word)
(global-set-key (kbd "C-d") 'backward-kill-word)
(global-set-key (kbd "C-S-w") (quote copy-word))
(global-set-key (kbd "C-'") 'ace-jump-mode)
(global-set-key (kbd "C-c e") 'er/expand-region)
(global-set-key "\C-c\C-m" 'helm-M-x)
;;;; these can be invoked vim-style
;;;; Esc-:<single_key_from_below>
;;(define-key evil-ex-map "b " 'helm-mini)
;;(define-key evil-ex-map "e" 'helm-find-files)
;;(define-key evil-ex-map "g" 'helm-projectile-grep)
;;(define-key evil-ex-map "f" 'helm-projectile-find-file)
;;(define-key evil-ex-map "g" 'helm-projectile-grep)
;;(define-key evil-ex-map "f" 'helm-projectile-find-file)
(global-set-key (kbd "C-x \\") 'align-regexp)
(global-set-key (kbd "M-/") 'hippie-expand)
(global-set-key (kbd "C-c n") 'cleanup-buffer)
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
(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 "C-x C-i") 'imenu)
(global-set-key (kbd "C-x C-y") 'helm-semantic-or-imenu)
(global-set-key (kbd "C-x M-f") 'ido-find-file-other-window)
(global-set-key (kbd "C-x C-M-f") 'find-file-in-project)
(global-set-key (kbd "C-x f") 'recentf-ido-find-file)
(global-set-key (kbd "C-x C-p") 'find-file-at-point)
(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)
C-x o
goes to the next window, Shift+direction arrow moves between frames.
(windmove-default-keybindings)
(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
(setq windmove-wrap-around t)
When your frame (i.e., the main Emacs window) is split into different parts (e.g. using C-x 2
or C-x 3
), you sometimes want to resize these parts dynamically. This defines Shift-C-[arrow keys]
so you can do this easily.
;; resizing 'windows' (i.e., inside the frame)
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)
When windows get out of order, you can rotate them.
(defun rotate-windows ()
"Rotate your windows" (interactive) (cond ((not (> (count-windows) 1)) (message "You can't rotate a single window!"))
(t
(setq i 1)
(setq numWindows (count-windows))
(while (< i numWindows)
(let* (
(w1 (elt (window-list) i))
(w2 (elt (window-list) (+ (% i numWindows) 1)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2))
)
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1)
(setq i (1+ i)))))))
(global-set-key (kbd "C-c m") 'rotate-windows)
(global-set-key (kbd "C-x ^") 'join-line)
Mark text between parentheses. From this Stackoverflow answer.
(defun backward-up-sexp (arg)
(interactive "p")
(let ((ppss (syntax-ppss)))
(cond ((elt ppss 3)
(goto-char (elt ppss 8))
(backward-up-sexp (1- arg)))
((backward-up-list arg)))))
(global-set-key [remap backward-up-list] 'backward-up-sexp)
(global-set-key (kbd "C-x m") 'eshell)
(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t)))
(global-set-key (kbd "C-x M-m") 'shell)
Smex replaces M-x, and is built on top of ido-mode. See http://github.com/nonsequitur/smex or http://www.emacswiki.org/emacs/Smex for details.
(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "C-x C-m") 'smex-major-mode-commands) ;; supersedes binding in starter-kit-bindings.org
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
(setq smex-show-unbound-commands t)
(smex-auto-update 30)
(global-set-key (kbd "C-x /") 'delete-horizontal-space)
(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))))))
Two global binding for Org-mode (see starter-kit-org)
(global-set-key (kbd "C-c l") 'org-store-lin)
(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c b") 'org-iswitchb)
(global-set-key (kbd "C-S-n")
(lambda () (interactive) (ignore-errors (next-line 5))))
(global-set-key (kbd "C-S-p")
(lambda () (interactive) (ignore-errors (previous-line 5))))
(global-set-key (kbd "C-S-f")
(lambda () (interactive) (ignore-errors (forward-char 5))))
(global-set-key (kbd "C-S-b")
(lambda () (interactive) (ignore-errors (backward-char 5))))
It’s to the point now where I almost can’t use git without magit.
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x G") 'magit-show-refs-popup)
magit-status
(global-set-key (kbd "C-h a") 'apropos)
Rgrep is infinitely useful in multi-file projects. (see elisp:(describe-function ‘rgrep))
(global-set-key (kbd "C-x C-r") 'rgrep)
Remember the previous window configurations and jump back to them as needed (as when, e.g., some other mode messes with your working layout.) Rebind the default keys to C-c-up and C-c-down as in a moment we’ll assign C-c-right for rotating windows.
(winner-mode 1)
(global-set-key (kbd "C-c <up>") 'winner-undo)
(global-set-key (kbd "C-c <down>") 'winner-redo)
By default C-z is bound to “Suspend Frame”, which minimizes Emacs. I find this of no use. Bind it to “Undo” instead.
;; I can't remember ever having meant to use C-z to suspend the frame
(global-set-key (kbd "C-z") 'undo)
Sometimes very useful (but we don’t use the core cua keys.)
(setq cua-enable-cua-keys nil)
(cua-mode)
(provide 'starter-kit-bindings)
(message "------ Starter Kit Binding loaded ------")