Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I just skimmed it, but it looks like vim really has undo/redo "solved":

    - Modal editing makes for nice "undo" points, clarifying whether undo should undo "World!" or "!".
    - "g-" and "g+" eliminate the "orphaned redo".  They walk the entire undo/redo tree rather than just the linear undo/redo.
    - Time travel undo/redo is really handy when you want to go to where you were on the wall-clock.  ":earlier 15 minutes" takes you to the code as it was 15 minutes ago.


> but it looks like vim really has undo/redo "solved"

Does it support restricting undo/redo to a selection? In Emacs you can select any region of text and just apply the undo history of the selection. That is extremely useful. Imagine working on to functions in the same file. You have are working on g() and realize you want to undo some change on f(), that you did before. Most editors don't support that. In Emacs you can just select the code of f() and press undo (C-_).

Several popular undo extension libraries break this feature.


Just to emphasize part of your comment as I think a lot a people aren't fully aware - Vim has an undo tree https://vimhelp.org/usr_32.txt.html#usr_32.txt


> ":earlier 15 minutes" takes you to the code as it was 15 minutes ago.

TIL. Very cool. tnx


Been using vim for few years, never hears of that feature. Still a student.


Don't forget about the Gundo plugin: it lets you navigate your tree of undo history.


Gundo is great. There is also mundo, which is a fork of gundo. And, undotree, which doesn't require python support.


Far from solved

Modal editing isn't enough if you type whole sentences/paragraphs of text within a single insert session

Also undo in selection is required to "solve" it, as well as semantic points besides "last 15 minutes" (like "last saved session" or "last time you quit the editor")

Also UI with a diff is sometimes better than having to undo/redo to see changes


>Modal editing isn't enough if you type whole sentences/paragraphs of text within a single insert session

Why not? Honest question.


Because it's too coarse: undoing the whole paragraph instead of just the last word with a typo is too much, so you'd have to be always aware of this limitation and break flow to switch modes for no other reason than to insert "undo points", and these are unnecessary mental bookkeeping chores


I don't have this problem in practise. It's not "break flow to switch modes" for me. I don't type this way. There's always as much movement as there's typing, especially while programming. Even when writing prose I exit the insert mode each time I think of what to write next making this always a good "undo point".

If I make a typo while in the insert mode I just remove last character or last word. I guess you could argue that this is something that undo should also cover but I don't see much need for that.

I'm not in the insert mode, exiting to normal mode for movement and undo. I'm in the normal mode entering insert mode to write.


While the inferiority of your workflow doesn't matter to you, it's still a point against undo being "solved" by vim


What problem does a magical "does what I mean" undo solve that pressing ^W or ^H doesn't? At a minimum, your "superior workflow" is "<Esc>ui" or "^Ou", both of which are more keystrokes and require your editor to read your mind.


Or my superior workflow is Alt-u or hold U, which is a single shortcut/keystroke, so you lose there as well

The other issue with your attempt at solving undo without undo is that the deletion doesn't become part of redo, also a single word with a typo could be in the middle of a paragraph where you navigated with a trackpad, while ^W would delete near the current cursor position

You don't need magic to fix the ubersimplicity of current defaults, just a bit of openness


^W is ctrl-W.


So what? How does it address the issue I've described?


It's the same number of keypresses as alt-U.


So now it's not "more keystrokes" as you originally claimed (and it's a higher number of keypressses vs holding U), and you still haven't addressed the issue with ^W I've described


There are alternatives to "undo", which are probably better suited to "undo last word" without making "what will undo undo" more mentally complicated. Having undo reverse the last edit, whether that's a word or a few words or adding an argument definition to a function, or adding an "if" block -- makes it very easy to keep in your head. "I want to undo that last thing I did".

The alternatives are:

    - Control-W (delete the last word, stay in insert mode)
    - "W" to move back a word (or "B" to move back a big word).  So: <Esc>BC
There's apparently also a recipe for setting up vim to insert undo points whenever you hit space, so you could also enable that for the files you want to do that on.


understanding of what that "last thing I did" isn't session specific, like "adding an if block and a long comment describing what that block does" is semantically two last things I did, the fact that they're happening within a single insert session doesn't help. And I don't really need too keep it in my head, a solved undo would make it visually obvious to free my head

The alternatives you suggest are bad: 1. This is no undo, so then it's not part of redo

2. Why would I ever want 3 undo points if I indent my comment a bit by 3 spaces?


I love vim but I actually find undo/redo to be one of the few annoyances of the program, because of the whole linear undo/redo thing. So I guess I need to look into this g+ option…


As I mentioned elsewhere, gundo is really helpful for navigating the undo tree.

My favorite thing about vim's flow is that it isn't just limited to undo/redo: you can re-perform your most recent action anywhere using the . key.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: