3

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

4

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 ()
  (interactive)
  (evil-shift-right evil-visual-beginning evil-visual-end)
  (evil-normal-state)
  (evil-visual-restore))

(defun my/evil-shift-left ()
  (interactive)
  (evil-shift-left evil-visual-beginning evil-visual-end)
  (evil-normal-state)
  (evil-visual-restore))

(evil-define-key 'visual global-map (kbd ">") 'my/evil-shift-right)
(evil-define-key 'visual global-map (kbd "<") 'my/evil-shift-left)
1
  • 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 that you have read and understand our privacy policy and code of conduct.

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