2

I am working through the user manual, doing the examples on a Mac using Vim (comes bundled with MacVim) on the terminal and was doing fine with undo (Chapter 2). Then with undo line or U, when doing the example it didn't produce the output shown. I had done tasks with U in Vimtutor before and it went fine.

I was following these instructions from Chapter 2, Section 2.5:

A very intelligent turtle        
  xxxx                      Delete very

A intelligent turtle 
              xxxxxx        Delete turtle

A intelligent
                            Restore line with "U"
A very intelligent turtle

Instead of restoring it, it shows an empty line. Literally, U returns the line to it's empty origin.

When saving the file with the text "A very intelligent turtle" and following the instructions again, it does nothing when pressing U. It keeps "A intelligent" without change.

Steps I do:

  1. Invoke Vim from command line.
  2. Press i to start inserting.
  3. Write: A very intelligent turtle.
  4. Press ESC to go to Normal mode.
  5. Press b three times to go to word very.
  6. Press x four times to delete it.
  7. Press w two times to go to word turtle.
  8. Press x six times to delete it.
  9. Press U.

Result: Empty line.

6
  • 1
    Maybe U is remapped in your distribution. What is the result of the following command :nmap U? Feb 4 at 5:05
  • 1
    Thanks for helping me isolate the problem. After executing :nmap U, it says : "No mapping found" Feb 4 at 20:24
  • Thanks for the feedback. Feb 5 at 2:02
  • 1
    Thanks for the example. The behavior described is as expected since it undo all the consecutive édition on the line: the insertion and the deletion. If undofile is off (:set noundofile) and you save the buffer after insertion and quit Vim the next Vim session deletes can be "recovers" can by U. Or after insertion and before the delete you edit another line since all the edition must be consecutive Feb 6 at 3:16
  • 1
    Indeed, that works. So it's normal behavior then. Feb 6 at 20:14

1 Answer 1

3

The undo line is a strange beast.

It gathers all the consecutive changes (insertion, deletion, modification) you did on the undo branch:

  1. On the last line you have edited
  2. Since the last undo line operation

makes one undo operation out of them and executing it (hence inserting it in the undo branch like any other editing operation)

Point 1 is important.

If you created a new line at the end of your edition (e.g. o) this last line become the last edited line and U does nothing.

If you undo all the changes of the last edited line it does nothing.

11
  • 4
    It is too complex for me I don't use it ;-) Feb 4 at 6:37
  • 4
    Same. U never clicked for me.
    – romainl
    Feb 4 at 8:52
  • 1
    I made sure to take into account what you said and got the same results. However, if I created an additional line before, with some text, and then created another line with "A very intelligent turtle" and did the steps to delete the words, U did restore the line. So it seems for U to work it needs more than one line. Feb 4 at 22:05
  • I do manage to have undo line working with one line buffer :-| What is the result of :set undofile?? Feb 5 at 2:01
  • It should work for a one line buffer but if you have :set undofile then all the operations are on that line and U restore everything since undofile has been set (if it is from the start of editing that file you should get an empty buffer) Feb 5 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.