Bram Moolenaar | 74675a6 | 2017-07-15 13:53:23 +0200 | [diff] [blame] | 1 | *terminal.txt* For Vim version 8.0. Last change: 2017 Jul 15 |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
| 7 | Terminal window support *terminal* |
| 8 | |
| 9 | |
| 10 | WARNING: THIS IS ONLY PARTLY IMPLEMENTED, ANYTHING CAN STILL CHANGE |
| 11 | |
| 12 | |
| 13 | 1. Basic use |terminal-use| |
| 14 | 2. Remote testing |terminal-testing| |
| 15 | 3. Debugging |terminal-debug| |
| 16 | |
| 17 | {Vi does not have any of these commands} |
| 18 | |
| 19 | ============================================================================== |
| 20 | 1. Basic use *terminal-use* |
| 21 | |
| 22 | This feature is for running a terminal emulator in a Vim window. A job can be |
| 23 | started connected to the terminal emulator. For example, to run a shell: > |
| 24 | :term bash |
| 25 | |
| 26 | Or to run a debugger: > |
| 27 | :term gdb vim |
| 28 | |
| 29 | The job runs asynchronously from Vim, the window will be updated to show |
| 30 | output from the job, also while editing in any other window. |
| 31 | |
| 32 | When the keyboard focus is in the terminal window, typed keys will be send to |
| 33 | the job. This uses a pty when possible. |
| 34 | |
| 35 | Navigate between windows with CTRL-W commands (and mouse). |
| 36 | E.g. CTRL-W CTRL-W moves focus to the next window. |
| 37 | |
Bram Moolenaar | 74675a6 | 2017-07-15 13:53:23 +0200 | [diff] [blame] | 38 | See option 'termkey' for specifying the key that precedes a Vim command. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 39 | Default is CTRL-W. |
| 40 | |
Bram Moolenaar | 74675a6 | 2017-07-15 13:53:23 +0200 | [diff] [blame] | 41 | See option 'termsize' for controlling the size of the terminal window. |
| 42 | (TODO: scrolling when the terminal is larger than the window) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 43 | |
| 44 | Syntax ~ |
| 45 | *:ter* *:terminal* |
| 46 | :terminal[!] [command] Open a new terminal window. |
| 47 | |
| 48 | If [command] is provided run it as a job and connect |
| 49 | the input and output to the terminal. |
| 50 | If [command] is not given the 'shell' option is used. |
| 51 | |
| 52 | A new buffer will be created, using [command] or |
| 53 | 'shell' as the name. If a buffer by this name already |
| 54 | exists a number is added in parenthesis. |
| 55 | E.g. if "gdb" exists the second terminal buffer will |
| 56 | use "gdb (1)". |
| 57 | |
| 58 | The window can be closed, in which case the buffer |
| 59 | becomes hidden. The command will not be stopped. The |
| 60 | `:buffer` command can be used to turn the current |
| 61 | window into a terminal window, using the existing |
| 62 | buffer. If there are unsaved changes this fails, use |
| 63 | ! to force, as usual. |
| 64 | |
| 65 | Resizing ~ |
| 66 | |
| 67 | The size of the terminal can be in one of three modes: |
| 68 | |
| 69 | 1. The 'termsize' option is empty: The terminal size follows the window size. |
| 70 | The minimal size is 2 screen lines with 10 cells. |
| 71 | |
| 72 | 2. The 'termsize' option is "rows*cols", where "rows" is the minimal number of |
| 73 | screen rows and "cols" is the minial number of cells. |
| 74 | |
| 75 | 3. The 'termsize' option is "rowsXcols" (where the x is upper or lower case). |
| 76 | The terminal size is fixed to the specified number of screen lines and |
| 77 | cells. If the window is bigger there will be unused empty space. |
| 78 | |
| 79 | If the window is smaller than the terminal size, only part of the terminal can |
| 80 | be seen (the lower-left part). |
| 81 | |
| 82 | The |term_getsize()| function can be used to get the current size of the |
| 83 | terminal. |term_setsize()| can be used only when in the first or second mode, |
| 84 | not when 'termsize' is "rowsXcols". |
| 85 | |
| 86 | ============================================================================== |
| 87 | 2. Remote testing *terminal-testing* |
| 88 | |
| 89 | Most Vim tests execute a script inside Vim. For some tests this does not |
| 90 | work, running the test interferes with the code being tested. To avoid this |
| 91 | Vim is executed in a terminal window. The test sends keystrokes to it and |
| 92 | inspects the resulting screen state. |
| 93 | |
| 94 | Functions ~ |
| 95 | |
| 96 | term_sendkeys() send keystrokes to a terminal |
| 97 | term_wait() wait for screen to be updated |
| 98 | term_scrape() inspect terminal screen |
| 99 | |
| 100 | |
| 101 | ============================================================================== |
| 102 | 3. Debugging *terminal-debug* |
| 103 | |
| 104 | The Terminal debugging plugin can be used to debug a program with gdb and view |
| 105 | the source code in a Vim window. For example: > |
| 106 | |
| 107 | :TermDebug vim |
| 108 | |
| 109 | This opens three windows: |
| 110 | - A terminal window in which "gdb vim" is executed. Here you can directly |
| 111 | interact with gdb. |
| 112 | - A terminal window for the executed program. When "run" is used in gdb the |
| 113 | program I/O will happen in this window, so that it does not interfere with |
| 114 | controlling gdb. |
| 115 | - A normal Vim window used to show the source code. When gdb jumps to a |
| 116 | source file location this window will display the code, if possible. Values |
| 117 | of variables can be inspected, breakpoints set and cleared, etc. |
| 118 | |
| 119 | This uses two terminal windows. To open the gdb window: > |
| 120 | :term gdb [arguments] |
| 121 | To open the terminal to run the tested program |term_open()| is used. |
| 122 | |
| 123 | TODO |
| 124 | |
| 125 | |
| 126 | vim:tw=78:ts=8:ft=help:norl: |