2017-03-21 09:08:19 -07:00
|
|
|
*terminal_emulator.txt* Nvim
|
2015-03-28 08:33:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
NVIM REFERENCE MANUAL by Thiago de Arruda
|
|
|
|
|
|
|
|
|
2017-05-22 15:25:15 -07:00
|
|
|
Terminal emulator *terminal* *terminal-emulator*
|
2015-03-28 08:33:19 -07:00
|
|
|
|
2017-02-21 07:16:48 -07:00
|
|
|
Nvim embeds a VT220/xterm terminal emulator based on libvterm. The terminal is
|
|
|
|
presented as a special buffer type, asynchronously updated from the virtual
|
|
|
|
terminal as data is received from the program connected to it.
|
2015-03-28 08:33:19 -07:00
|
|
|
|
2017-03-14 16:12:21 -07:00
|
|
|
Terminal buffers behave like normal buffers, except:
|
|
|
|
- With 'modifiable', lines can be edited but not deleted.
|
|
|
|
- 'scrollback' controls how many lines are kept.
|
|
|
|
- Output is followed if the cursor is on the last line.
|
|
|
|
- 'modified' is the default. You can set 'nomodified' to avoid a warning when
|
|
|
|
closing the terminal buffer.
|
|
|
|
- 'bufhidden' defaults to "hide".
|
2015-03-28 08:33:19 -07:00
|
|
|
|
2017-10-20 17:33:58 -07:00
|
|
|
Type |gO| to see the table of contents.
|
2017-05-01 08:09:29 -07:00
|
|
|
|
2015-03-28 08:33:19 -07:00
|
|
|
==============================================================================
|
2017-03-14 16:12:21 -07:00
|
|
|
Start *terminal-start*
|
2015-03-28 08:33:19 -07:00
|
|
|
|
|
|
|
There are 3 ways to create a terminal buffer:
|
|
|
|
|
|
|
|
- By invoking the |:terminal| ex command.
|
|
|
|
- By calling the |termopen()| function.
|
|
|
|
- By editing a file with a name matching `term://(.{-}//(\d+:)?)?\zs.*`.
|
|
|
|
For example:
|
|
|
|
>
|
2016-07-03 02:21:57 -07:00
|
|
|
:edit term://bash
|
|
|
|
:vsplit term://top
|
2015-03-28 08:33:19 -07:00
|
|
|
<
|
2016-07-03 02:21:57 -07:00
|
|
|
Note: The "term://" pattern is handled by a BufReadCmd handler, so the
|
|
|
|
|autocmd-nested| modifier is required to use it in an autocmd. >
|
|
|
|
autocmd VimEnter * nested split term://sh
|
2017-02-21 07:16:48 -07:00
|
|
|
< This is only mentioned for reference; use |:terminal| instead.
|
2016-07-03 02:21:57 -07:00
|
|
|
|
2017-03-14 16:12:21 -07:00
|
|
|
When the terminal starts, the buffer contents are updated and the buffer is
|
|
|
|
named in the form of `term://{cwd}//{pid}:{cmd}`. This naming scheme is used
|
|
|
|
by |:mksession| to restore a terminal buffer (by restarting the {cmd}).
|
2015-03-28 08:33:19 -07:00
|
|
|
|
|
|
|
==============================================================================
|
2017-03-14 16:12:21 -07:00
|
|
|
Input *terminal-input*
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2017-05-16 08:19:12 -07:00
|
|
|
To send input, enter |Terminal-mode| using any command that would enter "insert
|
2017-02-21 07:16:48 -07:00
|
|
|
mode" in a normal buffer, such as |i| or |:startinsert|. In this mode all keys
|
|
|
|
except <C-\><C-N> are sent to the underlying program. Use <C-\><C-N> to return
|
2017-05-11 05:34:48 -07:00
|
|
|
to normal-mode. |CTRL-\_CTRL-N|
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2017-05-11 05:34:48 -07:00
|
|
|
Terminal-mode has its own |:tnoremap| namespace for mappings, this can be used
|
|
|
|
to automate any terminal interaction.
|
|
|
|
|
|
|
|
To map <Esc> to exit terminal-mode: >
|
2015-03-28 08:33:19 -07:00
|
|
|
:tnoremap <Esc> <C-\><C-n>
|
2017-05-11 05:34:48 -07:00
|
|
|
|
|
|
|
To simulate |i_CTRL-R| in terminal-mode: >
|
|
|
|
:tnoremap <expr> <C-R> '<C-\><C-N>"'.nr2char(getchar()).'pi'
|
|
|
|
|
|
|
|
To use `ALT+{h,j,k,l}` to navigate windows from any mode: >
|
|
|
|
:tnoremap <A-h> <C-\><C-N><C-w>h
|
|
|
|
:tnoremap <A-j> <C-\><C-N><C-w>j
|
|
|
|
:tnoremap <A-k> <C-\><C-N><C-w>k
|
|
|
|
:tnoremap <A-l> <C-\><C-N><C-w>l
|
|
|
|
:inoremap <A-h> <C-\><C-N><C-w>h
|
|
|
|
:inoremap <A-j> <C-\><C-N><C-w>j
|
|
|
|
:inoremap <A-k> <C-\><C-N><C-w>k
|
|
|
|
:inoremap <A-l> <C-\><C-N><C-w>l
|
2015-03-28 08:33:19 -07:00
|
|
|
:nnoremap <A-h> <C-w>h
|
|
|
|
:nnoremap <A-j> <C-w>j
|
|
|
|
:nnoremap <A-k> <C-w>k
|
|
|
|
:nnoremap <A-l> <C-w>l
|
|
|
|
|
2017-05-11 05:34:48 -07:00
|
|
|
Mouse input has the following behavior:
|
2015-03-28 08:33:19 -07:00
|
|
|
|
|
|
|
- If the program has enabled mouse events, the corresponding events will be
|
|
|
|
forwarded to the program.
|
|
|
|
- If mouse events are disabled (the default), terminal focus will be lost and
|
|
|
|
the event will be processed as in a normal buffer.
|
|
|
|
- If another window is clicked, terminal focus will be lost and nvim will jump
|
|
|
|
to the clicked window
|
|
|
|
- If the mouse wheel is used while the mouse is positioned in another window,
|
|
|
|
the terminal wont lose focus and the hovered window will be scrolled.
|
|
|
|
|
|
|
|
==============================================================================
|
2017-03-14 16:12:21 -07:00
|
|
|
Configuration *terminal-configuration*
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2017-03-14 16:12:21 -07:00
|
|
|
Options: 'modified', 'scrollback'
|
2017-02-21 07:16:48 -07:00
|
|
|
Events: |TermOpen|, |TermClose|
|
|
|
|
Highlight groups: |hl-TermCursor|, |hl-TermCursorNC|
|
2015-03-28 08:33:19 -07:00
|
|
|
|
2017-05-22 15:25:15 -07:00
|
|
|
Terminal sets local defaults for some options, which may differ from your
|
|
|
|
global configuration.
|
|
|
|
|
|
|
|
- 'list' is disabled
|
|
|
|
- 'wrap' is disabled
|
2017-05-27 06:08:38 -07:00
|
|
|
- 'relativenumber' is disabled in |Terminal-mode| (and cannot be enabled)
|
2017-05-22 15:25:15 -07:00
|
|
|
|
|
|
|
You can change the defaults with a TermOpen autocommand: >
|
2017-05-27 06:08:38 -07:00
|
|
|
au TermOpen * setlocal list
|
2017-05-22 15:25:15 -07:00
|
|
|
|
2017-03-14 16:12:21 -07:00
|
|
|
TERMINAL COLORS ~
|
2015-03-28 08:33:19 -07:00
|
|
|
|
2017-03-14 16:12:21 -07:00
|
|
|
The `{g,b}:terminal_color_$NUM` variables control the terminal color palette,
|
|
|
|
where `$NUM` is the color index between 0 and 255 inclusive. This setting only
|
|
|
|
affects UIs with RGB capabilities; for normal terminals the color index is
|
|
|
|
just forwarded. The variables are read only during |TermOpen|.
|
2015-04-08 04:34:27 -07:00
|
|
|
|
2016-07-10 12:41:07 -07:00
|
|
|
==============================================================================
|
2017-03-14 16:12:21 -07:00
|
|
|
Status Variables *terminal-status*
|
2016-07-10 12:41:07 -07:00
|
|
|
|
|
|
|
Terminal buffers maintain some information about the terminal in buffer-local
|
|
|
|
variables:
|
|
|
|
|
|
|
|
- *b:term_title* The settable title of the terminal, typically displayed in
|
|
|
|
the window title or tab title of a graphical terminal emulator. Programs
|
|
|
|
running in the terminal can set this title via an escape sequence.
|
2017-06-10 00:55:06 -07:00
|
|
|
- |'channel'| The nvim channel ID for the underlying PTY.
|
|
|
|
|chansend()| can be used to send input to the terminal.
|
2016-07-10 12:41:07 -07:00
|
|
|
- *b:terminal_job_pid* The PID of the top-level process running in the
|
|
|
|
terminal.
|
|
|
|
|
2017-02-21 07:16:48 -07:00
|
|
|
These variables are initialized before TermOpen, so you can use them in
|
|
|
|
a local 'statusline'. Example: >
|
2016-07-10 12:41:07 -07:00
|
|
|
:autocmd TermOpen * setlocal statusline=%{b:term_title}
|
|
|
|
<
|
2015-03-28 08:33:19 -07:00
|
|
|
==============================================================================
|
|
|
|
vim:tw=78:ts=8:noet:ft=help:norl:
|