1. Frank Fischer
  2. evil
  3. Issues
Issue #144 open

"U" does not do anything

Anonymous created an issue

I'm trying to learn Vim keybindings from vimtutor, and noticed that "U" does not undo all changes on a line. Is this not bound for a reason, or is this a missing feature? I don't seem to see any mention of it anywhere online.

Comments (10)

  1. Frank Fischer repo owner
    • changed status to open

    Well, it is a command that is probably rarely used (I didn't even know it) and no one ever complained that it's missing. And it's probably not so easy to implement.

  2. dreimer

    Alright, I just saw it in the tutorial and noticed it didn't work. I'm not sure if it would be that hard to implement though, since couldn't it just use undo-in-region?

  3. Frank Fischer repo owner

    Hm, undo-in-region reverts the latest change in the region. But U seems to work differently. It reverts all latest changes as long as they are in the current line. Thus the command would have to go through the undo-list and test whether the latest change is in the current line. If so, it is reverted and the process is repeated. Otherwise the command stops. I have no idea if undo-in-region can be used to do this. And there may be problems depending on whether undo-tree is used or not.

    But of course, it is certainly possible, perhaps easier than I thought. Feel free to submit a patch if you find a good solution ;)

  4. dreimer

    I just found something revealing. In the other tutorial, Vi For Smarties, it contains this line: "Use U (uppercase) to Undo all changes made to a line if and only if the cursor has not been moved off that line yet." It sounds like it doesn't require anything particularly tricky.

  5. Frank Fischer repo owner

    I do not understand. It is still the problem to identify which changes in the undo list belong to the current line and how modifying this list interacts with other packages like undo-tree. Moving the cursor or not does not make a difference (btw, according to vim's doc (:help U) it is allowed to move point unless vim is in vi compatibility mode). As I said, it may not be too difficult but it's certainly not trivial. And the there are other more important issues with the undo system (e.g., #138). Because if this and because I think that the "U" command is not that useful (I've never used or missed it) I do not want to deal with "U" currently.

    ... this does not mean that we would not accept patches that implement the "U" command ... ;)

  6. Frank Fischer repo owner

    I still do not understand. Yes, you can affect other lines without moving to them, but this is not the point. The question is how to identify the changes in the undo-list (e.g., some changes may add/delete a line, then it may even be unclear what "the current line" is) that should be reverted. How those changes have been generated is not important.

  7. dreimer

    And that's something else I missed. You see, when I saw the line from Vi For Smarties, I thought you only had to look back at a few changes in the undo list. I was thinking that the only changes that mattered would be from when you moved onto the current line until the last change.

  8. Nick Felix

    It might be not as hard to implement the vim "U" behaviour, because it is not a real undo, in vim it is possible to undo the "U" command with "u". So it is just a seperate command and has nothing to do with the normal "undo". It could be possible to copy a line before it is changed. If the changes are made to more than one line without leaving the insert mode than "U" does nothing. every time a new line is edited the old "saved" line can be dropped. But I agree that it is rarely used, and not especially usefull.

  9. Log in to comment