5

I really appreciate the undo in region command in standard emacs, where you can just mark a region and only changes made in that region are undone.

This doesn't seem to work in the default spacemacs configuration.

Is there a way to activate this?

tom4everitt
  • 173
  • 4

3 Answers3

3

(define-key evil-visual-state-map (kbd "u") 'undo)

It will bind u to Emacs undo command in evil visual state (aka when you select region).

xged
  • 151
  • 4
1

You can select the region and do, either: SPC SPC undo or C-_ that is Control-shift--key

or even better, you can create your own keymap under SPC o that's reserved for user keybindings, and create SPC o u for undo:

(spacemacs/declare-prefix "o" "personal")

;; File bindings
(spacemacs/set-leader-keys
  "ou" 'undo)
  • Thanks. The `C-_` command works, but the marked region extends after the first time I press it (weird, but not the end of the world). `SPC SPC undo` doesn't do this, oddly enough. – tom4everitt Apr 24 '17 at 00:22
  • 1
    Also, it seems like a shorter undo history is kept then before. If I edit a region, then do an undo and redo somewhere else, the undo-history for the original region seems to be lost. – tom4everitt Apr 24 '17 at 00:30
  • Actually, I can't reliably reproduce it now. Never mind. I'll post a new question if I manage to. – tom4everitt Apr 24 '17 at 00:42
1

As of July 15, 2022, there exists a flag to enable undo-region with vim style key bindings in the Spacemacs develop -- which also happens to currently be the default, rolling release -- branch. Users can edit the .spacemacs file to include the following,

 (setq-default dotspacemacs-configuration-layers
                '((spacemacs-editing :variables
                                     vim-style-enable-undo-region t)))

For the related git pull request, see https://github.com/syl20bnr/spacemacs/pull/15631

  • What does *"5 years later"* mean? Could you please provide some info that identifies the particular *version* of Spacemacs (or whatever) that provides this? Presumably the link you show provides that info somewhere, but it really belongs in the answer text as well, to be most helpful. Thx. – Drew Jul 17 '22 at 20:38
  • 1
    I hate link rot as much as the next guy, answer updated. Appreciate the moderation towards high quality content. – TheWoodenPrince Jul 19 '22 at 02:33