2

If I press shift in insert mode, I can select text using the arrow keys. I want to be able to do the same in normal mode. This is what I got so far:

(define-key evil-normal-state-map (kbd "S-<left>") (lambda () (interactive) (evil-visual-char) (backward-char)))
(define-key evil-normal-state-map (kbd "S-<right>") (lambda () (interactive) (evil-visual-char) (forward-char)))

It works well, except S-<left> behaves weirdly since pressing it continuously it also extends the selection on the right side, even though the key-binding is only set for the normal mode.

  • @Dan I've added what I got so far to my question. – Lenar Hoyt Dec 6 '15 at 22:09
2

By default, visual state inherits bindings from normal state, as long as they do not collide.

Therefore, this should (and does) work:

(define-key evil-normal-state-map (kbd "S-<left>")
  (lambda ()
    (interactive)
    (evil-visual-char)
    (backward-char)))
(define-key evil-normal-state-map (kbd "S-<right>") 
  (lambda ()
    (interactive)
    (evil-visual-char)
    (forward-char)))
(define-key evil-visual-state-map (kbd "S-<left>")
  #'backward-char)
(define-key evil-visual-state-map (kbd "S-<right>") 
  #'forward-char)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.