3

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)
(package-initialize)

(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!

3

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
  (evil-normal-state))

(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 Jan 24 '17 at 17:29
  • @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 Jan 24 '17 at 17:31
  • @meh: as an aside, C-[ also sends the escape sequence. – Dan Jan 24 '17 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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