This list of call-interactively
actually represents a very simple Vim macro: vk=o
(define-key evil-normal-state-map (kbd "SPC dg")
(lambda ()
(interactive)
(call-interactively 'evil-visual-char)
(call-interactively 'evil-previous-line)
(call-interactively 'indent-region)
(call-interactively 'evil-open-below)))
Question
Is there a simple way to execute vim commands inside elisp?
Notes
I have found that you can bind vim macros to keyboard shortcuts using global-set-key
.
Something like this: (global-set-key (kbd "C-c C-l") "vk=o")
But trying to see how global-set-key was doing it, it lead me to compiled C code from define-key
which didn't help much.
I am looking to write something perhaps alike:
(define-key evil-normal-state-map (kbd "SPC dg")
(lambda ()
(interactive)
;; some code
(eval-vim-macro "vk=o")))
Thanks for the help!
TLDR: I ended up using evil-ex-execute
.
Stumbled upon this question looking for the same thing. Hope my findings help future travelers.
What I did to find this out was:
C-h k :
, which directed me towards the evil-ex
in evil-ex.el
file.evil-ex.el
file to find out the function that seemed to make sense.evil-ex-execute
to find that this is exactly what I need.Singing praises to Emacs introspection capabilities!