When in evil-mode, I can make the cursor go down 3 lines by command 'C-u 3 M-x evil-next-line' , but how can I make the cursor go down 3 lines by just pressing J?
1 Answers
1. Short answer
Add this to your .emacs
file:
(evil-define-motion evil-next-line-3 (count)
"Move the cursor 3 * COUNT lines down."
:type line
(let (line-move-visual)
(evil-line-move (* 3 (or count 1)))))
Note that J
is currently bound to evil-join
.
If you are ok to rebind it, just add:
(define-key evil-normal-state-map "J" 'evil-next-line-3)
Now, to join lines, you may either type M-x
evil-join
RET
or bind something else to evil-join
(see below).
Note that, if you type 2J
, you'll move twice 3 lines down, which is more or less 6 lines down... and C-u
J
will move 4*3 = 12 lines down.
2. Not so short answer (what I actually did)
I never used evil-mode
... so I tried to add this package and enabled the evil-mode
(which is ok for me since I know the main vi
commands and I know how to disable it with C--
M-x
evil-mode
RET
).
When evil-mode
is enabled and I type C-h
k
J
, the Help buffer says:
J runs the command evil-join (found in evil-normal-state-map),
which is an interactive compiled Lisp function in ‘evil-commands.el’.
It is bound to J.
(evil-join BEG END)
Join the selected lines.
Then I typed C-h
k
j
, clicked the evil-commands.el
link from the Help buffer and copied and adapted the definition of the evil-next-line
function to the evil-next-line-3
function and bound it to J
.
In case you want to go back to the previous binding of J
(or want to bind it to something else), you can evaluate something like:
(define-key evil-normal-state-map "J" 'evil-join)

- 848
- 6
- 14