tui.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. *tui.txt* Nvim
  2. NVIM REFERENCE MANUAL
  3. Terminal UI *TUI* *tui*
  4. By default when you run `nvim` (without |--embed| or |--headless|) it starts
  5. the builtin "terminal UI" (TUI). This default UI is optional: you can run Nvim
  6. as a "headless" server, or you can use a |GUI|.
  7. Type |gO| to see the table of contents.
  8. ==============================================================================
  9. Startup *startup-tui* *startup-terminal*
  10. Nvim has a client-server architecture: by default when you run `nvim`, this
  11. starts the builtin UI client, which starts a `nvim --embed` server (child)
  12. process that the UI client connects to. After attaching to the server, the UI
  13. client calls |nvim_set_client_info()| (as recommended for all UIs |dev-ui|)
  14. and sets these fields on its channel: >
  15. client = {
  16. attributes = {
  17. license = 'Apache 2',
  18. pid = …,
  19. website = 'https://neovim.io',
  20. },
  21. name = 'nvim-tui',
  22. type = 'ui',
  23. version = { … },
  24. }
  25. Nvim guesses the terminal type when it starts (except in |--embed| and
  26. |--headless| modes). The |$TERM| environment variable is the primary hint that
  27. determines the terminal type.
  28. *terminfo* *E557* *E558* *E559*
  29. To display its user interface, Nvim reads a list of "terminal capabilities"
  30. from the system terminfo database (or builtin defaults if terminfo is not
  31. found). If that information is wrong, the screen may be messed up or keys may
  32. not be recognized.
  33. The Unibilium library (used to read terminfo) allows you to override the
  34. system terminfo with one in the "$HOME/.terminfo/" directory. Building your
  35. own terminfo is usually as simple as running this:
  36. >
  37. curl -LO https://invisible-island.net/datafiles/current/terminfo.src.gz
  38. gunzip terminfo.src.gz
  39. tic -x terminfo.src
  40. <
  41. *$TERM*
  42. The $TERM environment variable must match the terminal you are using!
  43. Otherwise Nvim cannot know what sequences your terminal expects, and weird
  44. or sub-optimal behavior will result (scrolling quirks, wrong colors, etc.).
  45. $TERM is also important because it is forwarded by SSH to the remote session,
  46. unlike most other environment variables.
  47. >
  48. For this terminal Set $TERM to |builtin-terms|
  49. -------------------------------------------------------------------------
  50. anything libvte-based vte, vte-256color Y
  51. (e.g. GNOME Terminal) (aliases: gnome, gnome-256color)
  52. iTerm (original) iterm, iTerm.app N
  53. iTerm2 (new capabilities) iterm2, iTerm2.app Y
  54. Konsole konsole-256color N
  55. Linux virtual terminal linux, linux-256color Y
  56. PuTTY putty, putty-256color Y
  57. rxvt rxvt, rxvt-256color Y
  58. screen screen, screen-256color Y
  59. simple terminal (st) st, st-256color Y
  60. Terminal.app nsterm N
  61. tmux tmux, tmux-256color Y
  62. Windows/ConEmu conemu Y
  63. Windows/Cygwin-built Nvim cygwin Y
  64. Windows/Interix interix Y
  65. Windows/VTP console vtpcon Y
  66. Windows/legacy console win32con Y
  67. xterm or compatible xterm, xterm-256color Y
  68. <
  69. *builtin-terms* *builtin_terms*
  70. If a |terminfo| database is not available or there is no entry for the current
  71. terminal, Nvim will map |$TERM| to a builtin entry according to the above
  72. table, or "ansi" if there is no match. For example "TERM=putty-256color" will
  73. be mapped to the builtin "putty" entry. See also |tui-colors|.
  74. The builtin terminfo is not combined with any external terminfo database, nor
  75. can it be used in preference to one. You can thus entirely override any
  76. omissions or out-of-date information in the builtin terminfo database by
  77. supplying an external one with entries for the terminal type.
  78. Settings depending on terminal *term-dependent-settings*
  79. If you want to set terminal-dependent options or mappings, you can do this in
  80. your init.vim. Example: >vim
  81. if $TERM =~ '^\(rxvt\|screen\|interix\|putty\)\(-.*\)\?$'
  82. set notermguicolors
  83. elseif $TERM =~ '^\(tmux\|iterm\|vte\|gnome\)\(-.*\)\?$'
  84. set termguicolors
  85. elseif $TERM =~ '^\(xterm\)\(-.*\)\?$'
  86. if $XTERM_VERSION != ''
  87. set termguicolors
  88. elseif $KONSOLE_PROFILE_NAME != ''
  89. set termguicolors
  90. elseif $VTE_VERSION != ''
  91. set termguicolors
  92. else
  93. set notermguicolors
  94. endif
  95. elseif $TERM =~ ...
  96. ... and so forth ...
  97. endif
  98. <
  99. *scroll-region* *xterm-scroll-region*
  100. Where possible, Nvim will use the terminal's ability to set a scroll region in
  101. order to redraw faster when a window is scrolled. If the terminal's terminfo
  102. description describes an ability to set top and bottom scroll margins, that is
  103. used.
  104. This will not speed up scrolling in a window that is not the full width of the
  105. terminal. Xterm has an extra ability, not described by terminfo, to set left
  106. and right scroll margins as well. If Nvim detects that the terminal is Xterm,
  107. it will make use of this ability to speed up scrolling that is not the full
  108. width of the terminal.
  109. *tui-input*
  110. Historically, terminal emulators could not distinguish between certain control
  111. key modifiers and other keys. For example, <C-I> and <Tab> are represented in
  112. the same way, as are <Esc> and <C-[>, <CR> and <C-M>, and <NL> and <C-J>.
  113. Modern terminal emulators are able to distinguish between these pairs of keys
  114. by encoding control modifiers differently. There are two common but distinct
  115. ways of doing this, known as "modifyOtherKeys" and "CSI u". Nvim supports both
  116. encoding methods and at startup will tell the terminal emulator that it
  117. understands these key encodings. If your terminal emulator supports it then
  118. this will allow you to map the key pairs listed above separately. |<Tab>|
  119. Nvim uses libtermkey to convert terminal escape sequences to key codes.
  120. |terminfo| is used first, and CSI sequences not in |terminfo| (including
  121. extended keys a.k.a. "modifyOtherKeys" or "CSI u") can also be parsed.
  122. For example, when running Nvim in tmux, this makes Nvim leave Insert mode and
  123. go to the window below: >
  124. tmux send-keys 'Escape' [ 2 7 u 'C-W' j
  125. Where `'Escape' [ 2 7 u` is an unambiguous "CSI u" sequence for the <Esc> key.
  126. The kitty keyboard protocol https://sw.kovidgoyal.net/kitty/keyboard-protocol/
  127. is partially supported, including keypad keys in Unicode Private Use Area.
  128. For example, this sequence is recognized by Nvim as <C-kEnter>: >
  129. CSI 57414 ; 5 u
  130. and can be used differently from <C-CR> in mappings.
  131. *tui-modifyOtherKeys* *tui-csiu*
  132. At startup Nvim will query your terminal to see if it supports the "CSI u"
  133. encoding by writing the sequence >
  134. CSI ? u CSI c
  135. If your terminal emulator responds with >
  136. CSI ? <flags> u
  137. this means your terminal supports the "CSI u" encoding and Nvim will tell your
  138. terminal to enable it by writing the sequence >
  139. CSI > 1 u
  140. If your terminal does not support "CSI u" then Nvim will instead enable the
  141. "modifyOtherKeys" encoding by writing the sequence >
  142. CSI > 4 ; 2 m
  143. When Nvim exits cleanly it will send the corresponding sequence to disable the
  144. special key encoding. If Nvim does not exit cleanly then your terminal
  145. emulator could be in a bad state. If this happens, simply run "reset".
  146. *tui-colors*
  147. Nvim uses 256 colours by default, ignoring |terminfo| for most terminal types,
  148. including "linux" (whose virtual terminals have had 256-colour support since
  149. 4.8) and anything claiming to be "xterm". Also when $COLORTERM or $TERM
  150. contain the string "256".
  151. Nvim similarly assumes that any terminal emulator that sets $COLORTERM to any
  152. value, is capable of at least 16-colour operation.
  153. *true-color* *xterm-true-color*
  154. Nvim emits true (24-bit) colours in the terminal, if 'termguicolors' is set.
  155. It uses the "setrgbf" and "setrgbb" |terminfo| extensions (proposed by Rüdiger
  156. Sonderfeld in 2013). If your terminfo definition is missing them, then Nvim
  157. will decide whether to add them to your terminfo definition, using the ISO
  158. 8613-6:1994/ITU T.416:1993 control sequences for setting RGB colours (but
  159. modified to use semicolons instead of colons unless the terminal is known to
  160. follow the standard).
  161. Another convention, pioneered in 2016 by tmux, is the "Tc" terminfo extension.
  162. If terminfo has this flag, Nvim will add constructed "setrgbf" and "setrgbb"
  163. capabilities as if they had been in the terminfo definition.
  164. If terminfo does not (yet) have this flag, Nvim will fall back to $TERM and
  165. other environment variables. It will add constructed "setrgbf" and "setrgbb"
  166. capabilities in the case of the "rxvt", "linux", "st", "tmux", and "iterm"
  167. terminal types, or when Konsole, genuine Xterm, a libvte terminal emulator
  168. version 0.36 or later, or a terminal emulator that sets the COLORTERM
  169. environment variable to "truecolor" is detected.
  170. *xterm-resize*
  171. Nvim can resize the terminal display on some terminals that implement an
  172. extension pioneered by dtterm. |terminfo| does not have a flag for this
  173. extension. So Nvim simply assumes that (all) "dtterm", "xterm", "teraterm",
  174. "rxvt" terminal types, and Konsole, are capable of this.
  175. *tui-cursor-shape*
  176. Nvim will adjust the shape of the cursor from a block to a line when in insert
  177. mode (or as specified by the 'guicursor' option), on terminals that support
  178. it. It uses the same |terminfo| extensions that were pioneered by tmux for
  179. this: "Ss" and "Se".
  180. Similarly, if you set the cursor highlight group with blend=100, Nvim hides
  181. the cursor through the "cvvis" and "civis" extensions.
  182. If your terminfo definition is missing them, then Nvim will decide whether to
  183. add them to your terminfo definition, by looking at $TERM and other
  184. environment variables. For the "rxvt", "putty", "linux", "screen",
  185. "teraterm", and "iterm" terminal types, or when Konsole, a libvte-based
  186. terminal emulator, or genuine Xterm are detected, it will add constructed
  187. "Ss" and "Se" capabilities.
  188. *tui-cursor-tmux*
  189. Within tmux it may appear that Nvim is not changing the cursor, but in fact it
  190. is tmux receiving instructions from Nvim to change the cursor and not knowing
  191. what to do in turn. tmux must translate what it receives from Nvim into
  192. whatever control sequence is appropriate for the host terminal. It shares
  193. a common mechanism with Nvim, of using the "Ss" and "Se" capabilities from
  194. terminfo (for the output terminal) if they are present. Unlike Nvim, if they
  195. are not in terminfo you must add them by setting "terminal-overrides" in
  196. ~/.tmux.conf .
  197. See the tmux(1) manual page for the details of how and what to do in the tmux
  198. configuration file. It will look something like: >bash
  199. set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
  200. or (alas!) for Konsole 18.07.70 or older, something more complex like: >bash
  201. set -ga terminal-overrides 'xterm*:\E]50;CursorShape=%?%p1%{3}%<%t%{0}%e%{1}%;%d\007'
  202. <
  203. ==============================================================================
  204. Window size *window-size*
  205. [This is about the size of the whole window Vim is using, not a window that is
  206. created with the ":split" command.]
  207. On Unix systems, three methods are tried to get the window size:
  208. - an ioctl call (TIOCGSIZE or TIOCGWINSZ, depends on your system)
  209. - the environment variables "LINES" and "COLUMNS"
  210. - from the |terminfo| entries "lines" and "columns"
  211. If everything fails a default size of 24 lines and 80 columns is assumed. If
  212. a window-resize signal is received the size will be set again. If the window
  213. size is wrong you can use the 'lines' and 'columns' options to set the
  214. correct values. See |:mode|.
  215. ==============================================================================
  216. Slow and fast terminals *slow-fast-terminal*
  217. *slow-terminal*
  218. If you have a slow terminal you may want to reset the 'showcmd' and 'ruler'
  219. options. The command characters and cursor positions will not be shown in the
  220. status line (which involves a lot of cursor motions and attribute changes for
  221. every keypress or movement). If the terminal scrolls very slowly, set the
  222. 'scrolljump' to 5 or so. If the cursor is moved off the screen (e.g., with
  223. "j") Vim will scroll 5 lines at a time. Another possibility is to reduce the
  224. number of lines that Vim uses with the command "z{height}<CR>".
  225. If the characters from the terminal are arriving with more than 1 second
  226. between them you might want to set the 'timeout' and/or 'ttimeout' option.
  227. If you are using a color terminal that is slow when displaying lines beyond
  228. the end of a buffer, this is because Nvim is drawing the whitespace twice, in
  229. two sets of colours and attributes. To prevent this, use this command: >vim
  230. hi NonText cterm=NONE ctermfg=NONE
  231. This draws the spaces with the default colours and attributes, which allows the
  232. second pass of drawing to be optimized away. Note: Although in theory the
  233. colours of whitespace are immaterial, in practice they change the colours of
  234. cursors and selections that cross them. This may have a visible, but minor,
  235. effect on some UIs.
  236. ==============================================================================
  237. Using the mouse *mouse-using*
  238. *mouse-mode-table* *mouse-overview*
  239. Overview of what the mouse buttons do, when 'mousemodel' is "extend":
  240. *<S-LeftMouse>* *<A-RightMouse>* *<S-RightMouse>* *<RightDrag>*
  241. *<RightRelease>* *<LeftDrag>*
  242. Normal Mode: >
  243. event position selection change action
  244. cursor window
  245. ---------------------------------------------------------------------------
  246. <LeftMouse> yes end yes
  247. <C-LeftMouse> yes end yes "CTRL-]" (2)
  248. <S-LeftMouse> yes no change yes "*" (2)
  249. <LeftDrag> yes start or extend (1) no
  250. <LeftRelease> yes start or extend (1) no
  251. <MiddleMouse> yes if not active no put
  252. <MiddleMouse> yes if active no yank and put
  253. <RightMouse> yes start or extend yes
  254. <A-RightMouse> yes start or extend blockw. yes
  255. <S-RightMouse> yes no change yes "#" (2)
  256. <C-RightMouse> no no change no "CTRL-T"
  257. <RightDrag> yes extend no
  258. <RightRelease> yes extend no
  259. Insert or Replace Mode: >
  260. event position selection change action
  261. cursor window
  262. ---------------------------------------------------------------------------
  263. <LeftMouse> yes (cannot be active) yes
  264. <C-LeftMouse> yes (cannot be active) yes "CTRL-O^]" (2)
  265. <S-LeftMouse> yes (cannot be active) yes "CTRL-O*" (2)
  266. <LeftDrag> yes start or extend (1) no like CTRL-O (1)
  267. <LeftRelease> yes start or extend (1) no like CTRL-O (1)
  268. <MiddleMouse> no (cannot be active) no put register
  269. <RightMouse> yes start or extend yes like CTRL-O
  270. <A-RightMouse> yes start or extend blockw. yes
  271. <S-RightMouse> yes (cannot be active) yes "CTRL-O#" (2)
  272. <C-RightMouse> no (cannot be active) no "CTRL-O CTRL-T"
  273. In a help window: >
  274. event position selection change action
  275. cursor window
  276. ---------------------------------------------------------------------------
  277. <2-LeftMouse> yes (cannot be active) no "^]" (jump to help tag)
  278. When 'mousemodel' is "popup", these are different:
  279. *<A-LeftMouse>*
  280. Normal Mode: >
  281. event position selection change action
  282. cursor window
  283. ---------------------------------------------------------------------------
  284. <S-LeftMouse> yes start or extend (1) no
  285. <A-LeftMouse> yes start/extend blockw no
  286. <RightMouse> no popup menu no
  287. Insert or Replace Mode: >
  288. event position selection change action
  289. cursor window
  290. ---------------------------------------------------------------------------
  291. <S-LeftMouse> yes start or extend (1) no like CTRL-O (1)
  292. <A-LeftMouse> yes start/extend blockw no
  293. <RightMouse> no popup menu no
  294. (1) only if mouse pointer moved since press
  295. (2) only if click is in same buffer
  296. Clicking the left mouse button causes the cursor to be positioned. If the
  297. click is in another window that window is made the active window. When
  298. editing the command-line the cursor can only be positioned on the
  299. command-line. When in Insert mode Vim remains in Insert mode. If 'scrolloff'
  300. is set, and the cursor is positioned within 'scrolloff' lines from the window
  301. border, the text is scrolled.
  302. A selection can be started by pressing the left mouse button on the first
  303. character, moving the mouse to the last character, then releasing the mouse
  304. button. You will not always see the selection until you release the button,
  305. only in some versions (GUI, Win32) will the dragging be shown immediately.
  306. Note that you can make the text scroll by moving the mouse at least one
  307. character in the first/last line in the window when 'scrolloff' is non-zero.
  308. In Normal, Visual and Select mode clicking the right mouse button causes the
  309. Visual area to be extended. When 'mousemodel' is "popup", the left button has
  310. to be used while keeping the shift key pressed. When clicking in a window
  311. which is editing another buffer, the Visual or Select mode is stopped.
  312. In Normal, Visual and Select mode clicking the right mouse button with the alt
  313. key pressed causes the Visual area to become blockwise. When 'mousemodel' is
  314. "popup" the left button has to be used with the alt key. Note that this won't
  315. work on systems where the window manager consumes the mouse events when the
  316. alt key is pressed (it may move the window).
  317. *double-click* *<2-LeftMouse>* *<3-LeftMouse>* *<4-LeftMouse>*
  318. Double, triple and quadruple clicks are supported when the GUI is active, for
  319. Win32 and for an xterm. For selecting text, extra clicks extend the
  320. selection: >
  321. click select
  322. ---------------------------------
  323. double word or % match
  324. triple line
  325. quadruple rectangular block
  326. Exception: In a Help window a double click jumps to help for the word that is
  327. clicked on.
  328. A double click on a word selects that word. 'iskeyword' is used to specify
  329. which characters are included in a word. A double click on a character
  330. that has a match selects until that match (like using "v%"). If the match is
  331. an #if/#else/#endif block, the selection becomes linewise.
  332. For MS-Windows and xterm the time for double clicking can be set with the
  333. 'mousetime' option. For the other systems this time is defined outside of Vim.
  334. An example, for using a double click to jump to the tag under the cursor: >vim
  335. :map <2-LeftMouse> :exe "tag " .. expand("<cword>")<CR>
  336. Dragging the mouse with a double click (button-down, button-up, button-down
  337. and then drag) will result in whole words to be selected. This continues
  338. until the button is released, at which point the selection is per character
  339. again.
  340. For scrolling with the mouse see |scroll-mouse-wheel|.
  341. In Insert mode, when a selection is started, Vim goes into Normal mode
  342. temporarily. When Visual or Select mode ends, it returns to Insert mode.
  343. This is like using CTRL-O in Insert mode. Select mode is used when the
  344. 'selectmode' option contains "mouse".
  345. *X1Mouse* *X1Drag* *X1Release*
  346. *X2Mouse* *X2Drag* *X2Release*
  347. *<MiddleRelease>* *<MiddleDrag>*
  348. Mouse clicks can be mapped. The codes for mouse clicks are: >
  349. code mouse button normal action
  350. ---------------------------------------------------------------------------
  351. <LeftMouse> left pressed set cursor position
  352. <LeftDrag> left moved while pressed extend selection
  353. <LeftRelease> left released set selection end
  354. <MiddleMouse> middle pressed paste text at cursor position
  355. <MiddleDrag> middle moved while pressed -
  356. <MiddleRelease> middle released -
  357. <RightMouse> right pressed extend selection
  358. <RightDrag> right moved while pressed extend selection
  359. <RightRelease> right released set selection end
  360. <X1Mouse> X1 button pressed -
  361. <X1Drag> X1 moved while pressed -
  362. <X1Release> X1 button release -
  363. <X2Mouse> X2 button pressed -
  364. <X2Drag> X2 moved while pressed -
  365. <X2Release> X2 button release -
  366. The X1 and X2 buttons refer to the extra buttons found on some mice. The
  367. 'Microsoft Explorer' mouse has these buttons available to the right thumb.
  368. Currently X1 and X2 only work on Win32 and X11 environments.
  369. Examples: >vim
  370. :noremap <MiddleMouse> <LeftMouse><MiddleMouse>
  371. Paste at the position of the middle mouse button click (otherwise the paste
  372. would be done at the cursor position). >vim
  373. :noremap <LeftRelease> <LeftRelease>y
  374. Immediately yank the selection, when using Visual mode.
  375. Note the use of ":noremap" instead of "map" to avoid a recursive mapping.
  376. >vim
  377. :map <X1Mouse> <C-O>
  378. :map <X2Mouse> <C-I>
  379. Map the X1 and X2 buttons to go forwards and backwards in the jump list, see
  380. |CTRL-O| and |CTRL-I|.
  381. *mouse-swap-buttons*
  382. To swap the meaning of the left and right mouse buttons: >vim
  383. :noremap <LeftMouse> <RightMouse>
  384. :noremap <LeftDrag> <RightDrag>
  385. :noremap <LeftRelease> <RightRelease>
  386. :noremap <RightMouse> <LeftMouse>
  387. :noremap <RightDrag> <LeftDrag>
  388. :noremap <RightRelease> <LeftRelease>
  389. :noremap g<LeftMouse> <C-RightMouse>
  390. :noremap g<RightMouse> <C-LeftMouse>
  391. :noremap! <LeftMouse> <RightMouse>
  392. :noremap! <LeftDrag> <RightDrag>
  393. :noremap! <LeftRelease> <RightRelease>
  394. :noremap! <RightMouse> <LeftMouse>
  395. :noremap! <RightDrag> <LeftDrag>
  396. :noremap! <RightRelease> <LeftRelease>
  397. <
  398. vim:et:sw=2:tw=78:ts=8:ft=help:norl: