Re: vi-compatible undo and post-undo cursor position

Is it possible to enable vi-compatible undo (equivalent to ":set cpoptions+=u" in vim)?

Also, I've noticed that the cursor position after undo does not behave as in vi/vim. In vi, after an undo operation the cursor remains at the position affected by the undo, but in Visual Studio the cursor jumps back to the most recent change preceding the undone change.

Given how accustomed I have become to the standard vi/vim behavior, it's fairly disorienting to have the cursor jump away from the undo position.


Re: vi-compatible undo and post-undo cursor position

You can use the "viundo" option (:set viundo) to emulate vi's single-undo behavior (it's not complete but works). Put it in .viemurc (or _viemurc) in your home directory for it to be set automatically every time.

Regarding the undo cursor position, it's mostly controlled by VS - and there is not much that can be done in general -, but if you can provide me some more specific feedback I'll look into it and try to find a fix. It can maybe be improved in some specific cases.

Best regards,



Re: vi-compatible undo and post-undo cursor position

Vim's vi-compatible undo is not limited to single-level -- it just behaves slightly differently than the default Vim undo. Rather than repeating undo with the 'u' key, the 'u' key reverses the undo/redo direction, and Ctrl-R repeats in the current direction. BSD's nvi behaves similarly, but it uses '.' rather than Ctrl-R to repeat. (I hope that explanation is understandable.)

Since I used vi for years before switching to vim, I became accustomed to using repeated presses of 'u' to review my most recent change (undo/redo/undo/redo). I find multi-level undo EXTREMELY valuable though, and wouldn't want to lose that.

Regarding the cursor position after undo... in vim, the behavior is effectively the same as setting a mark at the beginning of every edit operation, then jumping back to that mark (with backquote) after undo.

Thanks for your prompt reply! I'm impressed with ViEmu -- I'm generally skeptical of vi emulation in non-vi editors, because vi has so many subtleties. After using ViEmu for a couple days and seeing your responsiveness to issues, I'm optimistic that I'll be able to use it to improve my Visual Studio experience.


Re: vi-compatible undo and post-undo cursor position

I'll have a look at vim's "vi-undo" mode and try to see if it's "emulatable" (does the word exist?) within VS.

Regarding cursor position afater undo, it's a very tricky area. Undocumented VS behavior, etc... if there is some specific operation in which it's most annoying, please let me know so that I can try to address it. In the general case, it's really tough to tame this behavior within VS, so it'll have to stay more or less as it is now.

Many people are initially spkeptical of ViEmu at the beginning, perfectly understandable, but in the end they like the integration and find it surprisingly natural - I use it myself all the time, so I'm sure that helped, and, of course, the feedback from hundreds of users whose requests I've been implementing since the first release!

Thanks to you and best regards,



Re: vi-compatible undo and post-undo cursor position

I'll try to explain vi undo mode more concisely: Vim's vi undo mode swaps the undo/redo behavior of ^R and 'u' whenever the user presses 'u'.

I would really like to find a solution to the "cursor position after undo" issue. When I press 'u', sometimes I cannot see what change the undo operation made because the cursor jumps to an entirely different section of the file. I realize this isn't a problem introduced by ViEmu, but I would really like to see ViEmu emulate the vi behavior in this case.

Thanks for being so responsive!


Re: vi-compatible undo and post-undo cursor position

I'll investigate the vi-undo mode with vim, hopefully that's not too complex.

The other problem is more difficult - there used to be problems with the cursor position after undo/redo, but I think I fixed it in most cases. I usually use VS.NET 2003 and C++ only, what version of VS and language are you using? It might make a difference. And what type of operations cause the problems most often? That is, insert-mode ops? Or 'dd' line deletions, or ex commands?


Re: vi-compatible undo and post-undo cursor position

I'm using VS.NET 2005 and C++... but I'm actually not seeing the post-undo cursor position problem anymore. It was very consistently misbehaving during my first Visual Studio session after installing ViEmu, but since restarting Visual Studio I haven't reproduced the problem. I had never seen it behave in the vi way, so thought that was just unaddressed... but now it seems to be behaving exactly as I expect. If I see the problem again, I'll let you know.


Re: vi-compatible undo and post-undo cursor position

Ah ok, let me know if it happens again or if you find a pattern. I don't understand how it could fail only the during the first session, there shouldn't be any difference, but there are quite a few "VS gray areas" that could cause it.


Re: vi-compatible undo and post-undo cursor position

For what it's worth, I also noticed (during that same session) that the cursor would jump to an unexpected position after I terminated the debugger.


Re: vi-compatible undo and post-undo cursor position

Really weird, I've never seen that behavior. Please let me know if it ever happens again!




Re: vi-compatible undo and post-undo cursor position

Select some code and press Ctrl-K, c to comment it. Make some other changes elsewhere in the file. Undo a few times. When you undo the comment operation, the cursor will not move.


Re: vi-compatible undo and post-undo cursor position

Thanks for the detailed steps to reproduce it! I'll have a look at it and get back to you.