Michael
Michael

Reputation: 1963

Emacs Evil "repeat" (dot) behavior

I have the following line in my .emacs

(define-key evil-normal-state-map "\M-j" (lambda () (interactive) (evil-next-line 5)))

that makes navigation in a file easier. For instance, with M-j I go 5 lines below, so I don't have to press j 5 times. I do the same for all hjkl. The trouble is that this command pollutes the last repeat in Evil (the dot), so let's say I replace a word in a given line, then I do M-j to go change a word 5 lines below. If I press ., it will jump another 5 lines below, instead of replacing the word as it would happen in Vim. If I use any of hjkl though, it won't pollute the last repeat. How can I do so that my function doesn't pollute the last repeat?

EDIT: I just noticed that it doesn't actually happen with \M-j and \M-k, but only with \M-h and \M-l, so the problem is even stranger. Both are defined as:

(define-key evil-normal-state-map "\M-h" '(lambda () (interactive) (evil-backward-char 5)))

(define-key evil-normal-state-map "\M-l" '(lambda () (interactive) (evil-forward-char 5)))

Upvotes: 2

Views: 1927

Answers (1)

Just replace the lambda with a defun say: (defun my-5-lines-down...)and then (evil-declare-motion 'my-5-lines-down) In evil (and probably vim?) motions do not count as repeatables so this should do the trick. Alternatively you can use evil-define-motioninstead of defun if you want control over the jump list. See documentation for defining a motion.

Upvotes: 3

Related Questions