Last active
April 14, 2016 21:40
-
-
Save troyp/6b4c9e1c8670200c04c16036805773d8 to your computer and use it in GitHub Desktop.
Vim-style keybinding in Emacs/Evil-mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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