Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I couldn't find any instructions on defining key sequences in the Evil doc.

The example given by the developers only covers a single key.

(define-key evil-normal-state "w" 'foo)

What do I need to do, if I want to define "gv" in the normal mode or ";RET" in the insert mode?

In Vim, for example, I just do:

imap ;<cr> <end>;<cr>
map gv :tabprev<cr>
share|improve this question
up vote 0 down vote accepted

The Evil wiki page suggests using elscreen.el to emulate Vim's tabs:

(load "elscreen" "ElScreen" t)

(define-key evil-normal-state-map (kbd "C-w t") 'elscreen-create) ;creat tab
(define-key evil-normal-state-map (kbd "C-w x") 'elscreen-kill) ;kill tab

(define-key evil-normal-state-map "gv" 'elscreen-previous) ;previous tab
(define-key evil-normal-state-map "gt" 'elscreen-next) ;next tab

Similarly you could define:

(define-key evil-insert-state-map (kbd "; <return>") 'move-end-of-line)

This emulates imap ;<cr> <end>;<cr>. If you press ; followed by Return then the cursor will jump to the end of the line and insert a semicolon. I would have liked to make it a little more generic, but I'm missing a key function.

(define-key evil-insert-state-map (kbd ";") 'insert-or-append)

(defun insert-or-append ()
  "If the user enters <return>, then jump to end of line and append a semicolon,
   otherwise insert user input at the position of the cursor"
  (let ((char-read (read-char-exclusive))
        (trigger ";"))
    (if (eql ?\r char-read)
          (insert trigger))
      (insert (this-command-keys)))))
share|improve this answer
(define-key evil-insert-state-map (kbd "; <return>") 'move-end-of-line) disables insertion of regular semicolon as Emacs expects another key and I see ;- in the minibuffer. I guess to fix it I need to use (read-event) in the command that is mapped to ";" instead of defining a key sequence, but I'm not sure how to use correctly. – Mark T. Aug 14 '12 at 9:33
@MarkT. You're right... I'll have to dig into the Emacs documentation to hack up a function that does what you want. – djf Aug 14 '12 at 18:17
This works perfectly. I'll sign up to upvote. Thank you. – Mark T. Aug 15 '12 at 4:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.