In evil insert state, I can mark a region in the buffer using the mouse. If I now press the Delete key (bound to the delete-char
command) it deletes the character at the current cursor position and not the the marked region. This behavior is different from how the delete key works in normal Emacs mode where the region is killed. How can I make evil insert mode work the same way?
1 Answer
If I understand correctly, you're asking about the behavior of
DELETE when the region is active, or, as far as evil
is concerned, when you're in evil
's visual
state. It should
be enough to rebind the key in that map:
(define-key evil-visual-state-map [delete] #'delete-region)
Update: as @HakonHaegland's comment indicates, it's not exactly clear what's going on with the different states. However, using the following keybinding seems to resolve the issue:
(define-key evil-insert-state-map [delete] #'evil-delete-char)
-
Actually, I am quite convinced that I am in
evil
'sinsert
state. Invisual
state I usually used
to delete the region. Also, if the region is not active, I would like to have the normaldelete-char
to be called, sodelete-region
will not work correctly if there is no marked region. I tried to replace yourdelete-region
withevil-delete-char
and it seems to work fine. Jul 26, 2016 at 17:08 -
@HåkonHægland: I might be misunderstanding, but I think the region is always active in
visual
state. You can check by marking the region with your mouse as you described, thenM-: (use-region-p)
to check if the region is active. You can also doM-: evil-state
to determine which state you're in.– Dan ♦Jul 27, 2016 at 2:41 -
Thanks. If I try
M-: evil-state
it saysinsert
. So it is as expected. Jul 27, 2016 at 6:40 -
@HåkonHægland: sorry, do you mean updating it about the
evil-delete-char
function that you tried?– Dan ♦Jul 27, 2016 at 14:43 -
@HåkonHægland: done! Still can't figure out what's going on with the different states, but I'm glad you got it working.– Dan ♦Jul 27, 2016 at 14:49