Skip to main content
12 votes
Accepted

Remove unsaved text in Emacs

Use M-x revert-buffer. A buffer only visits a file. The revert-buffer function reloads the current buffer's source file from disk. So long as the file hasn't changed since you last saved it, as ...
Lorem Ipsum's user avatar
  • 4,527
10 votes
Accepted

How to make interactive functions (simply) undoable?

I recommend you do C-h f replace-string RET and read it: [...] This function is for interactive use only; in Lisp code use `search-forward' and `replace-match' instead. [...] So, as suggested ...
Stefan's user avatar
  • 26.5k
8 votes

Possible not to use undo-tree in evil mode?

The author of undo-tree.el, Toby Cubitt, is presently too busy to fix this particular bug. If he has time in the future, he may look into the issue further. The author has indicated that he has ...
lawlist's user avatar
  • 19.2k
8 votes
Accepted

How can I prevent undo after redo?

The reason Emacs "starts to undo after all of the possible redos are done" is that, after you interrupted the original undo sequence with C-g, every change you had made up until that point ...
Pablo's user avatar
  • 320
7 votes
Accepted

How to assign the undo command to the Ctrl-z key binding?

Turns out that it seems to be related to me still having a (cua-mode t) line in my ~/.emacs file. After I removed this line, the line: (global-set-key (kbd "C-z") 'undo) in my ~/.emacs file worked ...
Josh Pinto's user avatar
7 votes
Accepted

how can I get Emacs kill-ring to behave like a simple clipboard buffer?

From the various comments so far, it sounds like you are in the process of learning about Emacs (welcome!). There are many things in Emacs that are unlike other editors, and as you go through the ...
glucas's user avatar
  • 20.6k
7 votes
Accepted

fine-grained undo

I like to do two things with undo. I turn off the amalgamation stuff (which by doing so permits undo one keystroke at at time); and, I get rid of the timer (because timers affect performance and ...
lawlist's user avatar
  • 19.2k
6 votes
Accepted

Check if current user undoing/redoing?

C-hv undo-in-progress Documentation: Non-nil while performing an undo. Some change-hooks test this variable to do something different. Bearing in mind that "redoing" is really still "undoing" in ...
phils's user avatar
  • 51.7k
6 votes

how can I get Emacs kill-ring to behave like a simple clipboard buffer?

I want to simplify the kill-ring so that it behaves like a simple clipboard. I find it complex that the kill-ring contains multiple items. You can completely ignore the fact that the kill ring ...
phils's user avatar
  • 51.7k
5 votes
Accepted

How to collapse undo history?

Edit: emacs-29.1 adds a with-undo-amagamate macro see commit. Here is an with-undo-amalgamate macro that uses Emacs-26 change-groups feature. This is atomic-change-group with the following changes: ...
ideasman42's user avatar
  • 8,846
5 votes

How can I prevent undo after redo?

Emacs 28 adds a redo command (called undo-redo). If you want to have more typical undo/redo, the following commands can be used. (global-set-key (kbd "C-z") 'undo-only) (global-set-key (kbd &...
ideasman42's user avatar
  • 8,846
4 votes
Accepted

Possible not to use undo-tree in evil mode?

Since answering this question, evil now supports pluggable undo systems. So if you want to use undo-fu instead of undo-tree you can do this as follows. (use-package evil :init (setq evil-undo-...
ideasman42's user avatar
  • 8,846
4 votes

How to reset undo history?

You can clear the undo history with this: (setq buffer-undo-list nil) ; discard undo history (set-buffer-modified-p nil) ; mark the buffer as unmodified I have the following functions in my config ...
glucas's user avatar
  • 20.6k
4 votes
Accepted

How to reset undo history?

Instead of C-u 1000000000 C-_, I'd recommend M-x revert-buffer RET. Then you don't need your xxx command. As for xxx, you could do: M-x buffer-disable-undo RET M-x buffer-enable-undo RET
Stefan's user avatar
  • 26.5k
4 votes

No further undo information

There are two (2) likely suspects: I. undo-tree-enable-undo-in-region is at its default non-nil setting and the O.P. has an active region; i.e., there are no more available undos in that active ...
lawlist's user avatar
  • 19.2k
3 votes

Undo region spacemacs

(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's user avatar
  • 151
3 votes

How can I implement Vim's `undo line` command in Emacs' evil-mode?

undo (bound to C-/, C-_, and C-x u by default) will restrict its action to the active region, if there is one: In Transient Mark mode when the mark is active, only undo changes within the current ...
Tyler's user avatar
  • 22.4k
3 votes

How to collapse undo history?

Some changes to the undo machinery "recently" broke some hack viper-mode was using to do this kind of collapsing (for the curious, it's used in the following case: when you press ESC to finish an ...
Stefan's user avatar
  • 26.5k
3 votes

How to reopen just killed buffer, like C-S-t in Firefox Browser?

EDIT: I didn't pay attention when answering, and answered something else the OP didn't ask. Once again, I'm sorry. Thank you for your words, @CodyChan. Well, I'm no Emacs veteran, and maybe this ...
Charles Roberto Canato's user avatar
3 votes
Accepted

Why isn't the jch's "with-undo-collapse" macro an emacs built-in yet?

There is undo-amalgamate-change-group nowadays. Used for instance in the function viper-adjust-undo in the file lisp/emulators/viper-cmd.el: (defun test-collapse () (let ((cg (prepare-change-group)...
Stefan's user avatar
  • 26.5k
3 votes
Accepted

Can redo be made to stop once the most recent state has been reached?

Emacs 28 adds a redo command (called undo-redo). If you want to have more typical undo/redo, the following commands can be used. (global-set-key (kbd "C-z") 'undo-only) (global-set-key (kbd &...
ideasman42's user avatar
  • 8,846
3 votes
Accepted

Restore emacs' default undo/redo behavior in spacemacs

Well, turns out the solution is easier then I imagined. Just add the following to your user-config.el file: (global-undo-tree-mode 0)
oneself's user avatar
  • 341
3 votes
Accepted

How to revert org-ctrl-c-tab in Org?

Keep calm and call that same function. If that doesn't do it, simply undo, close the buffer and reopen.
aadcg's user avatar
  • 1,248
2 votes

Why does modification in another buffer create undo boundary in current buffer?

This behaviour has changed now for Emacs 25.1. The original behaviour was to ensure that every buffer got an undo boundary, but it has negative side effects. Emacs 25.1 uses a new heuristic -- ...
Phil Lord's user avatar
  • 171
2 votes

Remap redo to C-S-/

If you haven't already try undo-tree.el. It gives Emacs a conventional undo, otherwise you need to undo the undos in order to redo--there is no redo function... With it you can add: (global-set-key ...
junkgui's user avatar
  • 46
2 votes
Accepted

redo (ctrl+y) undo

The commentary at the outset of the undo-tree.el library describes two built-in methods to undo and redo: https://github.com/emacsmirror/undo-tree/blob/master/undo-tree.el#L87 ;; C-_ C-/ (`undo-...
lawlist's user avatar
  • 19.2k
2 votes
Accepted

Replacement in loop as a single undo item in buffer-undo-list?

You're looking for undo-boundary: undo-boundary is a built-in function in ‘src/undo.c’. (undo-boundary) Mark a boundary between units of undo. An undo command will stop at this point, but another ...
phils's user avatar
  • 51.7k
2 votes
Accepted

Problem redoing with yasnippet

This is a bug in yasnippet, introduced on Jan 1st (not present in any stable release). See https://github.com/joaotavora/yasnippet/pull/893 for a fix, merged on Jan 22nd. The bug can be avoided by ...
npostavs's user avatar
  • 9,213
2 votes
Accepted

change how much undo-tree-undo undoes

I like to do two things with undo. I turn off the amalgamation stuff (which by doing so permits undo one keystroke at a time); and, I get rid of the timer (because timers affect performance and drive ...
lawlist's user avatar
  • 19.2k
2 votes
Accepted

Is it possible to group series of changes under single undo step?

Yes, I think you can do this. I think you need to use function undo-auto-amalgamate to tell Emacs to amalgamate (combine) operations in a single undo. It removes the previous undo-boundary. I haven'...
Drew's user avatar
  • 78k

Only top scored, non community-wiki answers of a minimum length are eligible