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

Re: [PATCH] initialization of main keymap



Felipe Contreras wrote on Thu, Sep 01, 2022 at 16:58:05 -0500:
> most vim users use emacs key bindings in the shell.

Citation needed.

> In my opinion the default should always be emacs bindings, no matter what.

+1

If the default were /either/ vi or emacs, a patch making the default
depend on the value of $EDITOR would never have been accepted.  We'd
have pointed out that it was overloading an environment variable that
already has a well-defined meaning; that a dependency between that
envvar and zle violates the principle of least surprise; that assuming
strstr(…, "vi") means "Vi-like editor" is guesswork (cf. PEP20); that
the C code shouldn't presume Vi users necessarily prefer «bindkey -v»;
and that users can and should set their preferred Zsh Line Editor keymap
in zshrc.

Attached is a counterpatch for discussion.

Felipe: Should revisions to this patch be requested, feel free to beat
me to implementing them, if you wish.

Cheers,

Daniel

[[[
diff --git a/README b/README
index 21142e17c..f4821e0e1 100644
--- a/README
+++ b/README
@@ -31,6 +31,28 @@ Zsh is a shell with lots of features.  For a list of some of these, see the
 file FEATURES, and for the latest changes see NEWS.  For more
 details, see the documentation.
 
+Incompatibilities since 5.9
+---------------------------
+
+The line editor's default keymap is now the "emacs" keymap regardless of the
+value of the environment variables $VISUAL and $EDITOR.  This only affects you
+if your $VISUAL or $EDITOR environment variable is set to a value that
+contains the string "vi".  To get the previous behaviour, add
+.
+    bindkey -v
+.
+or, if your $VISUAL and $EDITOR environment variables vary,
+.
+    if [[ ${VISUAL:-${EDITOR:-emacs}} == *vi* ]]; then
+        bindkey -v
+    else
+        bindkey -e
+    fi
+.
+to your .zshrc file.  These snippets are compatible with previous
+versions of the shell.
+
 Incompatibilities since 5.8.1
 -----------------------------
 
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index d90838f03..67a5351fd 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1445,20 +1445,14 @@ default_bindings(void)
 	}
 
     /* Put the keymaps in the right namespace.  The "main" keymap  *
-     * will be linked to the "emacs" keymap, except that if VISUAL *
-     * or EDITOR contain the string "vi" then it will be linked to *
-     * the "viins" keymap.                                         */
+     * will be linked to the "emacs" keymap.                       */
     linkkeymap(vmap, "viins", 0);
     linkkeymap(emap, "emacs", 0);
     linkkeymap(amap, "vicmd", 0);
     linkkeymap(oppmap, "viopp", 0);
     linkkeymap(vismap, "visual", 0);
     linkkeymap(smap, ".safe", 1);
-    if (((ed = zgetenv("VISUAL")) && strstr(ed, "vi")) ||
-	((ed = zgetenv("EDITOR")) && strstr(ed, "vi")))
-	linkkeymap(vmap, "main", 0);
-    else
-	linkkeymap(emap, "main", 0);
+    linkkeymap(emap, "main", 0);
 
     /* the .safe map cannot be modified or deleted */
     smap->flags |= KM_IMMUTABLE;
]]]




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