Search code examples
vimemacskey-bindings

Emacs: key bindings with sequences of normal keys


What's the Emacs's equivalent of Vim's imap ab c? (input-a, then input-b results in output-c)


Solution

  • The simplest way to set keys in Emacs is with global-set-key, but that's glossing over some of the details; see Xah Lee's tutorial on defining keys for more.

    Since you're coming from Vim, however, take a look at evil-mode, which is a really nice Vim emulation layer for Emacs.

    Using evil, you could bind a key (or series of them) in, say, insert or normal state with:

    (define-key evil-insert-state-map "a"  'some-command)
    (define-key evil-normal-state-map "bc" 'some-other-command)
    

    You can also do mode-specific keybindings pretty easily. So, for example, to have a binding affect insert or normal state only in LaTeX mode, you can say:

    (evil-define-key 'insert LaTeX-mode-map "d"   'another-command)
    (evil-define-key 'normal LaTeX-mode-map "efg" 'yet-another-command)