diff --git a/NEWS b/NEWS index c7fa1593f..18f5fabfa 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Corrected rounding of floating point values by ksh's printf %f formatting operator. Fix contributed by @hyenias. +- The forward-delete key now works as expected in emacs and vi editing modes. + 2020-09-11: - The 'command' regular builtin utility (which runs a simple command, removing diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index 56e3fb058..81ba527a9 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -1109,6 +1109,19 @@ static int escape(register Emacs_t* ep,register genchar *out,int count) case 'Y': ed_ungetchar(ep->ed,cntl('E')); return(-1); + case '3': + if(ed_getchar(ep->ed,1)=='~') + { /* + * VT220 forward-delete key. + * Since ERASECHAR and EOFCHAR are usually both mapped to ^D, we + * should only issue ERASECHAR if there is something to delete, + * otherwise forward-delete on empty line will terminate the shell. + */ + if(cur < eol) + ed_ungetchar(ep->ed,ERASECHAR); + return(-1); + } + /* FALLTHROUGH */ default: ed_ungetchar(ep->ed,i); } diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index f377e2c6a..5bb5047ba 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -1606,6 +1606,7 @@ static int mvcursor(register Vi_t* vp,register int motion) register int tcur_virt; register int incr = -1; register int bound = 0; + int c; switch(motion) { @@ -1632,7 +1633,14 @@ static int mvcursor(register Vi_t* vp,register int motion) break; case '[': - switch(motion=getcount(vp,ed_getchar(vp->ed,-1))) + c = ed_getchar(vp->ed,-1); + if(c=='3' && ed_getchar(vp->ed,-1)=='~') + { + /* VT220 forward-delete key */ + ed_ungetchar(vp->ed,'x'); + return(1); + } + switch(motion=getcount(vp,c)) { case 'A': #if SHOPT_EDPREDICT diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 1cc3e4a62..a98039c05 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -4597,6 +4597,11 @@ operate from any place on the line Neither the `RETURN' nor the `LINE FEED' key is entered after edit commands except when noted. .PP +The \fBM-[\fR multi-character commands below are DEC VT220 escape sequences +generated by keys on modern PC/Mac keyboards, such as the arrow keys. +You could type them directly but they are meant to recognize the keys +in question, which are indicated in parentheses. +.PP .PD 0 .TP 10 .BI ^F @@ -4604,7 +4609,7 @@ Move cursor forward (right) one character. .PP .TP 10 .BI M-[C -Move cursor forward (right) one character. +(Right arrow) Same as \fB^F\fR. .PP .TP 10 .BI M-f @@ -4620,7 +4625,7 @@ Move cursor backward (left) one character. .PP .TP 10 .BI M-[D -Move cursor backward (left) one character. +(Left arrow) Same as \fB^B\fR. .PP .TP 10 .BI M-b @@ -4632,15 +4637,19 @@ Move cursor to start of line. .PP .TP 10 .BI M-[H -Move cursor to start of line. +(Home) Same as \fB^A\fR. .PP .TP 10 .BI ^E Move cursor to end of line. .PP .TP 10 +.BI M-[F +(End) Same as \fB^E\fR. +.PP +.TP 10 .BI M-[Y -Move cursor to end of line. +Same as \fB^E\fR. .PP .TP 10 .BI ^] char @@ -4664,9 +4673,7 @@ Interchange the cursor and mark. by the .IR stty (1) command, usually -.B ^H -or -.BR # .) +.B ^H .) Delete previous character. .PP .TP 10 @@ -4686,6 +4693,10 @@ editing features (if any). Delete current character. .PP .TP 10 +.BI M-[3~ +(Forward delete) Same as \fB^D\fR. +.PP +.TP 10 .BI M-d Delete current word. .PP @@ -4748,15 +4759,16 @@ Push the region from the cursor to the mark on the stack. .I kill (User defined kill character as defined by the stty command, usually -.B ^G -or -.BR @ .) +.B ^U .) Kill the entire current line. If two .I kill characters are entered in succession, all kill characters from then on cause a line feed (useful when using paper terminals). +A subsequent pair of +.I kill +characters undoes this change. .PP .TP 10 .BI ^Y @@ -4805,6 +4817,7 @@ Moves back one line when not on the first line of a multi-line command. .PP .TP 10 .BI M-[A +(Up arrow) If the cursor is at the end of the line, it is equivalent to .B ^R with @@ -4812,7 +4825,7 @@ with set to the contents of the current line. Otherwise, it is equivalent to -.BR ^P. +.BR ^P . .PP .TP 10 .BI M-< @@ -4832,8 +4845,9 @@ the next command line forward in time is accessed. .PP .TP 10 .BI M-[B +(Down arrow) Equivalent to -.BR ^N. +.BR ^N . .PP .TP 10 .BI ^R string