Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 1 | *terminal.txt* For Vim version 8.0. Last change: 2017 Sep 17 |
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} |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 22 | {only available when compiled with the |+terminal| feature} |
| 23 | |
| 24 | The terminal feature requires the |+multi_byte|, |+job| and |+channel| features. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 25 | |
| 26 | ============================================================================== |
| 27 | 1. Basic use *terminal-use* |
| 28 | |
| 29 | This feature is for running a terminal emulator in a Vim window. A job can be |
| 30 | started connected to the terminal emulator. For example, to run a shell: > |
| 31 | :term bash |
| 32 | |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 33 | Or to run build command: > |
| 34 | :term make myprogram |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 35 | |
| 36 | The job runs asynchronously from Vim, the window will be updated to show |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 37 | output from the job, also while editing in another window. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 38 | |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 39 | |
Bram Moolenaar | 1f28b4c | 2017-07-28 13:48:34 +0200 | [diff] [blame] | 40 | Typing ~ |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 41 | *terminal-typing* |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 42 | When the keyboard focus is in the terminal window, typed keys will be sent to |
Bram Moolenaar | 1f28b4c | 2017-07-28 13:48:34 +0200 | [diff] [blame] | 43 | the job. This uses a pty when possible. You can click outside of the |
| 44 | terminal window to move keyboard focus elsewhere. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 45 | |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 46 | CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.: |
| 47 | CTRL-W CTRL-W move focus to the next window |
| 48 | CTRL-W : enter an Ex command |
| 49 | See |CTRL-W| for more commands. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 50 | |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 51 | Special in the terminal window: *CTRL-W_.* *CTRL-W_N* |
| 52 | CTRL-W . send a CTRL-W to the job in the terminal |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 53 | CTRL-W N go to Terminal-Normal mode, see |Terminal-mode| |
| 54 | CTRL-\ CTRL-N go to Terminal-Normal mode, see |Terminal-mode| |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 55 | CTRL-W " {reg} paste register {reg} *CTRL-W_quote* |
| 56 | Also works with the = register to insert the result of |
| 57 | evaluating an expression. |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 58 | CTRL-W CTRL-C ends the job, see below |t_CTRL-W_CTRL-C| |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 59 | |
| 60 | See option 'termkey' for specifying another key instead of CTRL-W that |
| 61 | will work like CTRL-W. However, typing 'termkey' twice sends 'termkey' to |
| 62 | the job. For example: |
| 63 | 'termkey' CTRL-W move focus to the next window |
| 64 | 'termkey' : enter an Ex command |
| 65 | 'termkey' 'termkey' send 'termkey' to the job in the terminal |
| 66 | 'termkey' . send a CTRL-W to the job in the terminal |
| 67 | 'termkey' N go to terminal Normal mode, see below |
| 68 | 'termkey' CTRL-N same as CTRL-W N |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 69 | 'termkey' CTRL-C same as |t_CTRL-W_CTRL-C| |
Bram Moolenaar | 6919819 | 2017-08-05 14:10:48 +0200 | [diff] [blame] | 70 | *t_CTRL-\_CTRL-N* |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 71 | The special key combination CTRL-\ CTRL-N can be used to switch to Normal |
| 72 | mode, just like this works in any other mode. |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 73 | *t_CTRL-W_CTRL-C* |
| 74 | CTRL-W CTRL-C can be typed to forcefully end the job. On MS-Windows a |
| 75 | CTRL-BREAK will also kill the job. |
| 76 | |
| 77 | If you type CTRL-C the effect depends on what the pty has been configured to |
| 78 | do. For simple commands this causes a SIGINT to be sent to the job, which |
| 79 | would end it. Other commands may ignore the SIGINT or handle the CTRL-C |
| 80 | themselves (like Vim does). |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 81 | |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 82 | To change the keys you type use terminal mode mappings, see |:tmap|. |
| 83 | These are defined like any mapping, but apply only when typing keys that are |
| 84 | sent to the job running in the terminal. |
| 85 | |
Bram Moolenaar | 1f28b4c | 2017-07-28 13:48:34 +0200 | [diff] [blame] | 86 | |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 87 | Size and color ~ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 88 | |
Bram Moolenaar | 74675a6 | 2017-07-15 13:53:23 +0200 | [diff] [blame] | 89 | See option 'termsize' for controlling the size of the terminal window. |
| 90 | (TODO: scrolling when the terminal is larger than the window) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 91 | |
Bram Moolenaar | 38baa3e | 2017-09-14 16:10:38 +0200 | [diff] [blame] | 92 | The job running in the terminal can change the colors. The default foreground |
| 93 | and background colors are taken from Vim, the Normal highlight group. |
| 94 | |
| 95 | For a color terminal the 'background' option is used to decide whether the |
| 96 | terminal window will start with a white or black background. |
| 97 | |
| 98 | To use a different color the Terminal highlight group can be used: > |
| 99 | hi Terminal ctermbg=lightgrey ctermfg=blue guibg=lightgrey guifg=blue |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 100 | |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 101 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 102 | Syntax ~ |
Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 103 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 104 | :[range]ter[minal] [options] [command] *:ter* *:terminal* |
Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 105 | Open a new terminal window. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 106 | |
| 107 | If [command] is provided run it as a job and connect |
| 108 | the input and output to the terminal. |
| 109 | If [command] is not given the 'shell' option is used. |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 110 | if [command] is NONE no job is started, the pty of the |
| 111 | terminal can be used by a command like gdb. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 112 | |
| 113 | A new buffer will be created, using [command] or |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 114 | 'shell' as the name, prefixed with a "!". If a buffer |
| 115 | by this name already exists a number is added in |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 116 | parentheses. E.g. if "gdb" exists the second terminal |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 117 | buffer will use "!gdb (1)". |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 118 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 119 | If [range] is given the specified lines are used as |
| 120 | input for the job. It will not be possible to type |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 121 | keys in the terminal window. For MS-Windows see the |
| 122 | ++eof argument below. |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 123 | |
| 124 | Two comma separated numbers are used as "rows,cols". |
| 125 | E.g. `:24,80gdb` opens a terminal with 24 rows and 80 |
| 126 | columns. However, if the terminal window spans the |
| 127 | Vim window with, there is no vertical split, the Vim |
| 128 | window width is used. |
| 129 | *term++close* *term++open* |
| 130 | Supported [options] are: |
| 131 | ++close The terminal window will close |
| 132 | automatically when the job terminates. |
| 133 | ++open When the job terminates and no window |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 134 | shows it, a window will be opened. |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 135 | Note that this can be interruptive. |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 136 | ++curwin Open the terminal in the current |
| 137 | window, do not split the current |
| 138 | window. Fails if the current buffer |
| 139 | cannot be |abandon|ed. |
| 140 | ++hidden Open the terminal in a hidden buffer, |
| 141 | no window will be used. |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 142 | ++rows={height} Use {height} for the terminal window |
| 143 | height. |
| 144 | ++cols={width} Use {width} for the terminal window |
| 145 | width. |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 146 | ++eof={text} when using [range]: text to send after |
| 147 | the last line was written. Cannot |
| 148 | contain white space. A CR is |
| 149 | appended. For MS-Windows the default |
| 150 | is to send CTRL-D. |
Bram Moolenaar | ef68e4f | 2017-09-02 16:28:36 +0200 | [diff] [blame] | 151 | E.g. for a shell use "++eof=exit" and |
| 152 | for Python "++eof=exit()". Special |
| 153 | codes can be used like with `:map`, |
| 154 | e.g. "<C-Z>" for CTRL-Z. |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 155 | |
| 156 | If you want to use more options use the |term_start()| |
| 157 | function. |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 158 | |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 159 | When the buffer associated with the terminal is unloaded or wiped out the job |
| 160 | is killed, similar to calling `job_stop(job, "kill")` |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 161 | |
Bram Moolenaar | e561a7e | 2017-08-29 22:44:59 +0200 | [diff] [blame] | 162 | So long as the job is running the window behaves like it contains a modified |
Bram Moolenaar | ef68e4f | 2017-09-02 16:28:36 +0200 | [diff] [blame] | 163 | buffer. Trying to close the window with `CTRL-W :quit` fails. When using |
| 164 | `CTRL-W :quit!` the job is ended. The text in the window is lost. The buffer |
| 165 | still exists, but getting it in a window with `:buffer` will show an empty |
| 166 | buffer. |
| 167 | |
| 168 | Trying to close the window with `CTRL-W :close` also fails. Using |
| 169 | `CTRL-W :close!` will close the window and make the buffer hidden. |
Bram Moolenaar | e561a7e | 2017-08-29 22:44:59 +0200 | [diff] [blame] | 170 | |
| 171 | You can use `CTRL-W :hide` to close the terminal window and make the buffer |
| 172 | hidden, the job keeps running. The `:buffer` command can be used to turn the |
| 173 | current window into a terminal window. If there are unsaved changes this |
| 174 | fails, use ! to force, as usual. |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 175 | |
| 176 | To have a background job run without a window, and open the window when it's |
| 177 | done, use options like this: > |
| 178 | :term ++hidden ++open make |
| 179 | Note that the window will open at an unexpected moment, this will interrupt |
| 180 | what you are doing. |
| 181 | |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 182 | *E947* *E948* |
Bram Moolenaar | 78712a7 | 2017-08-05 14:50:12 +0200 | [diff] [blame] | 183 | So long as the job is running, the buffer is considered modified and Vim |
| 184 | cannot be quit easily, see |abandon|. |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 185 | |
| 186 | When the job has finished and no changes were made to the buffer: closing the |
| 187 | window will wipe out the buffer. |
| 188 | |
| 189 | Before changes can be made to a terminal buffer, the 'modifiable' option must |
| 190 | be set. This is only possible when the job has finished. At the first change |
| 191 | the buffer will become a normal buffer and the highlighting is removed. |
| 192 | You may want to change the buffer name with |:file| to be able to write, since |
| 193 | the buffer name will still be set to the command. |
| 194 | |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 195 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 196 | Resizing ~ |
| 197 | |
| 198 | The size of the terminal can be in one of three modes: |
| 199 | |
| 200 | 1. The 'termsize' option is empty: The terminal size follows the window size. |
| 201 | The minimal size is 2 screen lines with 10 cells. |
| 202 | |
| 203 | 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] | 204 | screen rows and "cols" is the minimal number of cells. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 205 | |
| 206 | 3. The 'termsize' option is "rowsXcols" (where the x is upper or lower case). |
| 207 | The terminal size is fixed to the specified number of screen lines and |
| 208 | cells. If the window is bigger there will be unused empty space. |
| 209 | |
| 210 | If the window is smaller than the terminal size, only part of the terminal can |
| 211 | be seen (the lower-left part). |
| 212 | |
| 213 | The |term_getsize()| function can be used to get the current size of the |
| 214 | terminal. |term_setsize()| can be used only when in the first or second mode, |
| 215 | not when 'termsize' is "rowsXcols". |
| 216 | |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 217 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 218 | Terminal-Job and Terminal-Normal mode ~ |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 219 | *Terminal-mode* |
| 220 | When the job is running the contents of the terminal is under control of the |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 221 | job. That includes the cursor position. Typed keys are sent to the job. |
| 222 | The terminal contents can change at any time. This is called Terminal-Job |
| 223 | mode. |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 224 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 225 | Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the |
| 226 | contents of the terminal window is under control of Vim, the job output is |
| 227 | suspended. CTRL-\ CTRL-N does the same. |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 228 | |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 229 | Terminal-Job mode is where |:tmap| mappings are applied. Keys sent by |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 230 | |term_sendkeys()| are not subject to tmap, but keys from |feedkeys()| are. |
| 231 | |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 232 | *E946* |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 233 | In Terminal-Normal mode you can move the cursor around with the usual Vim |
| 234 | commands, Visually mark text, yank text, etc. But you cannot change the |
| 235 | contents of the buffer. The commands that would start insert mode, such as |
| 236 | 'i' and 'a', return to Terminal-Job mode. The window will be updated to show |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 237 | the contents of the terminal. |:startinsert| is ineffective. |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 238 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 239 | In Terminal-Normal mode the statusline and window title show "(Terminal)". If |
| 240 | the job ends while in Terminal-Normal mode this changes to |
| 241 | "(Terminal-finished)". |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 242 | |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 243 | It is not possible to enter Insert mode from Terminal-Job mode. |
| 244 | |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 245 | |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 246 | Cursor style ~ |
| 247 | |
| 248 | By default the cursor in the terminal window uses a not blinking block. The |
| 249 | normal xterm escape sequences can be used to change the blinking state and the |
| 250 | shape. Once focus leaves the terminal window Vim will restore the original |
| 251 | cursor. |
| 252 | |
| 253 | An exception is when xterm is started with the "-bc" argument, or another way |
| 254 | that causes the cursor to blink. This actually means that the blinking flag |
| 255 | is inverted. Since Vim cannot detect this, the terminal window cursor |
| 256 | blinking will also be inverted. |
| 257 | |
| 258 | |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 259 | Unix ~ |
| 260 | |
| 261 | On Unix a pty is used to make it possible to run all kinds of commands. You |
| 262 | can even run Vim in the terminal! That's used for debugging, see below. |
| 263 | |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 264 | Environment variables are used to pass information to the running job: |
| 265 | TERM name of the terminal, 'term' |
| 266 | ROWS number of rows in the terminal initially |
| 267 | LINES same as ROWS |
| 268 | COLUMNS number of columns in the terminal initially |
| 269 | COLORS number of colors, 't_Co' (256*256*256 in the GUI) |
| 270 | VIM_SERVERNAME v:servername |
| 271 | |
| 272 | The |client-server| feature can be used to communicate with the Vim instance |
| 273 | where the job was started. This only works when v:servername is not empty. |
| 274 | If needed you can set it with: > |
| 275 | call remote_startserver('vim-server') |
| 276 | |
| 277 | In the job you can then do something like: > |
| 278 | vim --servername $VIM_SERVERNAME --remote +123 some_file.c |
| 279 | This will open the file "some_file.c" and put the cursor on line 123. |
| 280 | |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 281 | |
| 282 | MS-Windows ~ |
| 283 | |
Bram Moolenaar | 8a77306 | 2017-07-24 22:29:21 +0200 | [diff] [blame] | 284 | On MS-Windows winpty is used to make it possible to run all kind of commands. |
| 285 | Obviously, they must be commands that run in a terminal, not open their own |
| 286 | window. |
| 287 | |
| 288 | You need the following two files from winpty: |
| 289 | |
| 290 | winpty.dll |
| 291 | winpty-agent.exe |
| 292 | |
| 293 | You can download them from the following page: |
| 294 | |
| 295 | https://github.com/rprichard/winpty |
| 296 | |
Bram Moolenaar | 8e539c5 | 2017-08-18 22:57:06 +0200 | [diff] [blame] | 297 | Just put the files somewhere in your PATH. You can set the 'winptydll' option |
| 298 | to point to the right file, if needed. If you have both the 32-bit and 64-bit |
| 299 | version, rename to winpty32.dll and winpty64.dll to match the way Vim was |
| 300 | build. |
Bram Moolenaar | b6e0ec6 | 2017-07-23 22:12:20 +0200 | [diff] [blame] | 301 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 302 | ============================================================================== |
| 303 | 2. Remote testing *terminal-testing* |
| 304 | |
| 305 | Most Vim tests execute a script inside Vim. For some tests this does not |
| 306 | work, running the test interferes with the code being tested. To avoid this |
| 307 | Vim is executed in a terminal window. The test sends keystrokes to it and |
| 308 | inspects the resulting screen state. |
| 309 | |
| 310 | Functions ~ |
| 311 | |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 312 | term_sendkeys() send keystrokes to a terminal (not subject to tmap) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 313 | term_wait() wait for screen to be updated |
| 314 | term_scrape() inspect terminal screen |
| 315 | |
| 316 | |
| 317 | ============================================================================== |
| 318 | 3. Debugging *terminal-debug* |
| 319 | |
| 320 | The Terminal debugging plugin can be used to debug a program with gdb and view |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 321 | the source code in a Vim window. Since this is completely contained inside |
| 322 | Vim this also works remotely over an ssh connection. |
| 323 | |
| 324 | |
| 325 | Starting ~ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 326 | |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 327 | Load the plugin with this command: > |
| 328 | packadd termdebug |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 329 | < *:Termdebug* |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 330 | To start debugging use `:TermDebug` folowed by the command name, for example: > |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 331 | :TermDebug vim |
| 332 | |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 333 | This opens two windows: |
Bram Moolenaar | 45d5f26 | 2017-09-10 19:14:31 +0200 | [diff] [blame] | 334 | gdb window A terminal window in which "gdb vim" is executed. Here you |
| 335 | can directly interact with gdb. The buffer name is "!gdb". |
| 336 | program window A terminal window for the executed program. When "run" is |
| 337 | used in gdb the program I/O will happen in this window, so |
| 338 | that it does not interfere with controlling gdb. The buffer |
| 339 | name is "gdb program". |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 340 | |
| 341 | The current window is used to show the source code. When gdb pauses the |
| 342 | source file location will be displayed, if possible. A sign is used to |
| 343 | highlight the current position (using highlight group debugPC). |
| 344 | |
| 345 | If the buffer in the current window is modified, another window will be opened |
| 346 | to display the current gdb position. |
| 347 | |
| 348 | Focus the terminal of the executed program to interact with it. This works |
| 349 | the same as any command running in a terminal window. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 350 | |
Bram Moolenaar | 45d5f26 | 2017-09-10 19:14:31 +0200 | [diff] [blame] | 351 | When the debugger ends, typically by typing "quit" in the gdb window, the two |
| 352 | opened windows are closed. |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 353 | |
| 354 | |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 355 | Stepping through code ~ |
| 356 | |
| 357 | Put focus on the gdb window to type commands there. Some common ones are: |
| 358 | - CTRL-C interrupt the program |
| 359 | - next execute the current line and stop at the next line |
| 360 | - step execute the current line and stop at the next statement, entering |
| 361 | functions |
| 362 | - finish execute until leaving the current function |
| 363 | - where show the stack |
| 364 | - frame N go to the Nth stack frame |
| 365 | - continue continue execution |
| 366 | |
Bram Moolenaar | 45d5f26 | 2017-09-10 19:14:31 +0200 | [diff] [blame] | 367 | In the window showing the source code some commands can used to control gdb: |
| 368 | :Break set a breakpoint at the current line; a sign will be displayed |
| 369 | :Delete delete a breakpoint at the current line |
| 370 | :Step execute the gdb "step" command |
| 371 | :Over execute the gdb "next" command (:Next is a Vim command) |
| 372 | :Finish execute the gdb "finish" command |
| 373 | :Continue execute the gdb "continue" command |
| 374 | |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 375 | The plugin adds a window toolbar with these entries: |
| 376 | Step :Step |
| 377 | Next :Over |
| 378 | Finish :Finish |
| 379 | Cont :Continue |
| 380 | Eval :Evaluate |
| 381 | This way you can use the mouse to perform the most common commands. |
| 382 | |
Bram Moolenaar | 45d5f26 | 2017-09-10 19:14:31 +0200 | [diff] [blame] | 383 | |
| 384 | Inspecting variables ~ |
| 385 | |
| 386 | :Evaluate evaluate the expression under the cursor |
| 387 | K same |
| 388 | :Evaluate {expr} evaluate {expr} |
| 389 | :'<,'>Evaluate evaluate the Visually selected text |
| 390 | |
| 391 | This is similar to using "print" in the gdb window. |
| 392 | |
| 393 | |
| 394 | Other commands ~ |
| 395 | |
| 396 | :Gdb jump to the gdb window |
| 397 | :Program jump to the window with the running program |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 398 | |
| 399 | |
| 400 | Communication ~ |
| 401 | |
| 402 | There is another, hidden, buffer, which is used for Vim to communicate with |
| 403 | gdb. The buffer name is "gdb communication". Do not delete this buffer, it |
| 404 | will break the debugger. |
| 405 | |
| 406 | |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 407 | Customizing ~ |
| 408 | |
Bram Moolenaar | e09ba7b | 2017-09-09 22:19:47 +0200 | [diff] [blame] | 409 | To change the name of the gdb command, set the "termdebugger" variable before |
| 410 | invoking `:Termdebug`: > |
| 411 | let termdebugger = "mygdb" |
| 412 | Only debuggers fully compatible with gdb will work. Vim uses the GDB/MI |
| 413 | interface. |
| 414 | |
| 415 | The color of the signs can be adjusted with these highlight groups: |
| 416 | - debugPC the current position |
| 417 | - debugBreakpoint a breakpoint |
| 418 | |
| 419 | The defaults are, when 'background' is "light": |
| 420 | hi debugPC term=reverse ctermbg=lightblue guibg=lightblue |
| 421 | hi debugBreakpoint term=reverse ctermbg=red guibg=red |
| 422 | |
| 423 | When 'background' is "dark": |
| 424 | hi debugPC term=reverse ctermbg=darkblue guibg=darkblue |
| 425 | hi debugBreakpoint term=reverse ctermbg=red guibg=red |
Bram Moolenaar | c572da5 | 2017-08-27 16:52:01 +0200 | [diff] [blame] | 426 | |
Bram Moolenaar | 38baa3e | 2017-09-14 16:10:38 +0200 | [diff] [blame] | 427 | To change the width of the Vim window when debugging starts, and use a |
| 428 | vertical split: > |
| 429 | let g:termdebug_wide = 163 |
| 430 | This will set &columns to 163 when :Termdebug is used. The value is restored |
| 431 | when quitting the debugger. |
| 432 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 433 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 434 | |
| 435 | vim:tw=78:ts=8:ft=help:norl: |