开发者

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 sta开发者_如何转开发ckoverflow isn't the best place for this (seemed to be the best option looking around).


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.


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜