Skip to content

Instantly share code, notes, and snippets.

@troyp
Last active April 14, 2016 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyp/6b4c9e1c8670200c04c16036805773d8 to your computer and use it in GitHub Desktop.
Save troyp/6b4c9e1c8670200c04c16036805773d8 to your computer and use it in GitHub Desktop.
Vim-style keybinding in Emacs/Evil-mode.
(defun kbd+ (keyrep &optional need-vector)
(if (vectorp keyrep) keyrep (edmacro-parse-keys keyrep need-vector)))
(defun gmap (keyrep defstr)
"Vim-style global keybinding. Uses the `global-set-key' binding function."
(global-set-key (kbd+ keyrep) (edmacro-parse-keys defstr t)))
(defun fmap (keybind-fn keyrep defstr)
"Vim-style keybinding using the key binding function KEYBIND-FN."
(call keybind-fn (kbd+ keyrep) (edmacro-parse-keys defstr t)))
(defun xmap (keymap keyrep defstr)
"Vim-style keybinding in KEYMAP. Uses the `define-key' binding function."
(define-key keymap (kbd+ keyrep) (edmacro-parse-keys defstr t)))
(defun nmap (keyrep defstr) "Vim-style keybinding for `evil-normal-state'. Uses the `define-key' binding function."
(xmap evil-normal-state-map keyrep defstr))
(defun imap (keyrep defstr) "Vim-style keybinding for `evil-insert-state'. Uses the `define-key' binding function."
(xmap evil-insert-state-map keyrep defstr))
(defun vmap (keyrep defstr) "Vim-style keybinding for `evil-visual-state'. Uses the `define-key' binding function."
(xmap evil-visual-state-map keyrep defstr))
(defun mmap (keyrep defstr) "Vim-style keybinding for `evil-motion-state'. Uses the `define-key' binding function."
(xmap evil-motion-state-map keyrep defstr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment