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

Re: trouble with vimbindings...



Thanks!
That solves my problem...
Just wondering why it isn't implemented that way by default...
well nevermind

Best regards,

On Sun, Mar 15, 2009 at 03:01:37PM -0700, Bart Schaefer wrote:
> On Mar 15,  9:56pm, iamjay wrote:
> }
> } When using vimkeybindings with bindkey -v... and you create a laaaarge
> } command like:
> } 
> } echo foo barfoo barfoo barfoo barfoo barfoo barfoo barfoo bar \
> }  foo bar bar barba rbar b barb bar
> } 
> } and you leave vim's insert mode.. theres no way for me to go to the
> } upper line..
> 
> This is the way the line editor always works.  When you hit enter
> at the end of the First line, the editor finishes and passes the
> line to the parser, which finds the backslash and starts up a new
> editor for the second line.  (This is true in emacs mode as well.)
> 
> So leaving insert mode while editing the second line leaves you in
> the same instance of the editor which "contains" only that second
> line.
> 
> There are several ways to "fix" this.  One would be to override the
> accept-line widget so that you never leave the first editor:
> 
>     backslash-accept-line() {
>       # Consider replacing LBUFFER with BUFFER on the next two
>       # lines, depending on your preferred semantics
>       if [[ $LBUFFER = *\\ ]]
>       then LBUFFER+=$'\n'
>       else zle .accept-line "$@"
>       fi
>     }
>     zle -N accept-line backslash-accept-line
> 
> The above doesn't handle the general case of multi-line constructs.
> For that you need something more violent:
> 
>     init-cmd-mode() {
>       # Needs adjustment if you otherwise define zle-line-init
>       zle -D zle-line-init
>       zle .vi-cmd-mode
>       zle -R
>     }
>     vi-cmd-mode() {
>       if [[ -n "$PREBUFFER" ]]
>       then
>         # Needs adjustment if you otherwise define zle-line-init
>         zle -N zle-line-init init-cmd-mode
> 	zle push-line-or-edit
>       else
>         zle .vi-cmd-mode "$@"
>       fi
>     }
>     zle -N vi-cmd-mode
> 
> Using push-line-or-edit effectively says "kill this editor and start
> a new one with the entire multi-line command I was working on."  The
> init-cmd-mode trick is needed to propagate the last command from the
> editor that's being killed, into the new editor that's starting up.
> 
> Other solutions are also possible, but I'm not going to try to invent
> all of them ...



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