0

I'm using emacs with evil key-bindings and I 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?

0

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)

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.