blob: 54899fca0f15da50509b393049cb2a55e753d4ba [file] [log] [blame]
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +01001*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 09
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Terminal window support *terminal*
8
9
10WARNING: THIS IS ONLY PARTLY IMPLEMENTED, ANYTHING CAN STILL CHANGE
11
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +020012The terminal feature is optional, use this to check if your Vim has it: >
13 echo has('terminal')
14If the result is "1" you have it.
15
Bram Moolenaare4f25e42017-07-07 11:54:15 +020016
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100171. Basic use |terminal-use|
18 Typing |terminal-typing|
19 Size and color |terminal-size-color|
20 Syntax |:terminal|
21 Resizing |terminal-resizing|
22 Terminal Modes |Terminal-mode|
23 Cursor style |terminal-cursor-style|
24 Special keys |terminal-special-keys|
25 Unix |terminal-unix|
26 MS-Windows |terminal-ms-windows|
272. Remote testing |terminal-testing|
283. Debugging |terminal-debug|
29 Starting |termdebug-starting|
30 Example session |termdebug-example|
31 Stepping through code |termdebug-stepping|
32 Inspecting variables |termdebug-variables|
33 Other commands |termdebug-commands|
34 Communication |termdebug-communication|
35 Customizing |termdebug-customizing|
Bram Moolenaare4f25e42017-07-07 11:54:15 +020036
37{Vi does not have any of these commands}
Bram Moolenaarc572da52017-08-27 16:52:01 +020038{only available when compiled with the |+terminal| feature}
39
40The terminal feature requires the |+multi_byte|, |+job| and |+channel| features.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020041
42==============================================================================
431. Basic use *terminal-use*
44
45This feature is for running a terminal emulator in a Vim window. A job can be
46started connected to the terminal emulator. For example, to run a shell: >
47 :term bash
48
Bram Moolenaare09ba7b2017-09-09 22:19:47 +020049Or to run build command: >
50 :term make myprogram
Bram Moolenaare4f25e42017-07-07 11:54:15 +020051
52The job runs asynchronously from Vim, the window will be updated to show
Bram Moolenaare09ba7b2017-09-09 22:19:47 +020053output from the job, also while editing in another window.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020054
Bram Moolenaar423802d2017-07-30 16:52:24 +020055
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +020056Typing ~
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +020057 *terminal-typing*
Bram Moolenaardd693ce2017-08-10 23:15:19 +020058When the keyboard focus is in the terminal window, typed keys will be sent to
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +020059the job. This uses a pty when possible. You can click outside of the
60terminal window to move keyboard focus elsewhere.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020061
Bram Moolenaar423802d2017-07-30 16:52:24 +020062CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.:
63 CTRL-W CTRL-W move focus to the next window
64 CTRL-W : enter an Ex command
65See |CTRL-W| for more commands.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020066
Bram Moolenaar423802d2017-07-30 16:52:24 +020067Special in the terminal window: *CTRL-W_.* *CTRL-W_N*
68 CTRL-W . send a CTRL-W to the job in the terminal
Bram Moolenaardd693ce2017-08-10 23:15:19 +020069 CTRL-W N go to Terminal-Normal mode, see |Terminal-mode|
70 CTRL-\ CTRL-N go to Terminal-Normal mode, see |Terminal-mode|
Bram Moolenaarf55e4c82017-08-01 20:44:53 +020071 CTRL-W " {reg} paste register {reg} *CTRL-W_quote*
72 Also works with the = register to insert the result of
73 evaluating an expression.
Bram Moolenaar8e539c52017-08-18 22:57:06 +020074 CTRL-W CTRL-C ends the job, see below |t_CTRL-W_CTRL-C|
Bram Moolenaar423802d2017-07-30 16:52:24 +020075
76See option 'termkey' for specifying another key instead of CTRL-W that
77will work like CTRL-W. However, typing 'termkey' twice sends 'termkey' to
78the job. For example:
79 'termkey' CTRL-W move focus to the next window
80 'termkey' : enter an Ex command
81 'termkey' 'termkey' send 'termkey' to the job in the terminal
82 'termkey' . send a CTRL-W to the job in the terminal
83 'termkey' N go to terminal Normal mode, see below
84 'termkey' CTRL-N same as CTRL-W N
Bram Moolenaar8e539c52017-08-18 22:57:06 +020085 'termkey' CTRL-C same as |t_CTRL-W_CTRL-C|
Bram Moolenaar69198192017-08-05 14:10:48 +020086 *t_CTRL-\_CTRL-N*
Bram Moolenaardd693ce2017-08-10 23:15:19 +020087The special key combination CTRL-\ CTRL-N can be used to switch to Normal
88mode, just like this works in any other mode.
Bram Moolenaar8e539c52017-08-18 22:57:06 +020089 *t_CTRL-W_CTRL-C*
90CTRL-W CTRL-C can be typed to forcefully end the job. On MS-Windows a
91CTRL-BREAK will also kill the job.
92
93If you type CTRL-C the effect depends on what the pty has been configured to
94do. For simple commands this causes a SIGINT to be sent to the job, which
95would end it. Other commands may ignore the SIGINT or handle the CTRL-C
96themselves (like Vim does).
Bram Moolenaar423802d2017-07-30 16:52:24 +020097
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +020098To change the keys you type use terminal mode mappings, see |:tmap|.
99These are defined like any mapping, but apply only when typing keys that are
Bram Moolenaar24a98a02017-09-27 22:23:55 +0200100sent to the job running in the terminal. For example, to make Escape switch
101to Terminal-Normal mode: >
102 tnoremap <Esc> <C-W>N
Bram Moolenaar01164a62017-11-02 22:58:42 +0100103< *options-in-terminal*
Bram Moolenaar24a98a02017-09-27 22:23:55 +0200104After opening the terminal window and setting 'buftype' to "terminal" the
105BufWinEnter autocommand event is triggered. This makes it possible to set
106options specifically for the window and buffer. Example: >
107 au BufWinEnter * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200108
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +0200109
Bram Moolenaar8e539c52017-08-18 22:57:06 +0200110Size and color ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100111 *terminal-size-color*
Bram Moolenaar74675a62017-07-15 13:53:23 +0200112See option 'termsize' for controlling the size of the terminal window.
113(TODO: scrolling when the terminal is larger than the window)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200114
Bram Moolenaar38baa3e2017-09-14 16:10:38 +0200115The job running in the terminal can change the colors. The default foreground
116and background colors are taken from Vim, the Normal highlight group.
117
118For a color terminal the 'background' option is used to decide whether the
119terminal window will start with a white or black background.
120
121To use a different color the Terminal highlight group can be used: >
122 hi Terminal ctermbg=lightgrey ctermfg=blue guibg=lightgrey guifg=blue
Bram Moolenaar8e539c52017-08-18 22:57:06 +0200123
Bram Moolenaar423802d2017-07-30 16:52:24 +0200124
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200125Syntax ~
Bram Moolenaar8a773062017-07-24 22:29:21 +0200126
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200127:[range]ter[minal] [options] [command] *:ter* *:terminal*
Bram Moolenaar8a773062017-07-24 22:29:21 +0200128 Open a new terminal window.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200129
130 If [command] is provided run it as a job and connect
131 the input and output to the terminal.
132 If [command] is not given the 'shell' option is used.
Bram Moolenaarc572da52017-08-27 16:52:01 +0200133 if [command] is NONE no job is started, the pty of the
134 terminal can be used by a command like gdb.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200135
136 A new buffer will be created, using [command] or
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200137 'shell' as the name, prefixed with a "!". If a buffer
138 by this name already exists a number is added in
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200139 parentheses. E.g. if "gdb" exists the second terminal
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200140 buffer will use "!gdb (1)".
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200141
Bram Moolenaarb2412082017-08-20 18:09:14 +0200142 If [range] is given the specified lines are used as
143 input for the job. It will not be possible to type
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200144 keys in the terminal window. For MS-Windows see the
145 ++eof argument below.
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200146
147 Two comma separated numbers are used as "rows,cols".
148 E.g. `:24,80gdb` opens a terminal with 24 rows and 80
149 columns. However, if the terminal window spans the
150 Vim window with, there is no vertical split, the Vim
151 window width is used.
152 *term++close* *term++open*
153 Supported [options] are:
154 ++close The terminal window will close
155 automatically when the job terminates.
156 ++open When the job terminates and no window
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200157 shows it, a window will be opened.
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200158 Note that this can be interruptive.
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200159 ++curwin Open the terminal in the current
160 window, do not split the current
161 window. Fails if the current buffer
162 cannot be |abandon|ed.
163 ++hidden Open the terminal in a hidden buffer,
164 no window will be used.
Bram Moolenaarb2412082017-08-20 18:09:14 +0200165 ++rows={height} Use {height} for the terminal window
166 height.
167 ++cols={width} Use {width} for the terminal window
168 width.
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200169 ++eof={text} when using [range]: text to send after
170 the last line was written. Cannot
171 contain white space. A CR is
172 appended. For MS-Windows the default
173 is to send CTRL-D.
Bram Moolenaaref68e4f2017-09-02 16:28:36 +0200174 E.g. for a shell use "++eof=exit" and
175 for Python "++eof=exit()". Special
176 codes can be used like with `:map`,
177 e.g. "<C-Z>" for CTRL-Z.
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200178
179 If you want to use more options use the |term_start()|
180 function.
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200181
Bram Moolenaar8e539c52017-08-18 22:57:06 +0200182When the buffer associated with the terminal is unloaded or wiped out the job
183is killed, similar to calling `job_stop(job, "kill")`
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200184
Bram Moolenaare561a7e2017-08-29 22:44:59 +0200185So long as the job is running the window behaves like it contains a modified
Bram Moolenaaref68e4f2017-09-02 16:28:36 +0200186buffer. Trying to close the window with `CTRL-W :quit` fails. When using
187`CTRL-W :quit!` the job is ended. The text in the window is lost. The buffer
188still exists, but getting it in a window with `:buffer` will show an empty
189buffer.
190
191Trying to close the window with `CTRL-W :close` also fails. Using
192`CTRL-W :close!` will close the window and make the buffer hidden.
Bram Moolenaare561a7e2017-08-29 22:44:59 +0200193
194You can use `CTRL-W :hide` to close the terminal window and make the buffer
195hidden, the job keeps running. The `:buffer` command can be used to turn the
196current window into a terminal window. If there are unsaved changes this
197fails, use ! to force, as usual.
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200198
199To have a background job run without a window, and open the window when it's
200done, use options like this: >
201 :term ++hidden ++open make
202Note that the window will open at an unexpected moment, this will interrupt
203what you are doing.
204
Bram Moolenaar8e539c52017-08-18 22:57:06 +0200205 *E947* *E948*
Bram Moolenaar78712a72017-08-05 14:50:12 +0200206So long as the job is running, the buffer is considered modified and Vim
207cannot be quit easily, see |abandon|.
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200208
209When the job has finished and no changes were made to the buffer: closing the
210window will wipe out the buffer.
211
212Before changes can be made to a terminal buffer, the 'modifiable' option must
213be set. This is only possible when the job has finished. At the first change
214the buffer will become a normal buffer and the highlighting is removed.
215You may want to change the buffer name with |:file| to be able to write, since
216the buffer name will still be set to the command.
217
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200218
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200219Resizing ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100220 *terminal-resizing*
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200221The size of the terminal can be in one of three modes:
222
2231. The 'termsize' option is empty: The terminal size follows the window size.
224 The minimal size is 2 screen lines with 10 cells.
225
2262. The 'termsize' option is "rows*cols", where "rows" is the minimal number of
Bram Moolenaar8a773062017-07-24 22:29:21 +0200227 screen rows and "cols" is the minimal number of cells.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200228
2293. The 'termsize' option is "rowsXcols" (where the x is upper or lower case).
230 The terminal size is fixed to the specified number of screen lines and
231 cells. If the window is bigger there will be unused empty space.
232
233If the window is smaller than the terminal size, only part of the terminal can
234be seen (the lower-left part).
235
236The |term_getsize()| function can be used to get the current size of the
237terminal. |term_setsize()| can be used only when in the first or second mode,
238not when 'termsize' is "rowsXcols".
239
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200240
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200241Terminal-Job and Terminal-Normal mode ~
Bram Moolenaar423802d2017-07-30 16:52:24 +0200242 *Terminal-mode*
243When the job is running the contents of the terminal is under control of the
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200244job. That includes the cursor position. Typed keys are sent to the job.
245The terminal contents can change at any time. This is called Terminal-Job
246mode.
Bram Moolenaar423802d2017-07-30 16:52:24 +0200247
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200248Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the
249contents of the terminal window is under control of Vim, the job output is
250suspended. CTRL-\ CTRL-N does the same.
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200251
Bram Moolenaar1b9645d2017-09-17 23:03:31 +0200252Terminal-Job mode is where |:tmap| mappings are applied. Keys sent by
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200253|term_sendkeys()| are not subject to tmap, but keys from |feedkeys()| are.
254
Bram Moolenaar423802d2017-07-30 16:52:24 +0200255 *E946*
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200256In Terminal-Normal mode you can move the cursor around with the usual Vim
257commands, Visually mark text, yank text, etc. But you cannot change the
258contents of the buffer. The commands that would start insert mode, such as
259'i' and 'a', return to Terminal-Job mode. The window will be updated to show
Bram Moolenaar1b9645d2017-09-17 23:03:31 +0200260the contents of the terminal. |:startinsert| is ineffective.
Bram Moolenaar423802d2017-07-30 16:52:24 +0200261
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200262In Terminal-Normal mode the statusline and window title show "(Terminal)". If
263the job ends while in Terminal-Normal mode this changes to
264"(Terminal-finished)".
Bram Moolenaar423802d2017-07-30 16:52:24 +0200265
Bram Moolenaar8e539c52017-08-18 22:57:06 +0200266It is not possible to enter Insert mode from Terminal-Job mode.
267
Bram Moolenaar423802d2017-07-30 16:52:24 +0200268
Bram Moolenaarc572da52017-08-27 16:52:01 +0200269Cursor style ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100270 *terminal-cursor-style*
Bram Moolenaarc572da52017-08-27 16:52:01 +0200271By default the cursor in the terminal window uses a not blinking block. The
272normal xterm escape sequences can be used to change the blinking state and the
273shape. Once focus leaves the terminal window Vim will restore the original
274cursor.
275
276An exception is when xterm is started with the "-bc" argument, or another way
277that causes the cursor to blink. This actually means that the blinking flag
278is inverted. Since Vim cannot detect this, the terminal window cursor
279blinking will also be inverted.
280
281
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100282Special keys ~
283 *terminal-special-keys*
284Since the terminal emulator simulates an xterm, only escape sequences that
285both Vim and xterm recognize will be available in the terminal window. If you
286want to pass on other escape sequences to the job running in the terminal you
287need to set up forwarding. Example: >
288 tmap <expr> <Esc>]b SendToTerm("\<Esc>]b")
289 func SendToTerm(what)
290 call term_sendkeys('', a:what)
291 return ''
292 endfunc
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200293
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100294
295Unix ~
296 *terminal-unix*
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200297On Unix a pty is used to make it possible to run all kinds of commands. You
298can even run Vim in the terminal! That's used for debugging, see below.
299
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200300Environment variables are used to pass information to the running job:
301 TERM name of the terminal, 'term'
302 ROWS number of rows in the terminal initially
303 LINES same as ROWS
304 COLUMNS number of columns in the terminal initially
305 COLORS number of colors, 't_Co' (256*256*256 in the GUI)
306 VIM_SERVERNAME v:servername
307
308The |client-server| feature can be used to communicate with the Vim instance
309where the job was started. This only works when v:servername is not empty.
310If needed you can set it with: >
311 call remote_startserver('vim-server')
312
313In the job you can then do something like: >
314 vim --servername $VIM_SERVERNAME --remote +123 some_file.c
315This will open the file "some_file.c" and put the cursor on line 123.
316
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200317
318MS-Windows ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100319 *terminal-ms-windows*
Bram Moolenaar8a773062017-07-24 22:29:21 +0200320On MS-Windows winpty is used to make it possible to run all kind of commands.
321Obviously, they must be commands that run in a terminal, not open their own
322window.
323
324You need the following two files from winpty:
325
326 winpty.dll
327 winpty-agent.exe
328
329You can download them from the following page:
330
331 https://github.com/rprichard/winpty
332
Bram Moolenaar8e539c52017-08-18 22:57:06 +0200333Just put the files somewhere in your PATH. You can set the 'winptydll' option
334to point to the right file, if needed. If you have both the 32-bit and 64-bit
335version, rename to winpty32.dll and winpty64.dll to match the way Vim was
336build.
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200337
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200338==============================================================================
3392. Remote testing *terminal-testing*
340
341Most Vim tests execute a script inside Vim. For some tests this does not
342work, running the test interferes with the code being tested. To avoid this
343Vim is executed in a terminal window. The test sends keystrokes to it and
344inspects the resulting screen state.
345
346Functions ~
347
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200348term_sendkeys() send keystrokes to a terminal (not subject to tmap)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200349term_wait() wait for screen to be updated
350term_scrape() inspect terminal screen
351
352
353==============================================================================
3543. Debugging *terminal-debug*
355
356The Terminal debugging plugin can be used to debug a program with gdb and view
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200357the source code in a Vim window. Since this is completely contained inside
358Vim this also works remotely over an ssh connection.
359
360
361Starting ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100362 *termdebug-starting*
Bram Moolenaarc572da52017-08-27 16:52:01 +0200363Load the plugin with this command: >
364 packadd termdebug
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200365< *:Termdebug*
Bram Moolenaarc572da52017-08-27 16:52:01 +0200366To start debugging use `:TermDebug` folowed by the command name, for example: >
Bram Moolenaar24a98a02017-09-27 22:23:55 +0200367 :Termdebug vim
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200368
Bram Moolenaarc572da52017-08-27 16:52:01 +0200369This opens two windows:
Bram Moolenaar45d5f262017-09-10 19:14:31 +0200370gdb window A terminal window in which "gdb vim" is executed. Here you
371 can directly interact with gdb. The buffer name is "!gdb".
372program window A terminal window for the executed program. When "run" is
373 used in gdb the program I/O will happen in this window, so
374 that it does not interfere with controlling gdb. The buffer
375 name is "gdb program".
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200376
377The current window is used to show the source code. When gdb pauses the
378source file location will be displayed, if possible. A sign is used to
379highlight the current position (using highlight group debugPC).
380
381If the buffer in the current window is modified, another window will be opened
382to display the current gdb position.
383
384Focus the terminal of the executed program to interact with it. This works
385the same as any command running in a terminal window.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200386
Bram Moolenaar45d5f262017-09-10 19:14:31 +0200387When the debugger ends, typically by typing "quit" in the gdb window, the two
388opened windows are closed.
Bram Moolenaarc572da52017-08-27 16:52:01 +0200389
390
Bram Moolenaar24a98a02017-09-27 22:23:55 +0200391Example session ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100392 *termdebug-example*
Bram Moolenaar24a98a02017-09-27 22:23:55 +0200393Start in the Vim "src" directory and build Vim: >
394 % make
395Start Vim: >
396 % ./vim
397Load the termdebug plugin and start debugging Vim: >
398 :packadd termdebug
399 :Termdebug vim
400You should now have three windows:
401 source - where you started, has a window toolbar with buttons
402 gdb - you can type gdb commands here
403 program - the executed program will use this window
404You can use CTRL-W CTRL-W or the mouse to move focus between windows.
405Put focus on the gdb window and type: >
406 break ex_help
407 run
408Vim will start running in the program window. Put focus there and type: >
409 :help gui
410Gdb will run into the ex_help breakpoint. The source window now shows the
411ex_cmds.c file. A ">>" marker will appear where the breakpoint was set. The
412line where the debugger stopped is highlighted. You can now step through the
413program. Let's use the mouse: click on the "Next" button in the window
414toolbar. You will see the highlighting move as the debugger executes a line
415of source code.
416
417Click "Next" a few times until the for loop is highlighted. Put the cursor on
418the end of "eap->arg", then click "Eval" in the toolbar. You will see this
419displayed:
420 "eap->arg": 0x555555e68855 "gui" ~
421This way you can inspect the value of local variables. You can also focus the
422gdb window and use a "print" command, e.g.: >
423 print *eap
424
425Now go back to the source window and put the cursor on the first line after
426the for loop, then type: >
427 :Break
428You will see a ">>" marker appear, this indicates the new breakpoint. Now
429click "Cont" in the toolbar and the code until the breakpoint will be
430executed.
431
432You can type more advanced commands in the gdb window. For example, type: >
433 watch curbuf
434Now click "Cont" in the toolbar (or type "cont" in the gdb window). Execution
435will now continue until the value of "curbuf" changes, which is in do_ecmd().
436To remove this watchpoint again type in the gdb window: >
437 delete 3
438
439You can see the stack by typing in the gdb window: >
440 where
441Move through the stack frames, e.g. with: >
442 frame 3
443The source window will show the code, at the point where the call was made to
444a deeper level.
445
446
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200447Stepping through code ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100448 *termdebug-stepping*
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200449Put focus on the gdb window to type commands there. Some common ones are:
450- CTRL-C interrupt the program
451- next execute the current line and stop at the next line
452- step execute the current line and stop at the next statement, entering
453 functions
454- finish execute until leaving the current function
455- where show the stack
456- frame N go to the Nth stack frame
457- continue continue execution
458
Bram Moolenaar45d5f262017-09-10 19:14:31 +0200459In the window showing the source code some commands can used to control gdb:
460 :Break set a breakpoint at the current line; a sign will be displayed
461 :Delete delete a breakpoint at the current line
462 :Step execute the gdb "step" command
463 :Over execute the gdb "next" command (:Next is a Vim command)
464 :Finish execute the gdb "finish" command
465 :Continue execute the gdb "continue" command
466
Bram Moolenaar1b9645d2017-09-17 23:03:31 +0200467The plugin adds a window toolbar with these entries:
468 Step :Step
469 Next :Over
470 Finish :Finish
471 Cont :Continue
472 Eval :Evaluate
473This way you can use the mouse to perform the most common commands.
474
Bram Moolenaar45d5f262017-09-10 19:14:31 +0200475
476Inspecting variables ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100477 *termdebug-variables*
Bram Moolenaar45d5f262017-09-10 19:14:31 +0200478 :Evaluate evaluate the expression under the cursor
479 K same
480 :Evaluate {expr} evaluate {expr}
481 :'<,'>Evaluate evaluate the Visually selected text
482
483This is similar to using "print" in the gdb window.
484
485
486Other commands ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100487 *termdebug-commands*
Bram Moolenaar45d5f262017-09-10 19:14:31 +0200488 :Gdb jump to the gdb window
489 :Program jump to the window with the running program
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200490
491
492Communication ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100493 *termdebug-communication*
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200494There is another, hidden, buffer, which is used for Vim to communicate with
495gdb. The buffer name is "gdb communication". Do not delete this buffer, it
496will break the debugger.
497
498
Bram Moolenaarc572da52017-08-27 16:52:01 +0200499Customizing ~
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +0100500 *termdebug-customizing*
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200501To change the name of the gdb command, set the "termdebugger" variable before
502invoking `:Termdebug`: >
503 let termdebugger = "mygdb"
Bram Moolenaar01164a62017-11-02 22:58:42 +0100504< *gdb-version*
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200505Only debuggers fully compatible with gdb will work. Vim uses the GDB/MI
Bram Moolenaar01164a62017-11-02 22:58:42 +0100506interface. This probably requires gdb version 7.12. if you get this error:
507 Undefined command: "new-ui". Try "help".~
508Then your gdb is too old.
Bram Moolenaare09ba7b2017-09-09 22:19:47 +0200509
510The color of the signs can be adjusted with these highlight groups:
511- debugPC the current position
512- debugBreakpoint a breakpoint
513
514The defaults are, when 'background' is "light":
515 hi debugPC term=reverse ctermbg=lightblue guibg=lightblue
516 hi debugBreakpoint term=reverse ctermbg=red guibg=red
517
518When 'background' is "dark":
519 hi debugPC term=reverse ctermbg=darkblue guibg=darkblue
520 hi debugBreakpoint term=reverse ctermbg=red guibg=red
Bram Moolenaarc572da52017-08-27 16:52:01 +0200521
Bram Moolenaar38baa3e2017-09-14 16:10:38 +0200522To change the width of the Vim window when debugging starts, and use a
523vertical split: >
524 let g:termdebug_wide = 163
525This will set &columns to 163 when :Termdebug is used. The value is restored
526when quitting the debugger.
Bram Moolenaar24a98a02017-09-27 22:23:55 +0200527If g:termdebug_wide is set and &Columns is already larger than
528g:termdebug_wide then a vertical split will be used without changing &columns.
529Set it to 1 to get a vertical split without every changing &columns (useful
530for when the terminal can't be resized by Vim).
Bram Moolenaar38baa3e2017-09-14 16:10:38 +0200531
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200532
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200533
534 vim:tw=78:ts=8:ft=help:norl: