2017-07-28 14:48 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> Patch 8.0.0787
> Problem:    Cannot send CTRL-W command to terminal job.
> Solution:   Make CTRL-W . a prefex for sending a key to the job.
> Files:      src/terminal.c, runtime/doc/terminal.txt, src/option.c

`<C-w>` used as a prefix is extremely inconvenient and `<C-w>.` is
inconsistent with all software with terminal emulator (i.e. screen and
tmux) I know which use `<C-{smth}>{smth}` by default. This thing is
even more weird given planned “typing 'termkey' twice sends 'termkey'
to the job”.

One of the common use-cases for Neovim terminal feature is replacing
screen and tmux with Neovim. Now imagine that you are running
Vim/shell/any other REPL inside a Vim and want to edit some text. The
`<C-w>` shortcut in this case may be used to correct the last word and
is rather common in my experience and you take it away by default.

This is the second reason why “prefix” key is `<C-\>`. First is
consistency: `<C-\><C-n>` is used to exit to a normal mode from any
other mode in existence, except for getchar() (or one of the internal
functions like vgetc())-based pseudo-modes, or if a plugin had it
deliberately mapped.

Also why there is *no* terminal mode? I am quite surprised that I
can’t do `<C-c><C-c><C-c><Esc><Esc><Esc><C-\><C-n>:` and get to a
command prompt: none of the ways to exit to normal mode work, but with
`set showmode` bottom line *still* looks like if I am in normal mode
while I obviously is not. Also no idea how user will copy text from
the terminal without normal mode (using term_scrape() looks like an
overkill and is obviously harder to use then
`<C-\><C-n>{motion}y{motion}`) or view scrollback.

>
>
> *** ../vim-8.0.0786/src/terminal.c      2017-07-27 22:14:55.301968245 +0200
> --- src/terminal.c      2017-07-28 12:10:33.883684540 +0200
> ***************
> *** 33,41 ****
>    * while, if the terminal window is visible, the screen contents is drawn.
>    *
>    * TODO:
>    * - include functions from #1871
>    * - do not store terminal buffer in viminfo.  Or prefix term:// ?
> -  * - Make CTRL-W . send CTRL-W to terminal?
>    * - Add a scrollback buffer (contains lines to scroll off the top).
>    *   Can use the buf_T lines, store attributes somewhere else?
>    * - When the job ends:
> --- 33,41 ----
>    * while, if the terminal window is visible, the screen contents is drawn.
>    *
>    * TODO:
> +  * - To set BS correctly, check get_stty(); Pass the fd of the pty.
>    * - include functions from #1871
>    * - do not store terminal buffer in viminfo.  Or prefix term:// ?
>    * - Add a scrollback buffer (contains lines to scroll off the top).
>    *   Can use the buf_T lines, store attributes somewhere else?
>    * - When the job ends:
> ***************
> *** 50,56 ****
>    * - when closing window and job has not ended, make terminal hidden?
>    * - don't allow exiting Vim when a terminal is still running a job
>    * - use win_del_lines() to make scroll-up efficient.
> -  * - command line completion for :terminal
>    * - add test for giving error for invalid 'termsize' value.
>    * - support minimal size when 'termsize' is "rows*cols".
>    * - support minimal size when 'termsize' is empty?
> --- 50,55 ----
> ***************
> *** 459,464 ****
> --- 458,481 ----
>   }
>
>   /*
> +  * Get a key from the user without mapping.
> +  * TODO: use terminal mode mappings.
> +  */
> +     static int
> + term_vgetc()
> + {
> +     int c;
> +
> +     ++no_mapping;
> +     ++allow_keys;
> +     got_int = FALSE;
> +     c = vgetc();
> +     --no_mapping;
> +     --allow_keys;
> +     return c;
> + }
> +
> + /*
>    * Wait for input and send it to the job.
>    * Return when the start of a CTRL-W command is typed or anything else that
>    * should be handled as a Normal mode command.
> ***************
> *** 481,497 ****
>         /* TODO: skip screen update when handling a sequence of keys. */
>         update_screen(0);
>         update_cursor(curbuf->b_term, FALSE);
> !       ++no_mapping;
> !       ++allow_keys;
> !       got_int = FALSE;
> !       c = vgetc();
> !       --no_mapping;
> !       --allow_keys;
>
>         if (c == (termkey == 0 ? Ctrl_W : termkey))
>         {
> !           stuffcharReadbuff(Ctrl_W);
> !           return;
>         }
>
>         /* Catch keys that need to be handled as in Normal mode. */
> --- 498,525 ----
>         /* TODO: skip screen update when handling a sequence of keys. */
>         update_screen(0);
>         update_cursor(curbuf->b_term, FALSE);
> !       c = term_vgetc();
>
>         if (c == (termkey == 0 ? Ctrl_W : termkey))
>         {
> ! #ifdef FEAT_CMDL_INFO
> !           if (add_to_showcmd(c))
> !               out_flush();
> ! #endif
> !           c = term_vgetc();
> ! #ifdef FEAT_CMDL_INFO
> !           clear_showcmd();
> ! #endif
> !
> !           if (termkey == 0 && c == '.')
> !               /* "CTRL-W .": send CTRL-W to the job */
> !               c = Ctrl_W;
> !           else if (termkey == 0 || c != termkey)
> !           {
> !               stuffcharReadbuff(Ctrl_W);
> !               stuffcharReadbuff(c);
> !               return;
> !           }
>         }
>
>         /* Catch keys that need to be handled as in Normal mode. */
> *** ../vim-8.0.0786/runtime/doc/terminal.txt    2017-07-24 22:26:39.757774872 
> +0200
> --- runtime/doc/terminal.txt    2017-07-28 12:07:47.008833461 +0200
> ***************
> *** 1,4 ****
> ! *terminal.txt*        For Vim version 8.0.  Last change: 2017 Jul 24
>
>
>                   VIM REFERENCE MANUAL    by Bram Moolenaar
> --- 1,4 ----
> ! *terminal.txt*        For Vim version 8.0.  Last change: 2017 Jul 28
>
>
>                   VIM REFERENCE MANUAL    by Bram Moolenaar
> ***************
> *** 33,54 ****
>   The job runs asynchronously from Vim, the window will be updated to show
>   output from the job, also  while editing in any other window.
>
>   When the keyboard focus is in the terminal window, typed keys will be send 
> to
> ! the job.  This uses a pty when possible.
>
> ! Navigate between windows with CTRL-W commands (and mouse).
> ! E.g. CTRL-W CTRL-W moves focus to the next window.
> ! Use "CTRL-W :" to edit an Ex command.
>
> ! See option 'termkey' for specifying the key that precedes a Vim command.
> ! Default is CTRL-W.
>
>   See option 'termsize' for controlling the size of the terminal window.
>   (TODO: scrolling when the terminal is larger than the window)
>
>   Syntax ~
>
> ! :ter[minal][!] [command]                      *:ter* *:terminal*
>                         Open a new terminal window.
>
>                         If [command] is provided run it as a job and connect
> --- 33,59 ----
>   The job runs asynchronously from Vim, the window will be updated to show
>   output from the job, also  while editing in any other window.
>
> + Typing ~
> +
>   When the keyboard focus is in the terminal window, typed keys will be send 
> to
> ! the job.  This uses a pty when possible.  You can click outside of the
> ! terminal window to move keyboard focus elsewhere.
> !
> ! Navigate between windows with CTRL-W commands.  E.g. CTRL-W CTRL-W moves 
> focus
> ! to the next window.  Use "CTRL-W :" to edit an Ex command.  Use "CTRL-W ." 
> to
> ! send a CTRL-W to the job in the terminal.
>
> ! See option 'termkey' for specifying another key that precedes a Vim command.
> ! Typing 'termkey' twice sends 'termkey' to the job.
>
> ! Size ~
>
>   See option 'termsize' for controlling the size of the terminal window.
>   (TODO: scrolling when the terminal is larger than the window)
>
>   Syntax ~
>
> ! :ter[minal] [command]                         *:ter* *:terminal*
>                         Open a new terminal window.
>
>                         If [command] is provided run it as a job and connect
> *** ../vim-8.0.0786/src/option.c        2017-07-24 20:02:56.824589410 +0200
> --- src/option.c        2017-07-28 12:09:58.619927317 +0200
> ***************
> *** 2773,2779 ****
>       {"termkey", "tk",     P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
>   #ifdef FEAT_TERMINAL
>                             (char_u *)VAR_WIN, PV_TK,
> !                           {(char_u *)"\x17", (char_u *)NULL}
>   #else
>                             (char_u *)NULL, PV_NONE,
>                             {(char_u *)NULL, (char_u *)0L}
> --- 2773,2779 ----
>       {"termkey", "tk",     P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
>   #ifdef FEAT_TERMINAL
>                             (char_u *)VAR_WIN, PV_TK,
> !                           {(char_u *)"", (char_u *)NULL}
>   #else
>                             (char_u *)NULL, PV_NONE,
>                             {(char_u *)NULL, (char_u *)0L}
> *** ../vim-8.0.0786/src/version.c       2017-07-28 13:44:56.012254793 +0200
> --- src/version.c       2017-07-28 13:46:32.911574356 +0200
> ***************
> *** 771,772 ****
> --- 771,774 ----
>   {   /* Add new patch number below this line */
> + /**/
> +     787,
>   /**/
>
> --
> press CTRL-ALT-DEL for more information
>
>  /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
> ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\  an exciting new programming language -- http://www.Zimbu.org        ///
>  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups 
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui