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

Re: CLI Tricks



[zzapper seems to be unusually good at running afoul of verizon's mail
filtering.  I've failed to receive the _first_ message in nearly every
thread he's started.  The Sunsite staff tells me they think it's because
their servers get temporarily listed by SpamCop, but why would zzapper
in particular be the one to always hit them during SpamCop blackouts?]

On Dec 12, 11:38am, zzapper wrote:
} 
} I meant NON-INSERT

[With regard to starting in vi command mode]

The short answer is, no, you can't, not without a bit of programming.

Vi mode works by changing zsh's "main" keymap to be the "viinsert" map
(normally it's the "emacs" map).  Command mode switches temporarily to
the "vicmd" keymap, but the keys in that map that would return you to
insert mode are all programmed to return you to the "main" map, not to
the "viinsert" map.  This is to allow invoking vicmd from a bindkey in
the emacs map without becoming trapped in vi mode.

So you could force zsh to start in vi command mode by making vicmd be
the main map, but then you can never get back to insert mode.

The way to program around this is to first copy the vicmd keymap:

    bindey -N vistartup vicmd

Next, create a widget function that restores "viinsert" as the main
keymap, and then calls through to a builtin widget.  You're going to
have to bind this to every key that might change to insert mode, so it
helps if it's generic:

    reset-vi-and-call () {
	local widget="${WIDGET#reset-}"
	bindkey -v
	zle $widget
    }

Now bind it to ALL the insert widgets in the vistartup keymap.  I'm
only going to show how you do this for "i" and "a", because it's very
monotonous:

    zle -N reset-vi-insert reset-vi-and-call
    bindkey -M vistartup i reset-vi-insert

    zle -N reset-vi-add-next reset-vi-and-call
    bindkey -M vistartup a reset-vi-add-next

Finally, set up your precmd function to force the main keymap to be
the vistartup keymap, because you have to reinitialize this every time
zsh re-enters ZLE:

    precmd () {
	# Any other stuff you already have in precmd stays here
	bindkey -A vistartup main
    }

That's all.  If you (or anyone) actually codes the rest of this up and
tests it, send the result to zsh-workers so we can consider including
it in the zsh distribution.



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