blob: 73bcf997194ba4e8993ad39968a0c90b3d6a8f9b [file] [log] [blame]
Bram Moolenaar8a773062017-07-24 22:29:21 +02001*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 24
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
171. Basic use |terminal-use|
182. Remote testing |terminal-testing|
193. Debugging |terminal-debug|
20
21{Vi does not have any of these commands}
22
23==============================================================================
241. Basic use *terminal-use*
25
26This feature is for running a terminal emulator in a Vim window. A job can be
27started connected to the terminal emulator. For example, to run a shell: >
28 :term bash
29
30Or to run a debugger: >
31 :term gdb vim
32
33The job runs asynchronously from Vim, the window will be updated to show
34output from the job, also while editing in any other window.
35
36When the keyboard focus is in the terminal window, typed keys will be send to
37the job. This uses a pty when possible.
38
39Navigate between windows with CTRL-W commands (and mouse).
40E.g. CTRL-W CTRL-W moves focus to the next window.
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +020041Use "CTRL-W :" to edit an Ex command.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020042
Bram Moolenaar74675a62017-07-15 13:53:23 +020043See option 'termkey' for specifying the key that precedes a Vim command.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020044Default is CTRL-W.
45
Bram Moolenaar74675a62017-07-15 13:53:23 +020046See option 'termsize' for controlling the size of the terminal window.
47(TODO: scrolling when the terminal is larger than the window)
Bram Moolenaare4f25e42017-07-07 11:54:15 +020048
49Syntax ~
Bram Moolenaar8a773062017-07-24 22:29:21 +020050
51:ter[minal][!] [command] *:ter* *:terminal*
52 Open a new terminal window.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020053
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 Moolenaarb6e0ec62017-07-23 22:12:20 +020071When the buffer associated with the terminal is wiped out the job is killed,
72similar to calling `job_stop(job, "kill")`
73
74
Bram Moolenaare4f25e42017-07-07 11:54:15 +020075Resizing ~
76
77The size of the terminal can be in one of three modes:
78
791. The 'termsize' option is empty: The terminal size follows the window size.
80 The minimal size is 2 screen lines with 10 cells.
81
822. The 'termsize' option is "rows*cols", where "rows" is the minimal number of
Bram Moolenaar8a773062017-07-24 22:29:21 +020083 screen rows and "cols" is the minimal number of cells.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020084
853. 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
89If the window is smaller than the terminal size, only part of the terminal can
90be seen (the lower-left part).
91
92The |term_getsize()| function can be used to get the current size of the
93terminal. |term_setsize()| can be used only when in the first or second mode,
94not when 'termsize' is "rowsXcols".
95
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +020096
97Unix ~
98
99On Unix a pty is used to make it possible to run all kinds of commands. You
100can even run Vim in the terminal! That's used for debugging, see below.
101
102
103MS-Windows ~
104
Bram Moolenaar8a773062017-07-24 22:29:21 +0200105On MS-Windows winpty is used to make it possible to run all kind of commands.
106Obviously, they must be commands that run in a terminal, not open their own
107window.
108
109You need the following two files from winpty:
110
111 winpty.dll
112 winpty-agent.exe
113
114You can download them from the following page:
115
116 https://github.com/rprichard/winpty
117
118Just put the files somewhere in your PATH.
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200119
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200120==============================================================================
1212. Remote testing *terminal-testing*
122
123Most Vim tests execute a script inside Vim. For some tests this does not
124work, running the test interferes with the code being tested. To avoid this
125Vim is executed in a terminal window. The test sends keystrokes to it and
126inspects the resulting screen state.
127
128Functions ~
129
130term_sendkeys() send keystrokes to a terminal
131term_wait() wait for screen to be updated
132term_scrape() inspect terminal screen
133
134
135==============================================================================
1363. Debugging *terminal-debug*
137
138The Terminal debugging plugin can be used to debug a program with gdb and view
139the source code in a Vim window. For example: >
140
141 :TermDebug vim
142
143This 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
153This uses two terminal windows. To open the gdb window: >
154 :term gdb [arguments]
155To open the terminal to run the tested program |term_open()| is used.
156
157TODO
158
159
160 vim:tw=78:ts=8:ft=help:norl: