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

Re: PATCH: key bindings, fixes, docs, tests for vi stuff

On 21 Nov, Bart wrote:

> But it shouldn't be that difficult to have the modules check for the
> existence of the keymap, skip re-creating it it if it's already there,
> and then only add bindings that don't conflict?

That won't work where people remove bindings. Maybe that's not too
common though I do it. Actually, looking at what I remove, I think
we should change the default binding of ^X in viins to be undefined
instead of self-insert. This is because the completion system adds a
bunch of widgets with a ^X prefix. Furthermore, vim uses ^X as a prefix
to mostly completion commands.

Coming back to the original question, it might be possible to make
keymaps a feature that causes module autoloading. If that doesn't work,
merging the defaults should be ok.

> } I also wonder if we could make it possible for shell function widgets
> } to specify some sort of default key binding much as is possible for
> } completion widgets.
> The widgets don't really specify their key binding, that's all done by
> compinit when it scans $fpath for #compdef lines.  We could easily have
> another such script that looks for a different #something.  There is
> already #autoload but it doesn't do bindings.

Somehow, I had thought compinit only looked at files named comp* or
_* but apparently not. I still would have considered #autoload as
implying the function was completion related. It seems a bit wasteful
to have two scripts scanning the whole of $fpath and generating caches.
Perhaps we should squeeze it into compinit and accept that it leaves
compinit badly named. Or is it better to somehow factor out that step
and share the results. An alternative might be to have separate *init
functions containing hardcoded lists of widget names so you might have a
zleviminit that would autoload a fixed list of widgets.

The patch below contains documentation to the vi default keys change I
proposed before. I've added in the removal of ^X in viins and the g~~
binding. It took me by surprise to see that redo is not bound by default
in emacs mode. Seems you have to reverse the direction of undo in emacs,
right? I can't remember any complaints about the lack of strict emacs
compatibility leading to lost changes there. I'm inclined to go ahead
with the vi mode undo change: vim converts probably outnumber vi purists
among zsh vi mode users.


diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index d49c720..dd8e628 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -1073,7 +1073,7 @@ Move backward one word, where a word is defined as a series of
 non-blank characters.
-item(tt(vi-backward-blank-word-end) (unbound) (unbound) (unbound))(
+item(tt(vi-backward-blank-word-end) (unbound) (gE) (unbound))(
 Move to the end of the previous word, where a word is defined as a
 series of non-blank characters.
@@ -1098,7 +1098,7 @@ item(tt(vi-backward-word) (unbound) (b) (unbound))(
 Move to the beginning of the previous word, vi-style.
-item(tt(vi-backward-word-end) (unbound) (unbound) (unbound))(
+item(tt(vi-backward-word-end) (unbound) (ge) (unbound))(
 Move to the end of the previous word, vi-style.
@@ -1215,7 +1215,7 @@ texinode(History Control)(Modifying Text)(Movement)(Zle Widgets)
 subsect(History Control)
-item(tt(beginning-of-buffer-or-history) (ESC-<) (unbound) (unbound))(
+item(tt(beginning-of-buffer-or-history) (ESC-<) (gg) (unbound))(
 Move to the beginning of the buffer, or if already there,
 move to the first event in the history list.
@@ -1728,7 +1728,7 @@ item(tt(vi-open-line-below) (unbound) (o) (unbound))(
 Open a line below the cursor and enter insert mode.
+item(tt(vi-oper-swap-case) (unbound) (g~) (unbound))(
 Read a movement command from the keyboard, and swap
 the case of all characters
 from the cursor position to the endpoint of the movement.
@@ -2286,7 +2286,7 @@ This command is executed when a key sequence that is not bound to any
 command is typed.  By default it beeps.
-item(tt(undo) (^_ ^Xu ^X^U) (unbound) (unbound))(
+item(tt(undo) (^_ ^Xu ^X^U) (u) (unbound))(
 Incrementally undo the last text modification.  When called from a
 user-defined widget, takes an optional argument indicating a previous state
 of the undo history as returned by the tt(UNDO_CHANGE_NO) variable;
@@ -2297,11 +2297,11 @@ insert mode is reverted, the changes having been merged when command mode was
+item(tt(redo) (unbound) (^R) (unbound))(
 Incrementally redo undone text modifications.
-item(tt(vi-undo-change) (unbound) (u) (unbound))(
+item(tt(vi-undo-change) (unbound) (unbound) (unbound))(
 Undo the last text modification.
 If repeated, redo the modification.
@@ -2320,7 +2320,7 @@ following an operator, it forces the subsequent movement command to be
 treated as a line-wise movement.
-item(tt(what-cursor-position) (^X=) (unbound) (unbound))(
+item(tt(what-cursor-position) (^X=) (ga) (unbound))(
 Print the character under the cursor, its code as an octal, decimal and
 hexadecimal number, the current cursor position within the buffer and the
 column of the cursor in the current line.
diff --git a/Src/Zle/zle_bindings.c b/Src/Zle/zle_bindings.c
index e3337d0..2ae8c87 100644
--- a/Src/Zle/zle_bindings.c
+++ b/Src/Zle/zle_bindings.c
@@ -278,7 +278,7 @@ int viinsbind[32] = {
     /* ^U */ z_vikillline,
     /* ^V */ z_viquotedinsert,
     /* ^W */ z_vibackwardkillword,
-    /* ^X */ z_selfinsert,
+    /* ^X */ z_undefinedkey,
     /* ^Y */ z_selfinsert,
     /* ^Z */ z_selfinsert,
     /* ^[ */ z_vicmdmode,
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index afba592..be02f3a 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1373,6 +1373,7 @@ default_bindings(void)
     bindkey(amap, "gE", refthingy(t_vibackwardblankwordend), NULL);
     bindkey(amap, "gg", refthingy(t_beginningofbufferorhistory), NULL);
     bindkey(amap, "g~", refthingy(t_vioperswapcase), NULL);
+    bindkey(amap, "g~~", NULL, "g~g~");
     /* emacs mode: arrow keys */ 
     add_cursor_key(emap, TCUPCURSOR, t_uplineorhistory, 'A');

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