1

Re: Serious undo issue: u does undo too many changes

Hello again,

I have found an issue. The u command (undo) does undo ALL changes which
are done in the last insert mode session.

What I do:
- enter insert mode
- change something
- change anything many lines of code away from the first change
- change anything else
- change....
- and change again
- press ESC to enter normal mode
- press u to undo

What I would expect is that the last change is undone, going back
in history with each further undo....
Well, but ALL changes done during insert mode are undone by
pressing u just once.

Kind of mad.
I have tried it several times. I disabled Visual Assist, restarted VS2008,
did a reboot... But always the same behavior. Same if changes are
done in replace mode.
If I change code in normal mode (paste text), the undo works
as expected.

Can someone tell me please whether this is the intended behavior
of ViEmu's undo? I don't think so (hmmm... I hope it is not).
The forum's search lists several undo issues in the past...

This drives my really crazy...


Greetings
  LoveVim


--------------------------------------
  ViEmu 2.2.9
  Visual Assist X 10.5.1727.0
  Visual Studio 2008 Standard, SP 1, German
  Plugins: ViEmu and Visual Assist X
  Windows XP

2

Re: Serious undo issue: u does undo too many changes

I find 'u' (Undo) behavior after ReSharper changes to be pretty much unpredictable...

Are there some config settings in VisStudio or VIEmu that affect the granularity of Undo?

VisStudio 2008, ReSharper 4.5, VIEmu 2.2.8.  All playing nicely together, so far...

3

Re: Serious undo issue: u does undo too many changes

Number8 wrote:

Are there some config settings in VisStudio or VIEmu that affect the granularity of Undo?

I just know the ViEmu setting "viundo", see manual. This limits the undo buffer to 1. So only
the last change can be undone. But this is really not what I want.

4

Re: Serious undo issue: u does undo too many changes

Hello,

That behavior is actually how ViEmu works. It is indeed lacking, and it can be improved, but it's not a "bug".

The reason this is not usually a problem is that vi/vim/viemu are meant to use with only short excursions into insert mode, going back to normal mode after each edit.

I have just checked it in vim, and it splits insert mode sections into separate undoable-actions each time you either use the mouse or the arrow keys (maybe other things). ViEmu should add that.

The source of the difficulty is that, in the vi/vim model, undo involves a granularity that does not correspond to the usual one in VS or other editors. A single 'u' should undo a full 'c$hello<esc>' action. To do this grouping, ViEmu inserts "sentinels" in the undo queue. Earlier (1.x) versions used a real grouping feature of VS's undo system, but this was problematic with some language services and versions of VS. Doing the grouping by sentinels means that all non-ViEmu actions become "grouped" together.

The best way to do this would probably be to respect the granularity of external actions as they are treated by VS, while grouping somehow ViEmu-initiated ones. I will take note of this as a request, too.

Meanwhile, I suggest reducing the extent of insert-mode actions, and using VS undo if you are using external actions heavily.

Regards,

  -- Jon

PS: 'viundo' is only meant to emulate the original single-level-undo behavior of vi. Some people miss that!

5

Re: Serious undo issue: u does undo too many changes

Hello Jon,

And once more, thank you for the detailed and fast response.

Jon wrote:

That behavior is actually how ViEmu works. It is indeed lacking, and it can be improved, but it's not a "bug".

Ok, but this behavior is uncommonly for me. I have not seen such an undo-philosophy other editors (I have to admit that I do not know many editors ;-) ).
I used the term "serious issue" in the subject since I see the risk that
I could undo something which I don't want to undo.
For example: I do a bug fix, move to the header of the file in order to write some comments which describe the bug fix and want to undo a typo. Well, if I have not changed into normal mode since bug-fixing, not only the typo will be undone, but also the bug-fix. Hmmm....?
At least a ViEmu newbie like me is a sure candiate to do this.
(By the way, I develop software for medical devices. So I hope for you - as a potential user of such devices - that I will never do such a mistake ;-) (just kidding)).

Commonly undo has a higher granularity. I like the way how vim does handle this.


Jon, I would highly appreciate improvements in ViEmu's undo feature in the not too far future.

Jon wrote:

Meanwhile, I suggest reducing the extent of insert-mode actions, and using VS undo if you are using external actions heavily.

I agree...

LoveVim

Last edited by LoveVim (2009-06-28 05:55:08)

6

Re: Serious undo issue: u does undo too many changes

LoveVim, I don't understand how you can enter insert mode, make a change, then make another change many lines away without escaping into command mode after your first change.  I'm a long-time unix vanilla vi user, and I don't use the mouse to move around in ViEmu (I use it just as I use vi on unix), so maybe I'm just not aware of how vim may be used in a windows environment, but it seems to me if you escaped after each discreet change, this would serve your purposes.

Also, could someone please show me the actual format of how to set "viundo" in the _viemurc file?  I like the one-undo toggle behavior of vi.  In gvim, it's set by ":set ul=0", but I can't figure out how to set viundo.

Thanks...

7

Re: Serious undo issue: u does undo too many changes

wsmith, ":set viundo" at the ex command line, or just 'set viundo' in _viemurc will do the trick.

LoveVim,

I suggest you read my "Why vi/vim article" if you haven't yet, as I think you are keeping some habits from non-vi editing. The idea is that you will exit insert mode after you do whatever minor edit you meant to. You don't travel around the file in insert mode -- that's only doable with the mouse or arrow keys, which you are not supposed to use, and which often did not work in many environments where vi was used. In the scenario you describe, you'd fix the bug, exit insert mode, and use 'gg' (or 1G, or :1, whatever you prefer) to go to the top of the file.

Vim's behavior is an improvement, because it breaks undo actions at arrow-key or mouse-click points, while keeping most of the old behavior. It would make sense for ViEmu to implement that, although I would still recommend doing things "the vi way".

I will definitely try to improve this in a future version. I am now concentrating on a few necessary major efforts (a new license key system, a few long-asked-for important features, and VS2010 support), so it will take some time, but it should be doable (at least part of the features). I hope some sales growth will help me hire permanent extra help to be able to improve ViEmu more, as the "todo" list is already huge!

Regards,

  -- Jon

8

Re: Serious undo issue: u does undo too many changes

Ahh, thank you!  I was trying ":set viundo".

I also added the ":nnoremap <esc> :noh<return><esc>" which I got from your blog...very nice!

Regards,
wsmith

9

Re: Serious undo issue: u does undo too many changes

You are very welcome! The new <esc> mapping has become a favorite of mine too smile

  - Jon

10

Re: Serious undo issue: u does undo too many changes

Hi Wsmith,

Wsmith wrote:

LoveVim, I don't understand how you can enter insert mode, make a change, then make another change many lines away without escaping into command mode after your first change.

Perhaps this is a vim/gvim feature - I don't know - but under all Linux derivates I have
used in the past 10 years and in gvim for Windows you simple have to press
cursor keys, page-up, page-down or ctrl-home and so on to move the cursor. This works
in both insert and normal mode. You can navigate quite comfortable in insert mode.
And you can navigate quite comfortable in normal mode, but more powerful. Depending on
what you want to do and depending on the situation the insert mode or the normal mode may provide
the appropriate feature to do it in an efficient(!) way.
I'm very pragmatic here. I prefer the way which needs less keystrokes and which I can
handle fluently.

If I remember correctly even my first vi/vim version for Amiga in the beginning 1990th
had supported navigation in insert mode.


Wsmith wrote:

...but it seems to me if you escaped after each discreet change, this would serve your purposes.

Yes, indeed this would increase the granularity of the undo command.
But I don't want to escape insert mode when I fluently type text/code just to increase
undo granularity due to the following reasons:
- it would be no longer a fluently typing
- it would lower efficiency since I have to press ESC and i each time I want to set
   an undo point

For example how would you type this code?:

    switch( nNumOfDays )
    {
        case ID_BUTTON_1:
            break;
        default:
            break;
    }

If I had the piece of code in mind, I would enter insert mode and would
start to type line by line (here with support of auto-completion and snippets,
but this is another topic and does not matter). Without leaving the insert mode.

How do you enter this code? Do you really leave here insert mode in every line?
If so you will definitely need more keystrokes than I would need - and not just
one or two...
Ok, I don't know vi, perhaps vi does not allow entering this in insert mode.
But your approach definitely lowers efficiency.

And if you type this fluently - and in my opinion efficient - without leaving
insert mode, you can simply run into the situation that you want to undo something.
But in the current undo implementation of ViEmu you would undo all(!) the typing you
have done in insert mode since entering insert mode. The complete switch code would be
undone (as typed so far)!

And in my opinion this is too much undo. I'm sorry.

If you want to increase granularity you have to leave insert mode more often.
This is clear. But this lowers efficiency. And a high efficiency is the reason
why I prefer Vim's input model and why I do not use one of the mode-less editors.


Greetings
  LoveVim

P.S.: I have used the term "efficiency". In this context I mean "efficiency of
typing code" - not efficiency of designing and implementing software products.

11

Re: Serious undo issue: u does undo too many changes

LoveVim, in your code example, I would indeed do as you do - enter insert mode and type the entire section of code.  But that does not involve navigation to another part of the document.
I always escape out of insert mode when I'm done typing at a particular location.  Of course I'm old-school vi, and used vi for 14 years where the only movement available was via the vi movement keys.  And as I said before, I don't even like the multiple-undo;  I prefer the old vi undo-redo toggle.  It just doesn't bother me at all the way ViEmu works for me, but I'm not trying to convince you that my way is better smile

12

Re: Serious undo issue: u does undo too many changes

LoveVim,

Thanks for the very thoughtful explanation. You are right that in some cases not exiting insert mode is more efficient. I apologize for thinking that you may have been a newcomer to vim -- it is often the case with newcomers to stay in insert mode for too long. One feature that I have only gotten a few requests for is insert mode ^o, to execute a normal mode command from insert mode, which ViEmu doesn't yet support. It is usually the case that users request it from not using vi/vim editing correctly, rather than for valid reasons. Of course, in both cases (i_ctrl-o and undo granularity), ViEmu should support them in the future, as there is no drawback.

I have been trying (for a few hours now!) to devise a test, using just the macros IDE, to see why keybinding setting doesn't work in the German version of VS. I'm stumbling into a block because even MSDN examples don't work. Can I say, again, how much I hate VS's VB-based programmability environment, and the clunkiness of their object model?

I'll post here as soon as I have something more concrete.