I'm a vim user moving to emacs evil.

I just added this line to my .init.el file and it broke my dot functionality.

(define-key evil-insert-state-map (kbd "TAB") 'evil-force-normal-state)

Why? I'm not even sure what to search for to start debugging this.

Here's my whole init.el file:

(require 'package)

(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))

(setq package-enable-at-startup nil)

(global-linum-mode 1)

(require 'evil)
(evil-mode t)

;;;; Keymappings                                                                  
(with-eval-after-load 'evil-maps
  (define-key evil-motion-state-map (kbd ":") 'evil-repeat-find-char)
  (define-key evil-motion-state-map (kbd ";") 'evil-ex))
  (define-key evil-insert-state-map (kbd "TAB") 'evil-force-normal-state)) 

If I don't comment out that line, the . in normal mode just deletes the current line as if I'm doing a dd. I tried adding stuff to the end of a line then repeating it on a few lines with .. All I got was fewer lines!

1 Answer 1


Short version

Switch your code to:

(define-key evil-insert-state-map (kbd "TAB") 'evil-normal-state)

Explanatory version

I presume that you're trying to use the TAB key as a substitute for the ESC key because the latter is harder to reach.

As an editorial aside, let me suggest you try remapping the ESC key to the CAPS LOCK key at the system level, as many Emacs packages use TAB for core functionality.

Back to the narrow issue. In insert state, ESC is bound by default to evil-normal-state, not evil-force-normal-state (which is its binding in normal state). That's an important point because the latter aborts the repeater. Here's the code that shows you:

(evil-define-command evil-force-normal-state ()
  "Switch to normal state without recording current command."
  :repeat abort             ;; here's the culprit
  :suppress-operator t

(NB: you can check out the source code with C-h f evil-force-normal-state and follow the links.)

  • Thanks @Dan! This is very helpful. Trouble is I already have CAPS LOCK working as my CTRL key... Looks to me like I'll have to get used to a different way. Thanks for pointing that out.
    – meh
    Commented Jan 24, 2017 at 17:29
  • 1
    @meh: if you're on Linux, you can use xcape to have CAPS LOCK act as ESC when tapped and released, and as CTRL when held down. Karabinder used to provide this option for OSX, but recent releases of the latter have apparently gummed up the works.
    – Dan
    Commented Jan 24, 2017 at 17:31
  • @meh: as an aside, C-[ also sends the escape sequence.
    – Dan
    Commented Jan 24, 2017 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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