Aidan Kane
Aidan Kane

Reputation: 4006

Can Vim restore the state exactly after an undo?

For example, if I'm in the end of a word and I type 'diwu', the cursor ends up at the start of the word.

Same applies if I have something selected in visual mode (after undo I'd like it to go back to the visual selection I had before the operation I've just undone).

Sorry if stackoverflow isn't the best place for this (seemed to be the best option looking around).

Upvotes: 0

Views: 221

Answers (2)

romainl
romainl

Reputation: 196476

I'm not sure it can/should be automated with a mapping but in your first case I would create a mark with ma then do the deletion/undo, then type `a to position the cursor at the mark.

In the second case, gv reselects the previous visual selection.

Upvotes: 2

sehe
sehe

Reputation: 392883

The closest I came:

 the quick brown fox jumped over the lazy moon
      cursor here ----- ^

Execute

madiwu`a

It requires you to explicitely save the location before the edit/undo so it is pretty useless unless you know beforehand that you are going to revert an edit

  1. ma (save current position in mark 'a')
  2. diw (delete inner word, 'jumped ')
  3. u (undo that change, cursor ends up at 'j' of 'jumped')
  4. `a (jump to 'a' marker)

Upvotes: 2

Related Questions