Re: ksh: allow editing empty line with 'v' in vi-mode

"Uwe Werler" <[email protected]> Thu, 30 Jul 2026 22:41:05 +0200
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
On Thu Jul 30, 2026 at 8:21 PM CEST, Johannes Thyssen Tishman wrote:
> Sometimes, when I know I'm gonna write a long command, I like to use vi
> mode's 'v' function to edit the command in my editor. Currently this
> only works to modify a command, i.e., when the command line is not
> empty, e.g.:
>
>   $ abcd^[v     --> Opens editor with 'abcd'
>
> Because of this, I've now acquired the (bad) habit of typing nonsense
> before using this function, such that I can start writing the command
> from scratch in the editor. The diff below allows using this function
> with an empty command line:
>
>   $ ^[v         --> Opens empty editor
>
> I tried adding tests, e.g., by setting VISUAL=3Dcat and HISTFILE=3D`mktem=
p
> ...`, but I couldn't get them to work. However, both the examples above,
> as well as when passing a number from the command history (see fc -l),
> e.g.,
>
>   $ ^[10v       --> Opens 10th command in history
>
> are still working fine.
>
> Index: vi.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> RCS file: /cvs/src/bin/ksh/vi.c,v
> diff -u -p -r1.70 vi.c
> --- vi.c	22 May 2026 18:11:08 -0000	1.70
> +++ vi.c	30 Jul 2026 18:05:10 -0000
> @@ -964,8 +964,6 @@ vi_cmd(int argcnt, const char *cmd)
>  			break;
> =20
>  		case 'v':
> -			if (es->linelen =3D=3D 0 && argcnt =3D=3D 0)
> -				return -1;
>  			if (!argcnt) {
>  				if (modified) {
>  					es->cbuf[es->linelen] =3D '\0';

+++ for this diff I already proposed in 2022:

https://marc.info/?l=3Dopenbsd-tech&m=3D166196351223367&w=3D2


--=20
With kind regards / Me=C3=B0 bestu kve=C3=B0ju / Mit freundlichen Gr=C3=BC=
=C3=9Fen

Uwe Werler