term.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 http://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-colors*
  92. Nvim uses 256 colours by default, ignoring |terminfo| for most terminal types,
  93. including "linux" (whose virtual terminals have had 256-colour support since
  94. 4.8) and anything claiming to be "xterm". Also when $COLORTERM or $TERM
  95. contain the string "256".
  96. Nvim similarly assumes that any terminal emulator that sets $COLORTERM to any
  97. value, is capable of at least 16-colour operation.
  98. *true-color* *xterm-true-color*
  99. Nvim emits true (24-bit) colours in the terminal, if 'termguicolors' is set.
  100. It uses the "setrgbf" and "setrgbb" |terminfo| extensions (proposed by Rüdiger
  101. Sonderfeld in 2013). If your terminfo definition is missing them, then Nvim
  102. will decide whether to add them to your terminfo definition, using the ISO
  103. 8613-6:1994/ITU T.416:1993 control sequences for setting RGB colours (but
  104. modified to use semicolons instead of colons unless the terminal is known to
  105. follow the standard).
  106. Another convention, pioneered in 2016 by tmux, is the "Tc" terminfo extension.
  107. If terminfo has this flag, Nvim will add constructed "setrgbf" and "setrgbb"
  108. capabilities as if they had been in the terminfo definition.
  109. If terminfo does not (yet) have this flag, Nvim will fall back to $TERM and
  110. other environment variables. It will add constructed "setrgbf" and "setrgbb"
  111. capabilities in the case of the the "rxvt", "linux", "st", "tmux", and "iterm"
  112. terminal types, or when Konsole, genuine Xterm, a libvte terminal emulator
  113. version 0.36 or later, or a terminal emulator that sets the COLORTERM
  114. environment variable to "truecolor" is detected.
  115. *xterm-resize*
  116. Nvim can resize the terminal display on some terminals that implement an
  117. extension pioneered by dtterm. |terminfo| does not have a flag for this
  118. extension. So Nvim simply assumes that (all) "dtterm", "xterm", "teraterm",
  119. "rxvt" terminal types, and Konsole, are capable of this.
  120. *tui-cursor-shape*
  121. Nvim will adjust the shape of the cursor from a block to a line when in insert
  122. mode (or as specified by the 'guicursor' option), on terminals that support
  123. it. It uses the same |terminfo| extensions that were pioneered by tmux for
  124. this: "Ss" and "Se".
  125. If your terminfo definition is missing them, then Nvim will decide whether to
  126. add them to your terminfo definition, by looking at $TERM and other
  127. environment variables. For the "rxvt", "putty", "linux", "screen",
  128. "teraterm", and "iterm" terminal types, or when Konsole, a libvte-based
  129. terminal emulator, or genuine Xterm are detected, it will add constructed
  130. "Ss" and "Se" capabilities.
  131. *tui-cursor-tmux*
  132. Within tmux it may appear that Nvim is not changing the cursor, but in fact it
  133. is tmux receiving instructions from Nvim to change the cursor and not knowing
  134. what to do in turn. tmux must translate what it receives from Nvim into
  135. whatever control sequence is appropriate for the host terminal. It shares
  136. a common mechanism with Nvim, of using the "Ss" and "Se" capabilities from
  137. terminfo (for the output terminal) if they are present. Unlike Nvim, if they
  138. are not in terminfo you must add them by setting "terminal-overrides" in
  139. ~/.tmux.conf .
  140. See the tmux(1) manual page for the details of how and what to do in the tmux
  141. configuration file. It will look something like: >
  142. set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
  143. <or (alas!) for Konsole 18.07.70 or older, something more complex like: >
  144. set -ga terminal-overrides 'xterm*:\E]50;CursorShape=%?%p1%{3}%<%t%{0}%e%{1}%;%d\007'
  145. <
  146. ==============================================================================
  147. Window size *window-size*
  148. [This is about the size of the whole window Vim is using, not a window that is
  149. created with the ":split" command.]
  150. On Unix systems, three methods are tried to get the window size:
  151. - an ioctl call (TIOCGSIZE or TIOCGWINSZ, depends on your system)
  152. - the environment variables "LINES" and "COLUMNS"
  153. - from the |terminfo| entries "lines" and "columns"
  154. If everything fails a default size of 24 lines and 80 columns is assumed. If
  155. a window-resize signal is received the size will be set again. If the window
  156. size is wrong you can use the 'lines' and 'columns' options to set the
  157. correct values. See |:mode|.
  158. ==============================================================================
  159. Slow and fast terminals *slow-fast-terminal*
  160. *slow-terminal*
  161. If you have a slow terminal you may want to reset the 'showcmd' and 'ruler'
  162. options. The command characters and cursor positions will not be shown in the
  163. status line (which involves a lot of cursor motions and attribute changes for
  164. every keypress or movement). If the terminal scrolls very slowly, set the
  165. 'scrolljump' to 5 or so. If the cursor is moved off the screen (e.g., with
  166. "j") Vim will scroll 5 lines at a time. Another possibility is to reduce the
  167. number of lines that Vim uses with the command "z{height}<CR>".
  168. If the characters from the terminal are arriving with more than 1 second
  169. between them you might want to set the 'timeout' and/or 'ttimeout' option.
  170. See the "Options" chapter |options|.
  171. If you are using a color terminal that is slow when displaying lines beyond
  172. the end of a buffer, this is because Nvim is drawing the whitespace twice, in
  173. two sets of colours and attributes. To prevent this, use this command: >
  174. hi NonText cterm=NONE ctermfg=NONE
  175. This draws the spaces with the default colours and attributes, which allows the
  176. second pass of drawing to be optimized away. Note: Although in theory the
  177. colours of whitespace are immaterial, in practice they change the colours of
  178. cursors and selections that cross them. This may have a visible, but minor,
  179. effect on some UIs.
  180. ==============================================================================
  181. Using the mouse *mouse-using*
  182. *mouse-mode-table* *mouse-overview*
  183. Overview of what the mouse buttons do, when 'mousemodel' is "extend":
  184. Normal Mode:
  185. event position selection change action ~
  186. cursor window ~
  187. <LeftMouse> yes end yes
  188. <C-LeftMouse> yes end yes "CTRL-]" (2)
  189. <S-LeftMouse> yes no change yes "*" (2) *<S-LeftMouse>*
  190. <LeftDrag> yes start or extend (1) no *<LeftDrag>*
  191. <LeftRelease> yes start or extend (1) no
  192. <MiddleMouse> yes if not active no put
  193. <MiddleMouse> yes if active no yank and put
  194. <RightMouse> yes start or extend yes
  195. <A-RightMouse> yes start or extend blockw. yes *<A-RightMouse>*
  196. <S-RightMouse> yes no change yes "#" (2) *<S-RightMouse>*
  197. <C-RightMouse> no no change no "CTRL-T"
  198. <RightDrag> yes extend no *<RightDrag>*
  199. <RightRelease> yes extend no *<RightRelease>*
  200. Insert or Replace Mode:
  201. event position selection change action ~
  202. cursor window ~
  203. <LeftMouse> yes (cannot be active) yes
  204. <C-LeftMouse> yes (cannot be active) yes "CTRL-O^]" (2)
  205. <S-LeftMouse> yes (cannot be active) yes "CTRL-O*" (2)
  206. <LeftDrag> yes start or extend (1) no like CTRL-O (1)
  207. <LeftRelease> yes start or extend (1) no like CTRL-O (1)
  208. <MiddleMouse> no (cannot be active) no put register
  209. <RightMouse> yes start or extend yes like CTRL-O
  210. <A-RightMouse> yes start or extend blockw. yes
  211. <S-RightMouse> yes (cannot be active) yes "CTRL-O#" (2)
  212. <C-RightMouse> no (cannot be active) no "CTRL-O CTRL-T"
  213. In a help window:
  214. event position selection change action ~
  215. cursor window ~
  216. <2-LeftMouse> yes (cannot be active) no "^]" (jump to help tag)
  217. When 'mousemodel' is "popup", these are different:
  218. Normal Mode:
  219. event position selection change action ~
  220. cursor window ~
  221. <S-LeftMouse> yes start or extend (1) no
  222. <A-LeftMouse> yes start or extend blockw. no *<A-LeftMouse>*
  223. <RightMouse> no popup menu no
  224. Insert or Replace Mode:
  225. event position selection change action ~
  226. cursor window ~
  227. <S-LeftMouse> yes start or extend (1) no like CTRL-O (1)
  228. <A-LeftMouse> yes start or extend blockw. no
  229. <RightMouse> no popup menu no
  230. (1) only if mouse pointer moved since press
  231. (2) only if click is in same buffer
  232. Clicking the left mouse button causes the cursor to be positioned. If the
  233. click is in another window that window is made the active window. When
  234. editing the command-line the cursor can only be positioned on the
  235. command-line. When in Insert mode Vim remains in Insert mode. If 'scrolloff'
  236. is set, and the cursor is positioned within 'scrolloff' lines from the window
  237. border, the text is scrolled.
  238. A selection can be started by pressing the left mouse button on the first
  239. character, moving the mouse to the last character, then releasing the mouse
  240. button. You will not always see the selection until you release the button,
  241. only in some versions (GUI, Windows) will the dragging be shown immediately.
  242. Note that you can make the text scroll by moving the mouse at least one
  243. character in the first/last line in the window when 'scrolloff' is non-zero.
  244. In Normal, Visual and Select mode clicking the right mouse button causes the
  245. Visual area to be extended. When 'mousemodel' is "popup", the left button has
  246. to be used while keeping the shift key pressed. When clicking in a window
  247. which is editing another buffer, the Visual or Select mode is stopped.
  248. In Normal, Visual and Select mode clicking the right mouse button with the alt
  249. key pressed causes the Visual area to become blockwise. When 'mousemodel' is
  250. "popup" the left button has to be used with the alt key. Note that this won't
  251. work on systems where the window manager consumes the mouse events when the
  252. alt key is pressed (it may move the window).
  253. *double-click*
  254. Double, triple and quadruple clicks are supported when the GUI is active, for
  255. Windows and for an xterm. For selecting text, extra clicks extend the
  256. selection:
  257. click select ~
  258. double word or % match *<2-LeftMouse>*
  259. triple line *<3-LeftMouse>*
  260. quadruple rectangular block *<4-LeftMouse>*
  261. Exception: In a Help window a double click jumps to help for the word that is
  262. clicked on.
  263. A double click on a word selects that word. 'iskeyword' is used to specify
  264. which characters are included in a word. A double click on a character
  265. that has a match selects until that match (like using "v%"). If the match is
  266. an #if/#else/#endif block, the selection becomes linewise.
  267. For MS-DOS and xterm the time for double clicking can be set with the
  268. 'mousetime' option. For the other systems this time is defined outside of
  269. Vim.
  270. An example, for using a double click to jump to the tag under the cursor: >
  271. :map <2-LeftMouse> :exe "tag ". expand("<cword>")<CR>
  272. Dragging the mouse with a double click (button-down, button-up, button-down
  273. and then drag) will result in whole words to be selected. This continues
  274. until the button is released, at which point the selection is per character
  275. again.
  276. In Insert mode, when a selection is started, Vim goes into Normal mode
  277. temporarily. When Visual or Select mode ends, it returns to Insert mode.
  278. This is like using CTRL-O in Insert mode. Select mode is used when the
  279. 'selectmode' option contains "mouse".
  280. *<MiddleRelease>* *<MiddleDrag>*
  281. Mouse clicks can be mapped. The codes for mouse clicks are:
  282. code mouse button normal action ~
  283. <LeftMouse> left pressed set cursor position
  284. <LeftDrag> left moved while pressed extend selection
  285. <LeftRelease> left released set selection end
  286. <MiddleMouse> middle pressed paste text at cursor position
  287. <MiddleDrag> middle moved while pressed -
  288. <MiddleRelease> middle released -
  289. <RightMouse> right pressed extend selection
  290. <RightDrag> right moved while pressed extend selection
  291. <RightRelease> right released set selection end
  292. <X1Mouse> X1 button pressed - *X1Mouse*
  293. <X1Drag> X1 moved while pressed - *X1Drag*
  294. <X1Release> X1 button release - *X1Release*
  295. <X2Mouse> X2 button pressed - *X2Mouse*
  296. <X2Drag> X2 moved while pressed - *X2Drag*
  297. <X2Release> X2 button release - *X2Release*
  298. The X1 and X2 buttons refer to the extra buttons found on some mice. The
  299. 'Microsoft Explorer' mouse has these buttons available to the right thumb.
  300. Currently X1 and X2 only work on Win32 and X11 environments.
  301. Examples: >
  302. :noremap <MiddleMouse> <LeftMouse><MiddleMouse>
  303. Paste at the position of the middle mouse button click (otherwise the paste
  304. would be done at the cursor position). >
  305. :noremap <LeftRelease> <LeftRelease>y
  306. Immediately yank the selection, when using Visual mode.
  307. Note the use of ":noremap" instead of "map" to avoid a recursive mapping.
  308. >
  309. :map <X1Mouse> <C-O>
  310. :map <X2Mouse> <C-I>
  311. Map the X1 and X2 buttons to go forwards and backwards in the jump list, see
  312. |CTRL-O| and |CTRL-I|.
  313. *mouse-swap-buttons*
  314. To swap the meaning of the left and right mouse buttons: >
  315. :noremap <LeftMouse> <RightMouse>
  316. :noremap <LeftDrag> <RightDrag>
  317. :noremap <LeftRelease> <RightRelease>
  318. :noremap <RightMouse> <LeftMouse>
  319. :noremap <RightDrag> <LeftDrag>
  320. :noremap <RightRelease> <LeftRelease>
  321. :noremap g<LeftMouse> <C-RightMouse>
  322. :noremap g<RightMouse> <C-LeftMouse>
  323. :noremap! <LeftMouse> <RightMouse>
  324. :noremap! <LeftDrag> <RightDrag>
  325. :noremap! <LeftRelease> <RightRelease>
  326. :noremap! <RightMouse> <LeftMouse>
  327. :noremap! <RightDrag> <LeftDrag>
  328. :noremap! <RightRelease> <LeftRelease>
  329. <
  330. vim:tw=78:ts=8:ft=help:norl: