Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.