Index | Thread | Search

From:
"Uwe Werler" <uwe@werler.is>
Subject:
Re: ksh: allow editing empty line with 'v' in vi-mode
To:
"Johannes Thyssen Tishman" <jtt@openbsd.org>, <tech@openbsd.org>
Date:
Thu, 30 Jul 2026 22:55:18 +0200

Download raw body.

Thread
On Thu Jul 30, 2026 at 10:41 PM CEST, Uwe Werler wrote:
> 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=cat and HISTFILE=`mktemp
>> ...`, 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
>> ===================================================================
>> 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;
>>  
>>  		case 'v':
>> -			if (es->linelen == 0 && argcnt == 0)
>> -				return -1;
>>  			if (!argcnt) {
>>  				if (modified) {
>>  					es->cbuf[es->linelen] = '\0';
>
> +++ for this diff I already proposed in 2022:
>
> https://marc.info/?l=openbsd-tech&m=166196351223367&w=2

and here's another one I once proposed:

https://marc.info/?l=openbsd-tech&m=166681423915767&w=2

-- 
With kind regards / Með bestu kveðju / Mit freundlichen Grüßen

Uwe Werler