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