neovim/runtime/doc/nvim_terminal_emulator.txt

130 lines
4.9 KiB
Plaintext
Raw Normal View History

*terminal_emulator.txt* Nvim
NVIM REFERENCE MANUAL by Thiago de Arruda
2017-05-22 15:25:15 -07:00
Terminal emulator *terminal* *terminal-emulator*
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.
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".
Type |gO| to see the table of contents.
==============================================================================
Start *terminal-start*
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
<
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
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}).
==============================================================================
Input *terminal-input*
2017-02-21 07:16:48 -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: >
: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
: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:
- 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.
==============================================================================
Configuration *terminal-configuration*
2017-02-21 07:16:48 -07:00
Options: 'modified', 'scrollback'
2017-02-21 07:16:48 -07:00
Events: |TermOpen|, |TermClose|
Highlight groups: |hl-TermCursor|, |hl-TermCursorNC|
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
You can change the defaults with a TermOpen autocommand: >
au TermOpen * setlocal list
2017-05-22 15:25:15 -07:00
TERMINAL COLORS ~
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|.
==============================================================================
Status Variables *terminal-status*
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.
- *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: >
:autocmd TermOpen * setlocal statusline=%{b:term_title}
<
==============================================================================
vim:tw=78:ts=8:noet:ft=help:norl: