Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 1 | *terminal.txt* For Vim version 8.0. Last change: 2017 Jul 24 |
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 ~ |
Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 50 | |
| 51 | :ter[minal][!] [command] *:ter* *:terminal* |
| 52 | Open a new terminal window. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 53 | |
| 54 | If [command] is provided run it as a job and connect |
| 55 | the input and output to the terminal. |
| 56 | If [command] is not given the 'shell' option is used. |
| 57 | |
| 58 | A new buffer will be created, using [command] or |
| 59 | 'shell' as the name. If a buffer by this name already |
| 60 | exists a number is added in parenthesis. |
| 61 | E.g. if "gdb" exists the second terminal buffer will |
| 62 | use "gdb (1)". |
| 63 | |
| 64 | The window can be closed, in which case the buffer |
| 65 | becomes hidden. The command will not be stopped. The |
| 66 | `:buffer` command can be used to turn the current |
| 67 | window into a terminal window, using the existing |
| 68 | buffer. If there are unsaved changes this fails, use |
| 69 | ! to force, as usual. |
| 70 | |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 71 | When the buffer associated with the terminal is wiped out the job is killed, |
| 72 | similar to calling `job_stop(job, "kill")` |
| 73 | |
| 74 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 75 | Resizing ~ |
| 76 | |
| 77 | The size of the terminal can be in one of three modes: |
| 78 | |
| 79 | 1. The 'termsize' option is empty: The terminal size follows the window size. |
| 80 | The minimal size is 2 screen lines with 10 cells. |
| 81 | |
| 82 | 2. The 'termsize' option is "rows*cols", where "rows" is the minimal number of |
Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 83 | screen rows and "cols" is the minimal number of cells. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 84 | |
| 85 | 3. The 'termsize' option is "rowsXcols" (where the x is upper or lower case). |
| 86 | The terminal size is fixed to the specified number of screen lines and |
| 87 | cells. If the window is bigger there will be unused empty space. |
| 88 | |
| 89 | If the window is smaller than the terminal size, only part of the terminal can |
| 90 | be seen (the lower-left part). |
| 91 | |
| 92 | The |term_getsize()| function can be used to get the current size of the |
| 93 | terminal. |term_setsize()| can be used only when in the first or second mode, |
| 94 | not when 'termsize' is "rowsXcols". |
| 95 | |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 96 | |
| 97 | Unix ~ |
| 98 | |
| 99 | On Unix a pty is used to make it possible to run all kinds of commands. You |
| 100 | can even run Vim in the terminal! That's used for debugging, see below. |
| 101 | |
| 102 | |
| 103 | MS-Windows ~ |
| 104 | |
Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 105 | On MS-Windows winpty is used to make it possible to run all kind of commands. |
| 106 | Obviously, they must be commands that run in a terminal, not open their own |
| 107 | window. |
| 108 | |
| 109 | You need the following two files from winpty: |
| 110 | |
| 111 | winpty.dll |
| 112 | winpty-agent.exe |
| 113 | |
| 114 | You can download them from the following page: |
| 115 | |
| 116 | https://github.com/rprichard/winpty |
| 117 | |
| 118 | Just put the files somewhere in your PATH. |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 119 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 120 | ============================================================================== |
| 121 | 2. Remote testing *terminal-testing* |
| 122 | |
| 123 | Most Vim tests execute a script inside Vim. For some tests this does not |
| 124 | work, running the test interferes with the code being tested. To avoid this |
| 125 | Vim is executed in a terminal window. The test sends keystrokes to it and |
| 126 | inspects the resulting screen state. |
| 127 | |
| 128 | Functions ~ |
| 129 | |
| 130 | term_sendkeys() send keystrokes to a terminal |
| 131 | term_wait() wait for screen to be updated |
| 132 | term_scrape() inspect terminal screen |
| 133 | |
| 134 | |
| 135 | ============================================================================== |
| 136 | 3. Debugging *terminal-debug* |
| 137 | |
| 138 | The Terminal debugging plugin can be used to debug a program with gdb and view |
| 139 | the source code in a Vim window. For example: > |
| 140 | |
| 141 | :TermDebug vim |
| 142 | |
| 143 | This opens three windows: |
| 144 | - A terminal window in which "gdb vim" is executed. Here you can directly |
| 145 | interact with gdb. |
| 146 | - A terminal window for the executed program. When "run" is used in gdb the |
| 147 | program I/O will happen in this window, so that it does not interfere with |
| 148 | controlling gdb. |
| 149 | - A normal Vim window used to show the source code. When gdb jumps to a |
| 150 | source file location this window will display the code, if possible. Values |
| 151 | of variables can be inspected, breakpoints set and cleared, etc. |
| 152 | |
| 153 | This uses two terminal windows. To open the gdb window: > |
| 154 | :term gdb [arguments] |
| 155 | To open the terminal to run the tested program |term_open()| is used. |
| 156 | |
| 157 | TODO |
| 158 | |
| 159 | |
| 160 | vim:tw=78:ts=8:ft=help:norl: |