Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zle: vi mode: wrong undo handling on fresh lines



On 23 Sep, Peter Stephenson wrote:
> Hauke Petersen <hkptrsn@xxxxxxxxx> wrote:
> > Insert operations should count as a single step in the undo history,
> > i.e. from command mode
> > 
> >     ifoo<ESC>u
> > 
> > should effectively be a no-op.
> > 
> > AFAICT, zsh handles this fine with the exception of fresh lines.
> 
> Is it something like this, perhaps?

I find the effect of this change to undo to be very annoying. Typically
undo now wipes the whole buffer which isn't much use. In particular, the
old behaviour of undo after a completion is important to me. I
understand that it rightly should be marking the start of an insertion
at this point. However, even aside from that, the change doesn't seem to
be quite right: e.g. vi-repeat (dot) can't repeat the initial insertion.

My setup is something of a hybrid: vi-mode but with many emacs-mode
widgets bound in insert mode. In most cases where there are identically
named vi- widgets, the only difference is that the vi- ones honour the
viinsbegin position (so I use the emacs ones). Note that vim has relaxed
some of these so you can do things like backspace past the start of a
change. Rather usefully, a vim Ctrl-W (backward-kill-word), will stop at
the start position but go on if invoked a second time. I can't find a
way to implement that in a zsh user-defined widget mainly because the
return status of vi-backward-kill-word doesn't seem to be helping me.
  
It is no bad thing to group successive inserts into a single undo event
(most editors, emacs included do this). The question is how to provide
some control so something like a backward-delete-word or completion can
be treated as a separate undo event. vim solves this by letting you
break a change into two undo blocks with Ctrl-G u. This doesn't alter
the vi change start position, only the undo stack. Is a widget to do
that possible? Another possibility which comes to mind would be to add a
flag like ZLE_KEEPSUFFIX† to mark widgets that start a new undo block,
though I realise those flags aren't currently configurable.

†Incidentally, I bind escape to first do zle auto-suffix-retain so
vi-cmd-mode should perhaps have ZLE_KEEPSUFFIX set.

Oliver



Messages sorted by: Reverse Date, Date, Thread, Author