Being evil with narrow-to-region-indirect
Emacs has a great vim emulation mode named evil-mode
. Of course it is also trivial to extend. Here is an example of defining a custom operator for by using evil-define-operator
:
(evil-define-operator evil-narrow-indirect (beg end type)
"Indirectly narrow the region from BEG to END."
(interactive "<R>")
(evil-normal-state)
(narrow-to-region-indirect beg end))
This macro is defining a procedure (evil-narrow-indirect
) that takes the beginning and end points of a region that the current evil-mode operator is acting upon. This makes it easy to integrate with a lot of existing Emacs methods. Here I used narrow-to-region-indirect
from another article here.
Now all that is left is to bind it to a key! I went with "m"
:
(define-key evil-normal-state-map "m" 'evil-narrow-indirect)
(define-key evil-visual-state-map "m" 'evil-narrow-indirect)
Eval these, and you have everything in place to say "mit"
or "mi}"
, etc.