Index | Thread | Search

From:
Walter Alejandro Iglesias <wai@roquesor.com>
Subject:
Adding vi command bindings to sftp(1)
To:
Stuart Henderson <stu.lists@spacehopper.org>
Cc:
misc@openbsd.org, tech@openbsd.org
Date:
Fri, 19 Dec 2025 16:29:24 +0100

Download raw body.

Thread
  • Walter Alejandro Iglesias:

    Adding vi command bindings to sftp(1)

I got it.  Ccing to tech@.

> I noticed that adding the following line to the bindings in
> 'src/usr.bin/ssh/sftp.c' makes vi command mode work:
> 
>   el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);
> 
> But I couldn't figured out so far how to add a conditional to apply that
> binding only in vi mode.  The following does not work:
> 
> (src/usr.bin/ssh/sftp.c)
> -----------------------------------------
> const char editor[2];
> 
> 	if (!batchmode && isatty(STDIN_FILENO)) {
> 
> 		[...]
> 
> 		if (el_get(el, EL_EDITOR, editor) == '0')
> 			printf("Editor: %s\n", editor);
> 
> 		if (strncmp(editor, "vi", 2) == 0)
> 			el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);
> 	}
> 
> ----------------------------------------------------------------------------
> 
> Am I using el_get() in a wrong way?
> 

Index: sftp.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sftp.c,v
diff -u -p -u -p -r1.247 sftp.c
--- sftp.c	13 Oct 2025 00:54:29 -0000	1.247
+++ sftp.c	19 Dec 2025 15:21:45 -0000
@@ -2210,6 +2210,7 @@ interactive_loop(struct sftp_conn *conn,
 	HistEvent hev;
 	extern char *__progname;
 	struct complete_ctx complete_ctx;
+	const char *editor;
 
 	if (!batchmode && isatty(STDIN_FILENO)) {
 		if ((el = el_init(__progname, stdin, stdout, stderr)) == NULL)
@@ -2239,6 +2240,11 @@ interactive_loop(struct sftp_conn *conn,
 		el_set(el, EL_BIND, "\\e\\e[D", "ed-prev-word", NULL);
 		/* make ^w match ksh behaviour */
 		el_set(el, EL_BIND, "^w", "ed-delete-prev-word", NULL);
+
+		/* Vi command mode */
+		el_get(el, EL_EDITOR, &editor);
+		if (editor[0] == 'v')
+			el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);
 	}
 
 	if ((remote_path = sftp_realpath(conn, ".")) == NULL)




-- 
Walter