25

These are some awesome options: emacs-24, evil-mode (using vim bindings in emacs), and undo-tree.

However, when I'm in edit mode (insert mode), I sometimes jump around for a number inserts, deletes, etc. before hitting escape and leaving insert mode.

"Undo" takes the whole insert (including deletes) as one edit. For example, I can't undo the paragraph I accidentally deleted without undo'ing the whole delete!

Is there any way to fix this?

Here are some related links:

Here are the vim mappings that convert certain vim commands so that they can be undone:

inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
inoremap <End> <C-g>u<End>
inoremap <BS> <c-g>u<BS>
inoremap <CR> <c-g>u<CR>
inoremap <del> <c-g>u<del>

What is needed is for the undo mode inside of emacs evil undo-tree to track additional events besides just leaving insert mode. For example, you should be able to stay in insert mode a long time and then undo any sort of delete, cut, paste.

Community
  • 1
  • 1
justingordon
  • 12,553
  • 12
  • 72
  • 116
  • Based on http://stackoverflow.com/questions/6590889/how-emacs-determines-a-unit-of-work-to-undo, the extra commands within evil need to call undo-boundary. – justingordon Jul 21 '12 at 23:43
  • Only because it hasn't been said yet: "You should treat insert mode like you're running over a hot bed of coals; get out of there as soon as possible". – Cory Kendall Jul 25 '12 at 01:56

2 Answers2

22

Try evil-want-fine-undo:

Whether actions are undone in several steps. There are two possible choices: nil ("no") means that all changes made during insert state, including a possible delete after a change operation, are collected in a single undo step. Non-nil ("yes") means that undo steps are determined according to Emacs heuristics, and no attempt is made to aggregate changes.

(setq evil-want-fine-undo t)
xeruf
  • 2,602
  • 1
  • 25
  • 48
tkf
  • 2,990
  • 18
  • 32
1

Is this specific to undo tree? I don't use it, so the following might not apply...

I'm not sure if you can modify the amount of editing that the undo mechanism considers to be a single unit, but what you can do is:

Select a region first and then type the undo key, and Emacs will only undo changes that were made in that region.

That can be very useful.

phils
  • 71,335
  • 11
  • 153
  • 198