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
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)