neovim/runtime/doc/term.txt

522 lines
24 KiB
Plaintext
Raw Normal View History

*term.txt* Nvim
VIM REFERENCE MANUAL by Bram Moolenaar
Terminal information
Vim uses information about the terminal you are using to fill the screen and
recognize what keys you hit. If this information is not correct, the screen
may be messed up or keys may not be recognized. The actions which have to be
performed on the screen are accomplished by outputting a string of
characters.
Type <M-]> to see the table of contents.
==============================================================================
Startup *startup-terminal*
When Vim is started a default terminal type is assumed. for MS-DOS this is
the pc terminal, for Unix an ansi terminal.
*terminfo* *E557* *E558* *E559*
On Unix the terminfo database is used. There is no access to the terminfo
settings with |:set|.
*TERM*
If you experience terminal difficulties, first ensure that you have set the
correct terminal type in your $TERM environment variable so that Nvim is
pulling the correct entry from the terminfo database in the first place.
As noted in the commentary in the terminfo source file:
- The correct $TERM for GNOME Terminal has been "gnome" since 1999, or
"gnome-256color" since 2006. "vte" and "vte-256color" are equivalents.
"xterm" and "xterm-256color" are incorrect.
- The correct $TERM for iTerm.app is "iterm" or "iTerm.app". "xterm" and
"xterm-256color" are incorrect; for starters they do not include
iTerm.app's status line capability.
- The correct $TERM for Terminal.app is "nsterm". "vt100", "xterm", and
"xterm-256color" are incorrect; for starters they do not include
Terminal.app's status line capability or correctly describe its
cursor-addressed mode.
- The correct $TERM for tmux is "tmux" or "tmux-256color". "screen" is
incorrect; for starters it does not include tmux's italics and status line
capabilities or correctly describe how to set inverse video.
Setting your $TERM environment variable to the correct value also avoids the
problem that SSH does not mirror arbitrary client-end environment variables
such as $COLORTERM, $XTERM_VERSION, $VTE_VERSION, $KONSOLE_PROFILE_NAME, and
$TERM_PROGRAM to the server end, whereas it does send the $TERM environment
variable.
Note that the Unibilium library (used by Nvim to read terminfo) allows you to
override an out-of-date system terminfo database with one in your
$HOME/.terminfo/ directory, in part or in whole.
*builtin-terms* *builtin_terms*
If a |terminfo| database is not available, or no entry for the terminal type is
found in that database, Nvim will look up the terminal type in a compiled-in
mini-database of terminfo entries for "xterm", "putty", "screen", "tmux",
"rxvt", "iterm", "interix", "linux", "st", "vte", "gnome", and "ansi".
The lookup matches the initial portion of the terminal type, so (for example)
"putty-256color" and "putty" will both be mapped to the built-in "putty"
entry. The built-in terminfo entries describe the terminal as 256-colour
capable if possible. See |termcap-colors|.
If no built-in terminfo record matches the terminal type, the built-in "ansi"
terminfo record is used as a final fallback.
The built-in mini-database is not combined with an 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 built-in 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 options or mappings, depending on the terminal name, you
can do this best in your vimrc. Example: >
if &term == "xterm"
... xterm maps and settings ...
elseif &term =~ "vt10."
... vt100, vt102 maps and settings ...
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.
This ability is only present in genuine Xterm, not in the many terminal
emulators that incorrectly describe themselves as xterm. Nvim's detection of
genuine Xterm will not work over an SSH connection, because the environment
variable, set by genuine Xterm, that it looks for is not automatically
replicated over an SSH login session.
*256-color* *terminfo-colors* *termcap-colors*
Nvim can make use of 256-colour terminals and tries to do so whereever it can.
If the |terminfo| description of the terminal says that it supports fewer
colours, Nvim will override this for many terminal types, including "linux"
(whose virtual terminals have had 256-colour support since version 4.8) and
anything (even if falsely) claiming to be "xterm". It will also set 256
colours when the COLORTERM or TERM environment variables contain the string
"256" somewhere.
Nvim similarly assumes that any terminal emulator that sets the COLORTERM
environment variable at all, to anything, is capable of at least 16-colour
operation; and it will override |terminfo| saying that it has fewer colours
available.
*true-color* *xterm-true-color*
Nvim supports using true (24-bit) colours in the terminal, on terminals that
support it. It uses the same |terminfo| extensions that were proposed by
Rüdiger Sonderfeld in 2013 for this: "setrgbf" and "setrgbb". If your
terminfo definition specifies these, then nothing more is required.
If your terminfo definition is missing them, then Nvim will on a wide range of
terminals resort to using the ISO 8613-6:1994/ITU T.416:1993 control sequences
for setting RGB colours. This includes the "rxvt", "linux", "st", and "iterm"
terminal types, or when Konsole, genuine Xterm, or a terminal emulator that
sets the COLORTERM environment variable to "truecolor" is detected.
*xterm-resize*
Nvim can resize the terminal display on some terminals that implement an
extension pioneered by the dtterm program. |terminfo| does not have a flag
for this extension. So Nvim simply assumes that (all) "dtterm", "xterm",
"teraterm", "rxvt" terminal types, and Konsole, are capable of this.
*cursor-shape* *terminfo-cursor-shape* *termcap-cursor-shape*
Nvim will adjust the shape of the cursor from a block to a line when in insert
mode (or as specified by the 'guicursor' option), on terminals that support
it. It uses the same |terminfo| extensions that were pioneered by tmux for
this: "Ss" and "Se". If your terminfo definition specifies these, as some
(such as those based upon "xterm+tmux") do, then nothing more is required.
If your terminfo definition is missing them, then Nvim will on a wide range of
terminals resort to using the conventional DECSUSR control sequence for
adjusting the cursor shape. If Konsole is detected, Nvim will use the
idiosyncratic Konsole terminal control sequences for this. Similarly if the
Linux kernel's built-in terminal emulator is detected, with its idiosyncratic
control sequence.
Note: tmux itself accepts the conventional DECSUSR control sequence, the same
as many other terminals do. It has to translate this into whatever control
sequence is appropriate for the terminal that it is outputting to. Like Nvim,
it will use the "Ss" and "Se" capabilities from terminfo if they are present.
Unlike Nvim, if they are not present in terminfo you will have to add them by
setting the tmux "terminal-overrides" setting in $HOME/.tmux.conf . It will
appear that Nvim is not changing the cursor, but in fact it is tmux receiving
instructions from Nvim to change the cursor and not knowing what to do. See
the tmux(1) manual page for the details of how and what to do in the tmux
configuration file. It will look something like: >
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
<or (alas!) for Konsole specifically, something more complex like: >
set -ga terminal-overrides \
'xterm*:\E]50;CursorShape=%?%p1%{3}%<%t%{0}%e%{1}%;%d\007'
<but these are only rough examples that do not include all of the other stuff
that occurs in that setting.
*cs7-problem*
Note: If the terminal settings are changed after running Vim, you might have
an illegal combination of settings. This has been reported on Solaris 2.5
with "stty cs8 parenb", which is restored as "stty cs7 parenb". Use
"stty cs8 -parenb -istrip" instead, this is restored correctly.
Many cursor key codes start with an <Esc>. Vim must find out if this is a
single hit of the <Esc> key or the start of a cursor key sequence. It waits
for a next character to arrive. If it does not arrive within one second a
single <Esc> is assumed. On very slow systems this may fail, causing cursor
keys not to work sometimes. If you discover this problem reset the 'timeout'
option. Vim will wait for the next character to arrive after an <Esc>. If
you want to enter a single <Esc> you must type it twice.
Some terminals have confusing codes for the cursor keys. The televideo 925 is
such a terminal. It sends a CTRL-H for cursor-left. This would make it
impossible to distinguish a backspace and cursor-left. To avoid this problem
CTRL-H is never recognized as cursor-left.
*vt100-cursor-keys* *xterm-cursor-keys*
Other terminals (e.g., vt100 and xterm) have cursor keys that send <Esc>OA,
<Esc>OB, etc. Unfortunately these are valid commands in insert mode: Stop
insert, Open a new line above the new one, start inserting 'A', 'B', etc.
Instead of performing these commands Vim will erroneously recognize this typed
key sequence as a cursor key movement. To avoid this and make Vim do what you
want in either case you could use these settings: >
:set notimeout " don't timeout on mappings
:set ttimeout " do timeout on terminal key codes
:set timeoutlen=100 " timeout after 100 msec
This requires the key-codes to be sent within 100 msec in order to recognize
them as a cursor key. When you type you normally are not that fast, so they
are recognized as individual typed commands, even though Vim receives the same
sequence of bytes.
==============================================================================
Window size *window-size*
[This is about the size of the whole window Vim is using, not a window that is
created with the ":split" command.]
On Unix systems, three methods are tried to get the window size:
- an ioctl call (TIOCGSIZE or TIOCGWINSZ, depends on your system)
- the environment variables "LINES" and "COLUMNS"
- from the |terminfo| entries "lines" and "columns"
If everything fails a default size of 24 lines and 80 columns is assumed. If
a window-resize signal is received the size will be set again. If the window
size is wrong you can use the 'lines' and 'columns' options to set the
correct values.
One command can be used to set the screen size:
*:mod* *:mode*
:mod[e]
Detects the screen size and redraws the screen.
==============================================================================
Slow and fast terminals *slow-fast-terminal*
*slow-terminal*
If you have a fast terminal you may like to set the 'ruler' option. The
cursor position is shown in the status line. If you are using horizontal
scrolling ('wrap' option off) consider setting 'sidescroll' to a small
number.
If you have a slow terminal you may want to reset the 'showcmd' and 'ruler'
options. The command characters and cursor positions will not be shown in the
status line (which involves a lot of cursor motions and attribute changes for
every keypress or movement). If the terminal scrolls very slowly, set the
'scrolljump' to 5 or so. If the cursor is moved off the screen (e.g., with
"j") Vim will scroll 5 lines at a time. Another possibility is to reduce the
number of lines that Vim uses with the command "z{height}<CR>".
If the characters from the terminal are arriving with more than 1 second
between them you might want to set the 'timeout' and/or 'ttimeout' option.
See the "Options" chapter |options|.
If you are using a color terminal that is slow when displaying lines beyond
the end of a buffer, this is because Nvim is drawing the whitespace twice, in
two sets of colours and attributes. To prevent this, use this command: >
hi NonText cterm=NONE ctermfg=NONE
This draws the spaces with the default colours and attributes, which allows the
second pass of drawing to be optimized away. Note: Although in theory the
colours of whitespace are immaterial, in practice they change the colours of
cursors and selections that cross them. This may have a visible, but minor,
effect on some UIs.
==============================================================================
Using the mouse *mouse-using*
This section is about using the mouse on a terminal or a terminal window. How
to use the mouse in a GUI window is explained in |gui-mouse|. For scrolling
with a mouse wheel see |scroll-mouse-wheel|.
These characters in the 'mouse' option tell in which situations the mouse will
be used by Vim:
n Normal mode
v Visual mode
i Insert mode
c Command-line mode
h all previous modes when in a help file
a all previous modes
r for |hit-enter| prompt
If you only want to use the mouse in a few modes or also want to use it for
the two questions you will have to concatenate the letters for those modes.
For example: >
:set mouse=nv
Will make the mouse work in Normal mode and Visual mode. >
:set mouse=h
Will make the mouse work in help files only (so you can use "g<LeftMouse>" to
jump to tags).
Whether the selection that is started with the mouse is in Visual mode or
Select mode depends on whether "mouse" is included in the 'selectmode'
option.
In an xterm, with the currently active mode included in the 'mouse' option,
normal mouse clicks are used by Vim, mouse clicks with the shift or ctrl key
pressed go to the xterm. With the currently active mode not included in
'mouse' all mouse clicks go to the xterm.
*xterm-clipboard*
The middle mouse button will insert the unnamed register. In that case, here
is how you copy and paste a piece of text:
Copy/paste with the mouse and Visual mode ('mouse' option must be set, see
above):
1. Press left mouse button on first letter of text, move mouse pointer to last
letter of the text and release the button. This will start Visual mode and
highlight the selected area.
2. Press "y" to yank the Visual text in the unnamed register.
3. Click the left mouse button at the insert position.
4. Click the middle mouse button.
Shortcut: If the insert position is on the screen at the same time as the
Visual text, you can do 2, 3 and 4 all in one: Click the middle mouse button
at the insert position.
*xterm-copy-paste*
NOTE: In some (older) xterms, it's not possible to move the cursor past column
95 or 223. This is an xterm problem, not Vim's. Get a newer xterm
|color-xterm|.
Copy/paste in xterm with (current mode NOT included in 'mouse'):
1. Press left mouse button on first letter of text, move mouse pointer to last
letter of the text and release the button.
2. Use normal Vim commands to put the cursor at the insert position.
3. Press "a" to start Insert mode.
4. Click the middle mouse button.
5. Press ESC to end Insert mode.
(The same can be done with anything in 'mouse' if you keep the shift key
pressed while using the mouse.)
Note: if you lose the 8th bit when pasting (special characters are translated
into other characters), you may have to do "stty cs8 -istrip -parenb" in your
shell before starting Vim.
Thus in an xterm the shift and ctrl keys cannot be used with the mouse. Mouse
commands requiring the CTRL modifier can be simulated by typing the "g" key
before using the mouse:
"g<LeftMouse>" is "<C-LeftMouse> (jump to tag under mouse click)
"g<RightMouse>" is "<C-RightMouse> ("CTRL-T")
*bracketed-paste-mode*
Bracketed paste mode allows terminal emulators to distinguish between typed
text and pasted text.
For terminal emulators that support it, this mode is enabled by default. Thus
2017-05-01 05:35:58 -07:00
you can paste text without Nvim giving any special meaning to it, e.g. it will
not auto-indent the pasted text. See https://cirw.in/blog/bracketed-paste for
technical details.
*mouse-mode-table* *mouse-overview*
A short overview of what the mouse buttons do, when 'mousemodel' is "extend":
Normal Mode:
event position selection change action ~
cursor window ~
<LeftMouse> yes end yes
<C-LeftMouse> yes end yes "CTRL-]" (2)
<S-LeftMouse> yes no change yes "*" (2) *<S-LeftMouse>*
<LeftDrag> yes start or extend (1) no *<LeftDrag>*
<LeftRelease> yes start or extend (1) no
<MiddleMouse> yes if not active no put
<MiddleMouse> yes if active no yank and put
<RightMouse> yes start or extend yes
<A-RightMouse> yes start or extend blockw. yes *<A-RightMouse>*
<S-RightMouse> yes no change yes "#" (2) *<S-RightMouse>*
<C-RightMouse> no no change no "CTRL-T"
<RightDrag> yes extend no *<RightDrag>*
<RightRelease> yes extend no *<RightRelease>*
Insert or Replace Mode:
event position selection change action ~
cursor window ~
<LeftMouse> yes (cannot be active) yes
<C-LeftMouse> yes (cannot be active) yes "CTRL-O^]" (2)
<S-LeftMouse> yes (cannot be active) yes "CTRL-O*" (2)
<LeftDrag> yes start or extend (1) no like CTRL-O (1)
<LeftRelease> yes start or extend (1) no like CTRL-O (1)
<MiddleMouse> no (cannot be active) no put register
<RightMouse> yes start or extend yes like CTRL-O
<A-RightMouse> yes start or extend blockw. yes
<S-RightMouse> yes (cannot be active) yes "CTRL-O#" (2)
<C-RightMouse> no (cannot be active) no "CTRL-O CTRL-T"
In a help window:
event position selection change action ~
cursor window ~
<2-LeftMouse> yes (cannot be active) no "^]" (jump to help tag)
When 'mousemodel' is "popup", these are different:
Normal Mode:
event position selection change action ~
cursor window ~
<S-LeftMouse> yes start or extend (1) no
<A-LeftMouse> yes start or extend blockw. no *<A-LeftMouse>*
<RightMouse> no popup menu no
Insert or Replace Mode:
event position selection change action ~
cursor window ~
<S-LeftMouse> yes start or extend (1) no like CTRL-O (1)
<A-LeftMouse> yes start or extend blockw. no
<RightMouse> no popup menu no
(1) only if mouse pointer moved since press
(2) only if click is in same buffer
Clicking the left mouse button causes the cursor to be positioned. If the
click is in another window that window is made the active window. When
editing the command-line the cursor can only be positioned on the
command-line. When in Insert mode Vim remains in Insert mode. If 'scrolloff'
is set, and the cursor is positioned within 'scrolloff' lines from the window
border, the text is scrolled.
A selection can be started by pressing the left mouse button on the first
character, moving the mouse to the last character, then releasing the mouse
button. You will not always see the selection until you release the button,
only in some versions (GUI, Windows) will the dragging be shown immediately.
Note that you can make the text scroll by moving the mouse at least one
character in the first/last line in the window when 'scrolloff' is non-zero.
In Normal, Visual and Select mode clicking the right mouse button causes the
Visual area to be extended. When 'mousemodel' is "popup", the left button has
to be used while keeping the shift key pressed. When clicking in a window
which is editing another buffer, the Visual or Select mode is stopped.
In Normal, Visual and Select mode clicking the right mouse button with the alt
key pressed causes the Visual area to become blockwise. When 'mousemodel' is
"popup" the left button has to be used with the alt key. Note that this won't
work on systems where the window manager consumes the mouse events when the
alt key is pressed (it may move the window).
*double-click*
Double, triple and quadruple clicks are supported when the GUI is active, for
Windows and for an xterm. For selecting text, extra clicks extend the
selection:
click select ~
double word or % match *<2-LeftMouse>*
triple line *<3-LeftMouse>*
quadruple rectangular block *<4-LeftMouse>*
Exception: In a Help window a double click jumps to help for the word that is
clicked on.
A double click on a word selects that word. 'iskeyword' is used to specify
which characters are included in a word. A double click on a character
that has a match selects until that match (like using "v%"). If the match is
an #if/#else/#endif block, the selection becomes linewise.
For MS-DOS and xterm the time for double clicking can be set with the
'mousetime' option. For the other systems this time is defined outside of
Vim.
An example, for using a double click to jump to the tag under the cursor: >
:map <2-LeftMouse> :exe "tag ". expand("<cword>")<CR>
Dragging the mouse with a double click (button-down, button-up, button-down
and then drag) will result in whole words to be selected. This continues
until the button is released, at which point the selection is per character
again.
In Insert mode, when a selection is started, Vim goes into Normal mode
temporarily. When Visual or Select mode ends, it returns to Insert mode.
This is like using CTRL-O in Insert mode. Select mode is used when the
'selectmode' option contains "mouse".
*drag-status-line*
When working with several windows, the size of the windows can be changed by
dragging the status line with the mouse. Point the mouse at a status line,
press the left button, move the mouse to the new position of the status line,
release the button. Just clicking the mouse in a status line makes that window
the current window, without moving the cursor. If by selecting a window it
will change position or size, the dragging of the status line will look
confusing, but it will work (just try it).
*<MiddleRelease>* *<MiddleDrag>*
Mouse clicks can be mapped. The codes for mouse clicks are:
code mouse button normal action ~
<LeftMouse> left pressed set cursor position
<LeftDrag> left moved while pressed extend selection
<LeftRelease> left released set selection end
<MiddleMouse> middle pressed paste text at cursor position
<MiddleDrag> middle moved while pressed -
<MiddleRelease> middle released -
<RightMouse> right pressed extend selection
<RightDrag> right moved while pressed extend selection
<RightRelease> right released set selection end
<X1Mouse> X1 button pressed - *X1Mouse*
<X1Drag> X1 moved while pressed - *X1Drag*
<X1Release> X1 button release - *X1Release*
<X2Mouse> X2 button pressed - *X2Mouse*
<X2Drag> X2 moved while pressed - *X2Drag*
<X2Release> X2 button release - *X2Release*
The X1 and X2 buttons refer to the extra buttons found on some mice. The
'Microsoft Explorer' mouse has these buttons available to the right thumb.
Currently X1 and X2 only work on Win32 and X11 environments.
Examples: >
:noremap <MiddleMouse> <LeftMouse><MiddleMouse>
Paste at the position of the middle mouse button click (otherwise the paste
would be done at the cursor position). >
:noremap <LeftRelease> <LeftRelease>y
Immediately yank the selection, when using Visual mode.
Note the use of ":noremap" instead of "map" to avoid a recursive mapping.
>
:map <X1Mouse> <C-O>
:map <X2Mouse> <C-I>
Map the X1 and X2 buttons to go forwards and backwards in the jump list, see
|CTRL-O| and |CTRL-I|.
*mouse-swap-buttons*
To swap the meaning of the left and right mouse buttons: >
:noremap <LeftMouse> <RightMouse>
:noremap <LeftDrag> <RightDrag>
:noremap <LeftRelease> <RightRelease>
:noremap <RightMouse> <LeftMouse>
:noremap <RightDrag> <LeftDrag>
:noremap <RightRelease> <LeftRelease>
:noremap g<LeftMouse> <C-RightMouse>
:noremap g<RightMouse> <C-LeftMouse>
:noremap! <LeftMouse> <RightMouse>
:noremap! <LeftDrag> <RightDrag>
:noremap! <LeftRelease> <RightRelease>
:noremap! <RightMouse> <LeftMouse>
:noremap! <RightDrag> <LeftDrag>
:noremap! <RightRelease> <LeftRelease>
<
vim:tw=78:ts=8:ft=help:norl: