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