term.txt 20 KB

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