I'm using emacs with evil key-bindings and I'd like to know, after getting some text into visual mode, how do you make sure that after hitting >> for indenting the text, the selection is kept, such that you can re-indent it again, or do something else with the entire selection?

1 Answer 1


After using < or > to indent a selection in visual mode, you can use gv to restore the previous selection and do some other action. If you wish to selection to be restored automatically, you can create your own functions for that and rebind your keys, like this:

(defun my/evil-shift-right ()
  (evil-shift-right evil-visual-beginning evil-visual-end)

(defun my/evil-shift-left ()
  (evil-shift-left evil-visual-beginning evil-visual-end)

(evil-define-key 'visual global-map (kbd ">") 'my/evil-shift-right)
(evil-define-key 'visual global-map (kbd "<") 'my/evil-shift-left)
  • this is perfect! Thank you so much. Mar 1, 2021 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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