Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/tui.txt`
7a72205a0c83b069c347a53768e3d3bd426f2f831b6afe380000000100000fa9
             Y
  Terminal.app                nsterm                              N
  tmux                        tmux, tmux-256color                 Y
  Windows/ConEmu              conemu                              Y
  Windows/Cygwin-built Nvim   cygwin                              Y
  Windows/Interix             interix                             Y
  Windows/VTP console         vtpcon                              Y
  Windows/legacy console      win32con                            Y
  xterm or compatible         xterm, xterm-256color               Y
<

					*builtin-terms* *builtin_terms*
If a |terminfo| database is not available or there is no entry for the current
terminal, Nvim will map |$TERM| to a builtin entry according to the above
table, or "ansi" if there is no match. For example "TERM=putty-256color" will
be mapped to the builtin "putty" entry. See also |tui-colors|.

The builtin terminfo is not combined with any external terminfo database, nor
can it be used in preference to one.  You can thus entirely override any
omissions or out-of-date information in the builtin terminfo database by
supplying an external one with entries for the terminal type.

Settings depending on terminal			*term-dependent-settings*

If you want to set terminal-dependent options or mappings, you can do this in
your init.vim.  Example: >vim

    if $TERM =~ '^\(rxvt\|screen\|interix\|putty\)\(-.*\)\?$'
        set notermguicolors
    elseif $TERM =~ '^\(tmux\|iterm\|vte\|gnome\)\(-.*\)\?$'
        set termguicolors
    elseif $TERM =~ '^\(xterm\)\(-.*\)\?$'
        if $XTERM_VERSION != ''
            set termguicolors
        elseif $KONSOLE_PROFILE_NAME != ''
            set termguicolors
        elseif $VTE_VERSION != ''
            set termguicolors
        else
            set notermguicolors
        endif
    elseif $TERM =~ ...
        ... and so forth ...
    endif
<
					*scroll-region* *xterm-scroll-region*
Where possible, Nvim will use the terminal's ability to set a scroll region in
order to redraw faster when a window is scrolled.  If the terminal's terminfo
description describes an ability to set top and bottom scroll margins, that is
used.

This will not speed up scrolling in a window that is not the full width of the
terminal.  Xterm has an extra ability, not described by terminfo, to set left
and right scroll margins as well.  If Nvim detects that the terminal is Xterm,
it will make use of this ability to speed up scrolling that is not the full
width of the terminal.

								*tui-input*
Historically, terminal emulators could not distinguish between certain control
key modifiers and other keys. For example, <C-I> and <Tab> are represented in
the same way, as are <Esc> and <C-[>, <CR> and <C-M>, and <NL> and <C-J>.

Modern terminal emulators are able to distinguish between these pairs of keys
by encoding control modifiers differently. There are two common but distinct
ways of doing this, known as "modifyOtherKeys" and "CSI u". Nvim supports both
encoding methods and at startup will tell the terminal emulator that it
understands these key encodings. If your terminal emulator supports it then
this will allow you to map the key pairs listed above separately. |<Tab>|

Nvim uses libtermkey to convert terminal escape sequences to key codes.
|terminfo| is used first, and CSI sequences not in |terminfo| (including
extended keys a.k.a. "modifyOtherKeys" or "CSI u") can also be parsed.

For example, when running Nvim in tmux, this makes Nvim leave Insert mode and
go to the window below: >
        tmux send-keys 'Escape' [ 2 7 u 'C-W' j
Where `'Escape' [ 2 7 u` is an unambiguous "CSI u" sequence for the <Esc> key.

The kitty keyboard protocol https://sw.kovidgoyal.net/kitty/keyboard-protocol/
is partially supported, including keypad keys in Unicode Private Use Area.
For example, this sequence is recognized by Nvim as <C-kEnter>: >
        CSI 57414 ; 5 u
and can be used differently from <C-CR> in mappings.

						*tui-modifyOtherKeys* *tui-csiu*

Title: Nvim Terminal UI: Built-in Terminfo, Terminal-Dependent Settings, and Input Handling
Summary
This section covers aspects of Nvim's Terminal UI, including built-in terminfo entries and how they are used when a terminfo database is unavailable. It provides an example of how to set terminal-dependent options in init.vim based on the $TERM variable. It explains how Nvim uses the terminal's scroll region ability for faster redrawing and how it handles terminal input, including the differentiation of control key modifiers and the support for 'modifyOtherKeys' and 'CSI u' encoding methods. Also, it mentions partial support for the Kitty keyboard protocol.