robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Barrett Ruthdocs(tui): kitty keyboard protocol flags #41056c1a65ff353

master
17.8 KiB408 linesraw
1*tui.txt*      Nvim
2
3
4                            NVIM REFERENCE MANUAL
5
6
7Terminal UI						*TUI* *tui*
8
9By default when you run `nvim` (without |--embed| or |--headless|) it starts
10the builtin "terminal UI" (TUI). This default UI is optional: you can run Nvim
11as a "headless" server, or you can use a |GUI|.
12
13                                      Type |gO| to see the table of contents.
14
15==============================================================================
16Startup					*startup-tui* *startup-terminal*
17
18Nvim has a client-server architecture: by default when you run `nvim`, this
19starts the builtin UI client, which starts a `nvim --embed` server (child)
20process that the UI client connects to. After attaching to the server, the UI
21client calls |nvim_set_client_info()| (as recommended for all UIs |dev-ui|)
22and sets these fields on its channel: >
23
24  client = {
25    attributes = {
26      license = 'Apache 2',
27      pid = …,
28      website = 'https://neovim.io',
29    },
30    name = 'nvim-tui',
31    type = 'ui',
32    version = { … },
33  }
34
35Nvim guesses the terminal type when it starts (except in |--embed| and
36|--headless| modes). The |$TERM| environment variable is the primary hint that
37determines the terminal type.
38
39					*terminfo* *E557* *E558* *E559*
40To display its user interface, Nvim reads a list of "terminal capabilities"
41from the system terminfo database (or builtin defaults if terminfo is not
42found). If that information is wrong, the screen may be messed up or keys may
43not be recognized.
44
45The Unibilium library (used to read terminfo) allows you to override the
46system terminfo with one in the "$HOME/.terminfo/" directory. Building your
47own terminfo is usually as simple as running this:
48>
49  curl -LO https://invisible-island.net/datafiles/current/terminfo.src.gz
50  gunzip terminfo.src.gz
51  tic -x terminfo.src
52<
53
54                                                       *$NVIM_TERMDEFS*
55To override the builtin terminfo, set $NVIM_TERMDEFS to a JSON object whose
56keys correspond to one or more of the fields below, each of which will
57override its counterpart (if any) in the builtin terminfo. The system terminfo
58will be skipped entirely: only builtin definitions, plus the $NVIM_TERMDEFS
59overrides, will be used.
60
61For example, to disable alternate screen, override the "reset the cursor
62style" sequence, and set the <Home> and <S-Home> sequences: >
63
64  NVIM_TERMDEFS='{
65    "enter_ca_mode": "",
66    "exit_ca_mode": "",
67    "reset_cursor_style": "\u001b[0 q",
68    "key_home": ["\u001bOH", "\u001b[1;2H"]
69  }' nvim
70<
71Be careful when putting escape sequences in strings, as JSON uses unicode
72escapes like `\u001b`. For all available fields, see |tui-termdefs|.
73
74								*$TERM*
75The $TERM environment variable must match the terminal you are using!
76Otherwise Nvim cannot know what sequences your terminal expects, and weird
77or sub-optimal behavior will result (scrolling quirks, wrong colors, etc.).
78
79$TERM is also important because it is forwarded by SSH to the remote session,
80unlike most other environment variables.
81
82>
83  For this terminal           Set $TERM to                  |builtin-terms|
84  -------------------------------------------------------------------------
85  ansi                        (unknown)                           Y
86  Ghostty                     ghostty, xterm-ghostty              Y
87  iTerm (original)            iterm, iTerm.app                    N
88  iTerm2 (new capabilities)   iterm2, iTerm2.app                  Y
89  Konsole                     konsole-256color                    N
90  libvte-based                vte, vte-256color                   Y
91   (e.g. GNOME Terminal)      (aliases: gnome, gnome-256color)
92  Linux virtual terminal      linux, linux-256color               Y
93  PuTTY                       putty, putty-256color               Y
94  rxvt                        rxvt, rxvt-256color                 Y
95  screen                      screen, screen-256color             Y
96  simple terminal (st)        st, st-256color                     Y
97  Terminal.app                nsterm                              N
98  tmux                        tmux, tmux-256color                 Y
99  Windows/ConEmu              conemu                              Y
100  Windows/Cygwin-built Nvim   cygwin                              Y
101  Windows/Interix             interix                             Y
102  Windows/legacy console      win32con                            Y
103  Windows/VTP console         vtpcon                              Y
104  xterm or compatible         xterm, xterm-256color               Y
105<
106
107					*builtin-terms* *builtin_terms*
108Nvim will map |$TERM| to a builtin entry according to the above table if:
109
110- a |terminfo| database is not available on the system
111- no terminfo entry found for the current detected terminal
112- Nvim was built without terminfo support (`has('terminfo')==0`)
113
114The builtin terminfo is not combined with any external terminfo database, nor
115can it be used in preference to one.  You can thus entirely override any
116omissions or out-of-date information in the builtin terminfo database by
117supplying an external one with entries for the terminal type.
118
119For example "TERM=putty-256color" will be mapped to the builtin "putty" entry.
120See also |tui-colors|.
121
122Settings depending on terminal			*term-dependent-settings*
123
124If you want to set terminal-dependent options or mappings, you can do this in
125your init.vim.  Example: >vim
126
127    if $TERM =~ '^\(rxvt\|screen\|interix\|putty\)\(-.*\)\?$'
128        set notermguicolors
129    elseif $TERM =~ '^\(tmux\|iterm\|vte\|gnome\)\(-.*\)\?$'
130        set termguicolors
131    elseif $TERM =~ '^\(xterm\)\(-.*\)\?$'
132        if $XTERM_VERSION != ''
133            set termguicolors
134        elseif $KONSOLE_PROFILE_NAME != ''
135            set termguicolors
136        elseif $VTE_VERSION != ''
137            set termguicolors
138        else
139            set notermguicolors
140        endif
141    elseif $TERM =~ ...
142        ... and so forth ...
143    endif
144<
145					*scroll-region* *xterm-scroll-region*
146Where possible, Nvim will use the terminal's ability to set a scroll region in
147order to redraw faster when a window is scrolled.  If the terminal's terminfo
148description describes an ability to set top and bottom scroll margins, that is
149used.
150
151This will not speed up scrolling in a window that is not the full width of the
152terminal.  Xterm has an extra ability, not described by terminfo, to set left
153and right scroll margins as well.  If Nvim detects that the terminal is Xterm,
154it will make use of this ability to speed up scrolling that is not the full
155width of the terminal.
156
157								*tui-input*
158Historically, terminal emulators could not distinguish between certain control
159key modifiers and other keys. For example, <C-I> and <Tab> are represented in
160the same way, as are <Esc> and <C-[>, <CR> and <C-M>, and <NL> and <C-J>.
161
162Modern terminal emulators are able to distinguish between these pairs of keys
163by encoding control modifiers differently. There are two common but distinct
164ways of doing this, known as "modifyOtherKeys" and "CSI u". Nvim supports both
165encoding methods and at startup will tell the terminal emulator that it
166understands these key encodings. If your terminal emulator supports it then
167this will allow you to map the key pairs listed above separately. |<Tab>|
168
169Nvim uses libtermkey to convert terminal escape sequences to key codes.
170|terminfo| is used first, and CSI sequences not in |terminfo| (including
171extended keys a.k.a. "modifyOtherKeys" or "CSI u") can also be parsed.
172
173For example, when running Nvim in tmux, this makes Nvim leave Insert mode and
174go to the window below: >
175        tmux send-keys 'Escape' [ 2 7 u 'C-W' j
176Where `'Escape' [ 2 7 u` is an unambiguous "CSI u" sequence for the <Esc> key.
177
178The kitty keyboard protocol https://sw.kovidgoyal.net/kitty/keyboard-protocol/
179is partially supported, including keypad keys in Unicode Private Use Area.
180For example, this sequence is recognized by Nvim as <C-kEnter>: >
181        CSI 57414 ; 5 u
182and can be used differently from <C-CR> in mappings.
183
184						*tui-modifyOtherKeys* *tui-csiu*
185At startup Nvim will query your terminal to see if it supports the "CSI u"
186encoding by writing the sequence >
187        CSI ? u CSI c
188If your terminal emulator responds with >
189        CSI ? <flags> u
190this means your terminal supports the "CSI u" encoding and Nvim will tell your
191terminal to enable it by writing the sequence >
192        CSI > 3 u
193If your terminal does not support "CSI u" then Nvim will instead enable the
194"modifyOtherKeys" encoding by writing the sequence >
195        CSI > 4 ; 2 m
196
197The "3" requests the kitty keyboard protocol "progressive enhancement" flags
1981 (disambiguate escape codes) and 2 (report event types). Nvim does not
199request 8 (report all keys as escape codes) nor 16 (report associated text),
200which are needed to distinguish keys that produce the same text as their
201unmodified counterpart, such as <S-Space> and <Space>.
202
203When Nvim exits cleanly it will send the corresponding sequence to disable the
204special key encoding. If Nvim does not exit cleanly then your terminal
205emulator could be in a bad state. If this happens, simply run "reset".
206
207							*tui-colors*
208Nvim uses 256 colours by default, ignoring |terminfo| for most terminal types,
209including "linux" (whose virtual terminals have had 256-colour support since
2104.8) and anything claiming to be "xterm".  Also when $COLORTERM or $TERM
211contain the string "256".
212
213Nvim similarly assumes that any terminal emulator that sets $COLORTERM to any
214value, is capable of at least 16-colour operation.
215
216						*true-color* *xterm-true-color*
217Nvim emits true (24-bit) colours in the terminal, if 'termguicolors' is set.
218
219It uses the "setrgbf" and "setrgbb" |terminfo| extensions (proposed by Rüdiger
220Sonderfeld in 2013). If your terminfo definition is missing them, then Nvim
221will decide whether to add them to your terminfo definition, using the ISO
2228613-6:1994/ITU T.416:1993 control sequences for setting RGB colours (but
223modified to use semicolons instead of colons unless the terminal is known to
224follow the standard).
225
226Another convention, pioneered in 2016 by tmux, is the "Tc" terminfo extension.
227If terminfo has this flag, Nvim will add constructed "setrgbf" and "setrgbb"
228capabilities as if they had been in the terminfo definition.
229
230If terminfo does not (yet) have this flag, Nvim will fall back to $TERM and
231other environment variables.  It will add constructed "setrgbf" and "setrgbb"
232capabilities in the case of the "rxvt", "linux", "st", "tmux", and "iterm"
233terminal types, or when Konsole, genuine Xterm, a libvte terminal emulator
234version 0.36 or later, or a terminal emulator that sets the COLORTERM
235environment variable to "truecolor" is detected.
236
237							*xterm-resize*
238Nvim can resize the terminal display on some terminals that implement an
239extension pioneered by dtterm.  |terminfo| does not have a flag for this
240extension.  So Nvim simply assumes that (all) "dtterm", "xterm", "teraterm",
241"rxvt" terminal types, and Konsole, are capable of this.
242
243							*tui-cursor-shape*
244Nvim will adjust the shape of the cursor from a block to a line when in insert
245mode (or as specified by the 'guicursor' option), on terminals that support
246it.  It uses the same |terminfo| extensions that were pioneered by tmux for
247this: "Ss" and "Se".
248Similarly, if you set the cursor highlight group with blend=100, Nvim hides
249the cursor through the "cvvis" and "civis" extensions.
250
251If your terminfo definition is missing them, then Nvim will decide whether to
252add them to your terminfo definition, by looking at $TERM and other
253environment variables.  For the "rxvt", "putty", "linux", "screen",
254"teraterm", and "iterm" terminal types, or when Konsole, a libvte-based
255terminal emulator, or genuine Xterm are detected, it will add constructed
256"Ss" and "Se" capabilities.
257
258							*tui-cursor-tmux*
259Within tmux it may appear that Nvim is not changing the cursor, but in fact it
260is tmux receiving instructions from Nvim to change the cursor and not knowing
261what to do in turn.  tmux must translate what it receives from Nvim into
262whatever control sequence is appropriate for the host terminal.  It shares
263a common mechanism with Nvim, of using the "Ss" and "Se" capabilities from
264terminfo (for the output terminal) if they are present. Unlike Nvim, if they
265are not in terminfo you must add them by setting "terminal-overrides" in
266~/.tmux.conf .
267
268See the tmux(1) manual page for the details of how and what to do in the tmux
269configuration file.  It will look something like: >bash
270        set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
271or (alas!) for Konsole 18.07.70 or older, something more complex like: >bash
272        set -ga terminal-overrides 'xterm*:\E]50;CursorShape=%?%p1%{3}%<%t%{0}%e%{1}%;%d\007'
273<
274==============================================================================
275Window size						*window-size*
276
277[This is about the size of the whole window Vim is using, not a window that is
278created with the ":split" command.]
279
280On Unix systems, three methods are tried to get the window size:
281
282- an ioctl call (TIOCGSIZE or TIOCGWINSZ, depends on your system)
283- the environment variables "LINES" and "COLUMNS"
284- from the |terminfo| entries "lines" and "columns"
285
286If everything fails a default size of 24 lines and 80 columns is assumed.  If
287a window-resize signal is received the size will be set again.  If the window
288size is wrong you can use the 'lines' and 'columns' options to set the
289correct values. See |:mode|.
290
291==============================================================================
292Slow and fast terminals				*slow-fast-terminal*
293						*slow-terminal*
294
295If you have a slow terminal you may want to reset the 'showcmd' and 'ruler'
296options.  The command characters and cursor positions will not be shown in the
297status line (which involves a lot of cursor motions and attribute changes for
298every keypress or movement).  If the terminal scrolls very slowly, set the
299'scrolljump' to 5 or so.  If the cursor is moved off the screen (e.g., with
300"j") Vim will scroll 5 lines at a time.  Another possibility is to reduce the
301number of lines that Vim uses with the command "z{height}<CR>".
302
303If the characters from the terminal are arriving with more than 1 second
304between them you might want to set the 'timeout' and/or 'ttimeout' option.
305
306If you are using a color terminal that is slow when displaying lines beyond
307the end of a buffer, this is because Nvim is drawing the whitespace twice, in
308two sets of colours and attributes.  To prevent this, use this command: >vim
309        hi NonText cterm=NONE ctermfg=NONE
310This draws the spaces with the default colours and attributes, which allows the
311second pass of drawing to be optimized away.  Note: Although in theory the
312colours of whitespace are immaterial, in practice they change the colours of
313cursors and selections that cross them.  This may have a visible, but minor,
314effect on some UIs.
315
316==============================================================================
317Terminfo override                                               *tui-termdefs*
318
319Below are the available fields in |$NVIM_TERMDEFS|. For keys of type `string[]`,
320the first entry is the unshifted variant of the key, and the second entry is
321the shifted variant. >
322
323    Field                      Type
324    -----------------------------------
325    RGB                        bool
326    Su                         bool
327    Tc                         bool
328    back_color_erase           bool
329
330    columns                    int
331    lines                      int
332    max_colors                 int
333
334    carriage_return            string
335    change_scroll_region       string
336    clear_screen               string
337    clr_eol                    string
338    clr_eos                    string
339    cursor_address             string
340    cursor_down                string
341    cursor_home                string
342    cursor_invisible           string
343    cursor_left                string
344    cursor_normal              string
345    cursor_right               string
346    cursor_up                  string
347    delete_line                string
348    enter_blink_mode           string
349    enter_bold_mode            string
350    enter_ca_mode              string
351    enter_dim_mode             string
352    enter_italics_mode         string
353    enter_reverse_mode         string
354    enter_secure_mode          string
355    enter_standout_mode        string
356    enter_underline_mode       string
357    erase_chars                string
358    exit_attribute_mode        string
359    exit_ca_mode               string
360    from_status_line           string
361    insert_line                string
362    keypad_local               string
363    keypad_xmit                string
364    parm_delete_line           string
365    parm_down_cursor           string
366    parm_insert_line           string
367    parm_left_cursor           string
368    parm_right_cursor          string
369    parm_up_cursor             string
370    set_a_background           string
371    set_a_foreground           string
372    set_attributes             string
373    set_lr_margin              string
374    to_status_line             string
375
376    enter_strikethrough_mode   string
377    reset_cursor_color         string
378    reset_cursor_style         string
379    set_cursor_color           string
380    set_cursor_style           string
381    set_rgb_background         string
382    set_rgb_foreground         string
383    set_underline_style        string
384
385    key_backspace              string
386    key_btab                   string
387    key_clear                  string
388    key_npage                  string
389    key_ppage                  string
390    key_select                 string
391
392    key_beg                    string[]
393    key_dc                     string[]
394    key_end                    string[]
395    key_find                   string[]
396    key_home                   string[]
397    key_ic                     string[]
398    key_left                   string[]
399    key_right                  string[]
400    key_suspend                string[]
401    key_undo                   string[]
402
403    key_f1                     string
404    ...                        string
405    key_f63                    string
406<
407
408 vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: