blob: 1054037838c7c8579806a9e1e76c24df2bd27d8f [file] [log] [blame]
Bram Moolenaar423802d2017-07-30 16:52:24 +02001*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 30
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
Bram Moolenaar423802d2017-07-30 16:52:24 +020036
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +020037Typing ~
38
Bram Moolenaare4f25e42017-07-07 11:54:15 +020039When the keyboard focus is in the terminal window, typed keys will be send to
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +020040the job. This uses a pty when possible. You can click outside of the
41terminal window to move keyboard focus elsewhere.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020042
Bram Moolenaar423802d2017-07-30 16:52:24 +020043CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.:
44 CTRL-W CTRL-W move focus to the next window
45 CTRL-W : enter an Ex command
46See |CTRL-W| for more commands.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020047
Bram Moolenaar423802d2017-07-30 16:52:24 +020048Special in the terminal window: *CTRL-W_.* *CTRL-W_N*
49 CTRL-W . send a CTRL-W to the job in the terminal
50 CTRL-W N go to Terminal Normal mode, see |Terminal-mode|
51
52See option 'termkey' for specifying another key instead of CTRL-W that
53will work like CTRL-W. However, typing 'termkey' twice sends 'termkey' to
54the job. For example:
55 'termkey' CTRL-W move focus to the next window
56 'termkey' : enter an Ex command
57 'termkey' 'termkey' send 'termkey' to the job in the terminal
58 'termkey' . send a CTRL-W to the job in the terminal
59 'termkey' N go to terminal Normal mode, see below
60 'termkey' CTRL-N same as CTRL-W N
61
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +020062
63Size ~
Bram Moolenaare4f25e42017-07-07 11:54:15 +020064
Bram Moolenaar74675a62017-07-15 13:53:23 +020065See option 'termsize' for controlling the size of the terminal window.
66(TODO: scrolling when the terminal is larger than the window)
Bram Moolenaare4f25e42017-07-07 11:54:15 +020067
Bram Moolenaar423802d2017-07-30 16:52:24 +020068
Bram Moolenaare4f25e42017-07-07 11:54:15 +020069Syntax ~
Bram Moolenaar8a773062017-07-24 22:29:21 +020070
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +020071:ter[minal] [command] *:ter* *:terminal*
Bram Moolenaar8a773062017-07-24 22:29:21 +020072 Open a new terminal window.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020073
74 If [command] is provided run it as a job and connect
75 the input and output to the terminal.
76 If [command] is not given the 'shell' option is used.
77
78 A new buffer will be created, using [command] or
79 'shell' as the name. If a buffer by this name already
80 exists a number is added in parenthesis.
81 E.g. if "gdb" exists the second terminal buffer will
82 use "gdb (1)".
83
84 The window can be closed, in which case the buffer
85 becomes hidden. The command will not be stopped. The
86 `:buffer` command can be used to turn the current
87 window into a terminal window, using the existing
88 buffer. If there are unsaved changes this fails, use
89 ! to force, as usual.
90
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +020091When the buffer associated with the terminal is wiped out the job is killed,
92similar to calling `job_stop(job, "kill")`
93
94
Bram Moolenaare4f25e42017-07-07 11:54:15 +020095Resizing ~
96
97The size of the terminal can be in one of three modes:
98
991. The 'termsize' option is empty: The terminal size follows the window size.
100 The minimal size is 2 screen lines with 10 cells.
101
1022. The 'termsize' option is "rows*cols", where "rows" is the minimal number of
Bram Moolenaar8a773062017-07-24 22:29:21 +0200103 screen rows and "cols" is the minimal number of cells.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200104
1053. The 'termsize' option is "rowsXcols" (where the x is upper or lower case).
106 The terminal size is fixed to the specified number of screen lines and
107 cells. If the window is bigger there will be unused empty space.
108
109If the window is smaller than the terminal size, only part of the terminal can
110be seen (the lower-left part).
111
112The |term_getsize()| function can be used to get the current size of the
113terminal. |term_setsize()| can be used only when in the first or second mode,
114not when 'termsize' is "rowsXcols".
115
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200116
Bram Moolenaar423802d2017-07-30 16:52:24 +0200117Terminal Normal mode ~
118 *Terminal-mode*
119When the job is running the contents of the terminal is under control of the
120job. That includes the cursor position. The terminal contents can change at
121any time.
122
123Use CTRL-W N (or 'termkey' N) to go to Terminal Normal mode. Now the contents
124of the terminal window is under control of Vim, the job output is suspended.
125 *E946*
126In this mode you can move the cursor around with the usual Vim commands,
127Visually mark text, yank text, etc. But you cannot change the contents of the
128buffer. The commands that would start insert mode, such as 'i' and 'a',
129return control of the window to the job. Any pending output will now be
130displayed.
131
132In Terminal mode the statusline and window title show "(Terminal)". If the
133job ends while in Terminal mode this changes to "(Terminal-finished)".
134
135
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200136Unix ~
137
138On Unix a pty is used to make it possible to run all kinds of commands. You
139can even run Vim in the terminal! That's used for debugging, see below.
140
141
142MS-Windows ~
143
Bram Moolenaar8a773062017-07-24 22:29:21 +0200144On MS-Windows winpty is used to make it possible to run all kind of commands.
145Obviously, they must be commands that run in a terminal, not open their own
146window.
147
148You need the following two files from winpty:
149
150 winpty.dll
151 winpty-agent.exe
152
153You can download them from the following page:
154
155 https://github.com/rprichard/winpty
156
157Just put the files somewhere in your PATH.
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200158
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200159==============================================================================
1602. Remote testing *terminal-testing*
161
162Most Vim tests execute a script inside Vim. For some tests this does not
163work, running the test interferes with the code being tested. To avoid this
164Vim is executed in a terminal window. The test sends keystrokes to it and
165inspects the resulting screen state.
166
167Functions ~
168
169term_sendkeys() send keystrokes to a terminal
170term_wait() wait for screen to be updated
171term_scrape() inspect terminal screen
172
173
174==============================================================================
1753. Debugging *terminal-debug*
176
177The Terminal debugging plugin can be used to debug a program with gdb and view
178the source code in a Vim window. For example: >
179
180 :TermDebug vim
181
182This opens three windows:
183- A terminal window in which "gdb vim" is executed. Here you can directly
184 interact with gdb.
185- A terminal window for the executed program. When "run" is used in gdb the
186 program I/O will happen in this window, so that it does not interfere with
187 controlling gdb.
188- A normal Vim window used to show the source code. When gdb jumps to a
189 source file location this window will display the code, if possible. Values
190 of variables can be inspected, breakpoints set and cleared, etc.
191
192This uses two terminal windows. To open the gdb window: >
193 :term gdb [arguments]
194To open the terminal to run the tested program |term_open()| is used.
195
196TODO
197
198
199 vim:tw=78:ts=8:ft=help:norl: