Skip to content

Commit 1f28b4c

Browse files
committed
patch 8.0.0787: cannot send CTRL-W command to terminal job
Problem: Cannot send CTRL-W command to terminal job. Solution: Make CTRL-W . a prefex for sending a key to the job.
1 parent 8bcc99b commit 1f28b4c

4 files changed

Lines changed: 54 additions & 19 deletions

File tree

runtime/doc/terminal.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 24
1+
*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 28
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -33,22 +33,27 @@ Or to run a debugger: >
3333
The job runs asynchronously from Vim, the window will be updated to show
3434
output from the job, also while editing in any other window.
3535

36+
Typing ~
37+
3638
When the keyboard focus is in the terminal window, typed keys will be send to
37-
the job. This uses a pty when possible.
39+
the job. This uses a pty when possible. You can click outside of the
40+
terminal window to move keyboard focus elsewhere.
41+
42+
Navigate between windows with CTRL-W commands. E.g. CTRL-W CTRL-W moves focus
43+
to the next window. Use "CTRL-W :" to edit an Ex command. Use "CTRL-W ." to
44+
send a CTRL-W to the job in the terminal.
3845

39-
Navigate between windows with CTRL-W commands (and mouse).
40-
E.g. CTRL-W CTRL-W moves focus to the next window.
41-
Use "CTRL-W :" to edit an Ex command.
46+
See option 'termkey' for specifying another key that precedes a Vim command.
47+
Typing 'termkey' twice sends 'termkey' to the job.
4248

43-
See option 'termkey' for specifying the key that precedes a Vim command.
44-
Default is CTRL-W.
49+
Size ~
4550

4651
See option 'termsize' for controlling the size of the terminal window.
4752
(TODO: scrolling when the terminal is larger than the window)
4853

4954
Syntax ~
5055

51-
:ter[minal][!] [command] *:ter* *:terminal*
56+
:ter[minal] [command] *:ter* *:terminal*
5257
Open a new terminal window.
5358

5459
If [command] is provided run it as a job and connect

src/option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ static struct vimoption options[] =
27732773
{"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
27742774
#ifdef FEAT_TERMINAL
27752775
(char_u *)VAR_WIN, PV_TK,
2776-
{(char_u *)"\x17", (char_u *)NULL}
2776+
{(char_u *)"", (char_u *)NULL}
27772777
#else
27782778
(char_u *)NULL, PV_NONE,
27792779
{(char_u *)NULL, (char_u *)0L}

src/terminal.c

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
* while, if the terminal window is visible, the screen contents is drawn.
3434
*
3535
* TODO:
36+
* - To set BS correctly, check get_stty(); Pass the fd of the pty.
3637
* - include functions from #1871
3738
* - do not store terminal buffer in viminfo. Or prefix term:// ?
38-
* - Make CTRL-W . send CTRL-W to terminal?
3939
* - Add a scrollback buffer (contains lines to scroll off the top).
4040
* Can use the buf_T lines, store attributes somewhere else?
4141
* - When the job ends:
@@ -50,7 +50,6 @@
5050
* - when closing window and job has not ended, make terminal hidden?
5151
* - don't allow exiting Vim when a terminal is still running a job
5252
* - use win_del_lines() to make scroll-up efficient.
53-
* - command line completion for :terminal
5453
* - add test for giving error for invalid 'termsize' value.
5554
* - support minimal size when 'termsize' is "rows*cols".
5655
* - support minimal size when 'termsize' is empty?
@@ -458,6 +457,24 @@ term_convert_key(int c, char *buf)
458457
return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
459458
}
460459

460+
/*
461+
* Get a key from the user without mapping.
462+
* TODO: use terminal mode mappings.
463+
*/
464+
static int
465+
term_vgetc()
466+
{
467+
int c;
468+
469+
++no_mapping;
470+
++allow_keys;
471+
got_int = FALSE;
472+
c = vgetc();
473+
--no_mapping;
474+
--allow_keys;
475+
return c;
476+
}
477+
461478
/*
462479
* Wait for input and send it to the job.
463480
* Return when the start of a CTRL-W command is typed or anything else that
@@ -481,17 +498,28 @@ terminal_loop(void)
481498
/* TODO: skip screen update when handling a sequence of keys. */
482499
update_screen(0);
483500
update_cursor(curbuf->b_term, FALSE);
484-
++no_mapping;
485-
++allow_keys;
486-
got_int = FALSE;
487-
c = vgetc();
488-
--no_mapping;
489-
--allow_keys;
501+
c = term_vgetc();
490502

491503
if (c == (termkey == 0 ? Ctrl_W : termkey))
492504
{
493-
stuffcharReadbuff(Ctrl_W);
494-
return;
505+
#ifdef FEAT_CMDL_INFO
506+
if (add_to_showcmd(c))
507+
out_flush();
508+
#endif
509+
c = term_vgetc();
510+
#ifdef FEAT_CMDL_INFO
511+
clear_showcmd();
512+
#endif
513+
514+
if (termkey == 0 && c == '.')
515+
/* "CTRL-W .": send CTRL-W to the job */
516+
c = Ctrl_W;
517+
else if (termkey == 0 || c != termkey)
518+
{
519+
stuffcharReadbuff(Ctrl_W);
520+
stuffcharReadbuff(c);
521+
return;
522+
}
495523
}
496524

497525
/* Catch keys that need to be handled as in Normal mode. */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
787,
772774
/**/
773775
786,
774776
/**/

0 commit comments

Comments
 (0)