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

I still use a lot of nvi on openbsd. and it has a strange quirk to it's undo.

so "u" undoes your last action. but if you hit it again it undoes the undo, a redo if you will. I did not really think about it much, just accepted that was how nvi worked, a single level undo. But that is not true at all. the trick is you have to "u" undo then "." repeat previous action and you get the full undo stack. and, like the parent post mentioned, you also get a full redo stack the same way. Get it to redo then repeat previous action.

I am not exactly sure what vim does, But I suspect this is one of it's improvements.



I can't believe that, in 16 minutes, nobody else on HN had the answer: nvi is following original, authentic vi behavior, not this newfangled stuff. The Vim manual explains it:

  How undo and redo commands work depends on the 'u' flag in 'cpoptions'.
  There is the Vim way ('u' excluded) and the Vi-compatible way ('u' included).
  In the Vim way, "uu" undoes two changes.  In the Vi-compatible way, "uu" does
  nothing (undoes an undo).

  'u' excluded, the Vim way:
  You can go back in time with the undo command.  You can then go forward again
  with the redo command.  If you make a new change after the undo command,
  the redo will not be possible anymore.

  'u' included, the Vi-compatible way:
  The undo command undoes the previous change, and also the previous undo
  command.  The redo command repeats the previous undo command.  It does NOT
  repeat a change command, use "." for that.
https://vimhelp.org/undo.txt.html

(Actually, I have so rarely used vi that I'm relying on the implications of the Vim manual that it's original vi behavior.)


With vim, "u" always moves back in time through the undo history, CTRL-r forward. "." repeats the last action which changed some text but not stuff like moves or going forward/backward through the undo history.

nvi sounds very weird to me.


Yes, in Vim, repeated u's just continues undoing, while ctrl-r is for redos.




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

Search: