VIM REFERENCE MANUAL - Part 9

By Bram Moolenaar

CONTENTS

[Note: The commands for multiple windows and buffers are explained in a different file, see vim_win.html]

  1. Introduction
  2. Notation
  3. Starting Vim
    1. Command line
    2. Workbench (Amiga only)
    3. Vim window (Amiga only)
    4. Initialization
    5. Suspending
    6. The viminfo file
  4. Modes
    1. Introduction
    2. Switching from mode to mode
    3. Insert and Replace mode
      1. special keys
      2. special special keys
      3. 'textwidth' option
      4. 'expandtab' option
      5. Replace mode
      6. Insert mode completion
    4. Command_line mode
      1. Command line editing
      2. Command line completion
      3. Ex command lines
      4. Ex command line ranges
      5. Ex special characters
    5. The window contents
    6. Abbreviations
    7. Digraphs
    8. Using the mouse
    9. On-line help
  5. Editing files
    1. Introduction
    2. Editing a file
    3. The argument list
    4. Writing and quitting
    5. Using the QuickFix mode
    6. Editing binary files
    7. Automatic commands
  6. Cursor motions
    1. Left-right motions
    2. Up-down motions
    3. Word motions
    4. Text object motions
    5. Text object selection
    6. Pattern searches
    7. Various motions
  7. Scrolling
  8. Tags and special searches
    1. Tags
    2. Identifier searches
  9. Inserting text
  10. Deleting text
  11. Changing text
    1. Delete and insert
    2. Simple changes
    3. Complex changes
    4. Formatting text
    5. Formatting C programs
  12. Copying and moving text
  13. Visual mode
  14. Various commands
  15. Repeating commands
    1. Single repeats
    2. Multiple repeats
    3. Complex repeats
  16. Undo and redo
  17. Key mapping
  18. Recovery after a crash
    1. The swap file
    2. Recovery
  19. Options
    1. Setting options
    2. Automatically setting options
    3. Saving settings
    4. Options summary
  20. Terminal information
    1. Startup
    2. Terminal options
    3. Window size
    4. Slow and fast terminals
  21. Differences from Vi and Ex
    1. Missing commands
    2. Missing options
    3. Limits

20. 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. Special keys produce a string of characters. These strings are stored in the terminal options, see section 20.2 Terminal_Options.
20.1 Startup
When Vim is started a default terminal type is assumed. For the Amiga this is a standard CLI window, for MS-DOS the pc terminal, for Unix an ansi terminal. A few other terminal types are always available, see below builtin_terms.

You can give the terminal name with the '-T' command line option. If it is not given Vim will try to get the name from the TERM environment variable.

On Unix the terminfo database or termcap file is used. This is referred to as "termcap" in all the documentation. At compile time, when running configure, the choice whether to use terminfo or termcap is done automatically. When running Vim the output of ":version" will show "+terminfo" if terminfo is used. If terminfo is not used "-terminfo" is shown.

On non-Unix systems a termcap is only available if Vim was compiled with TERMCAP defined.

Which builtin terminals are available depends on a few defines in feature.h, which needs to be set at compile time:
define output of ":version" terminals builtin
NO_BUILTIN_TCAPS -builtin_terms none
SOME_BUILTIN_TCAPS +builtin_terms most common ones (default)
ALL_BUILTIN_TCAPS ++builtin_terms all available

You can see a list of available builtin terminals with ":set term=xxx".

If the termcap code is included Vim will try to get the strings for the terminal you are using from the termcap file and the builtin termcaps. Both are always used, if an entry for the terminal you are using is present. Which one is used first depends on the 'ttybuiltin' option:

'ttybuiltin' on 1: builtin termcap 2: external termcap
'ttybuiltin' off 1: external termcap 2: builtin termcap
If an option is missing in one of them, it will be obtained from the other one. If an option is present in both, the one first encountered is used.

Which external termcap file is used varies from system to system and may depend on the environment variables "TERMCAP" and "TERMPATH". See "man tgetent".

For normal editing the terminal will be put into "raw" mode. The strings defined with 't_ti' and 't_ks' will be sent to the terminal. Normally this puts the terminal in a state where the termcap codes are valid and activates the cursor and function keys. When Vim exits the terminal will be put back into the mode it was before Vim started. The strings defined with 't_te' and 't_ke' will be sent to the terminal. On the Amiga with commands that execute an external command (e.g. "!!") the terminal will be put into Normal mode for a moment. This means that you can stop the output to the screen by hitting a printing key. Output resumes when you hit <BS>.

Some termcap entries are wrong in the sense that after sending 't_ks' the cursor keys send codes different from the codes defined in the termcap. To avoid this you can set 't_ks' (and 't_ke') to empty strings. This must be done during initialization (see 3.4 Initialization), otherwise its too late.

Some termcap entries assume that the highest bit is always reset. For example: The cursor-up entry for the amiga could be ":ku=\EA:". But the Amiga really sends "\233A". This works fine if the highest bit is reset, e.g. when using an Amiga over a serial line. If the cursor keys don't work, try the entry ":ku=\233A:".

Some termcap entries have the entry ":ku=\E[A:". But the Amiga really sends "\233A". On output "\E[" and "\233" are often equivalent, on input they aren't. You will have to change the termcap entry, or change the key code with the :set command to fix this.

Many cursor key codes start with an <Esc>. Vim must find out if this 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. Resetting the 'esckeys' option avoids this problems in Insert mode, but you lose the possibility to use cursor and function keys in Insert mode.

On the Amiga the recognition of window resizing is activated only when the terminal name is "amiga" or "builtin_amiga".

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.

Other terminals (e.g. vt100 and xterm) have cursor keys that send OA, 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 recognize this key sequence as a cursor key movement. To avoid this you could use these settings:

:set notimeout " don't timeout on mappings
:set ttimeout " do timeout on terminal key codes
:set timeoutlen=100 " timemout in 100 msec
This requires the keys to be hit withing 100msec. When you type you normally are not that fast. The cursor key codes arrive within 100 msec, so they are still recognized.

The default termcap entry for xterm on sun and other platforms does not contain the entry for scroll regions. Add ":cs=\E[%i%d;%dr:" to the xterm entry in /etc/termcap and everything should work.

20.2 Terminal options
The terminal options can be set just like normal options. But they are not shown with the ":set all" command. Instead use ":set termcap".

It is always possible to change individual strings by setting the appropriate option. For example:

:set t_ce=^V^[[K (CTRL-V, <Esc>, [, K)
{Vi: no terminal options. You have to exit Vi, edit the termcap entry and try again}

The options are listed below. The associated termcap code is always equal to the last two characters of the option name. Two termcap codes are required: Cursor positioning and clear screen.

OUTPUT CODES
option meaning
t_AL add number of blank lines
t_al add new blank line
t_cd clear to end of screen
t_ce clear to end of line
t_cl clear screen (required!)
t_cm cursor motion (required!)
t_CS if non-empty, cursor relative to scroll region
t_cs define scrolling region
t_da if non-empty, lines from above scroll down
t_db if non-empty, lines from below scroll up
t_DL delete number of lines
t_dl delete line
t_ke out of "keypad transmit" mode
t_ks put terminal in "keypad transmit" mode
t_md bold mode
t_me Normal mode (undoes t_mr and t_md)
t_mr reverse (invert) mode
t_ms if non-empty, cursor can be moved in standout/inverse mode
t_RI cursor number of chars right
t_se standout end
t_so standout mode
t_sr scroll reverse (backward)
t_te out of "termcap" mode
t_ti put terminal in "termcap" mode
t_ue underline end
t_us underline mode
t_vb visual bell
t_ve cursor visible
t_vi cursor invisible
t_vs cursor very visible
t_ZH italics mode
t_ZR italics end

KEY CODES
Note: Use the <> form if possible
option name meaning
t_ku <Up> arrow up
t_kd <Down> arrow down
t_kr <Right> arrow right
t_kl <Left> arrow left
<S-Up> shift arrow up
<S-Down> shift arrow down
t_%i <S-Right> shift arrow right
t_#4 <S-Left> shift arrow left
t_k1 <F1> function key 1
t_k2 <F2> function key 2
t_k3 <F3> function key 3
t_k4 <F4> function key 4
t_k5 <F5> function key 5
t_k6 <F6> function key 6
t_k7 <F7> function key 7
t_k8 <F8> function key 8
t_k9 <F9> function key 9
t_k; <F10> function key 10
t_F1 <F11> function key 11
t_F2 <F12> function key 12
<S-F1) shifted function key 1
<S-F2> shifted function key 2
<S-F3> shifted function key 3
<S-F4> shifted function key 4
<S-F5> shifted function key 5
<S-F6> shifted function key 6
<S-F7> shifted function key 7
<S-F8> shifted function key 8
<S-F9> shifted function key 9
<S-F10> shifted function key 10
<S-F11> shifted function key 11
<S-F12> shifted function key 12
t_%1 <Help> help key
t_&8 <Undo> undo key
t_kI <Insert> insert key
t_kD <Delete> delete key
t_kb <BS> backspace key
t_kh <Home> home key
t_@7 <End> end key
t_kP <PageUp> page-up key
t_kN <PageDown> page-down key

Note about t_so and t_mr: When the termcap entry "so" is not present the entry for "mr" is used. And visa versa. The same is done for "se" and "me". If your terminal supports both inversion and standout mode, you can see two different modes. If you terminal supports only one of the modes, both will look the same.

If inversion or other highlighting does not work correctly, try setting the 'weirdinvert' option. This makes the start-highlight or end-highlight termcap code to be outputted before every character. This slows down terminal I/O a lot, but it makes inversion work on some terminals.

Some termcaps do not include an entry for 'cs' (scroll region), although the terminal does support it. For example: xterm on a sun. You can use the builtin_xterm or define t_cs yourself. For example:

:set t_cs=^V^[[%i%d;%dr

Where ^V is CTRL-V and ^[ is <Esc>.

Unfortunately it is not possible to deduct from the termcap how cursor positioning should be done when using a scrolling region: Relative to the beginning of the screen or relative to the beginning of the scrolling region. Most terminals use the first method. A know exception is the MS-DOS console (pcterm). The 't_CS' option should be set to any string when cursor positioning is relative to the start of the scrolling region. It should be set to an empty string otherwise. It is default "yes" when 'term' is "pcterm".

Note for xterm users:
The shifted cursor keys normally don't work. You can make them work with the xmodmap command and some mappings in Vim.

Give these commands in the xterm:

xmodmap -e "keysym Up = Up F13"
xmodmap -e "keysym Down = Down F16"
xmodmap -e "keysym Left = Left F18"
xmodmap -e "keysym Right = Right F19"

And use these mappings in Vim:

:map <t_F3> <S-Up>
:map! <t_F3> <S-Up>
:map <t_F6> <S-Down>
:map! <t_F6> <S-Down>
:map <t_F8> <S-Left>
:map! <t_F8> <S-Left>
:map <t_F9> <S-Right>
:map! <t_F9> <S-Right>
Instead of, say, you can use any other command that you want to use the shift-cursor-up key for. (Note: To help people that have a Sun keyboard with left side keys F14 is not used because it is confused with the undo key; F15 is not used, because it does a window-to-front; F17 is not used, because it closes the window. On other systems you can probably use them)
20.3 Window size
[This is about the size of the whole window Vim is using, not a window that is created with the :split command]

If you are running Vim on an Amiga and the terminal name is "amiga" or "builtin_amiga", the amiga-specific window resizing will be enabled. 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 termcap entries "li" and "co"
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[e] [mode]

Without argument this only detects the screen size. With MS-DOS it is possible to switch screen mode. [mode] can be one of these values:

"bw40" 40 columns black&white
"c40" 40 columns color
"bw80" 80 columns black&white
"c80" 80 columns black&white (most people use this)
"mono" 80 columns monochrome
"c4350" 43 or 50 lines EGA/VGA mode
number mode number to use, depends on your video card
20.4
Slow and fast terminals
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' option. The command characters will not be shown in the status line. 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.

If your terminal does not support a scrolling region, but it does support insert/delete line commands, scrolling with multiple windows may make the lines jump up and down. If you don't want this set the 'ttyfast' option. This will redraw the window instead of scroll it.

If your terminal scrolls very slowly, but redrawing is not slow, set the 'ttyscroll' option to a small number, e.g. 3. This will make Vim redraw the screen instead of scrolling, when there are more than 3 lines to be scrolled.

If you are testing termcap options, but you cannot see what is happening, you might want to set the 'writedelay' option. When non-zero, one character is sent to the terminal at a time (does not work for MS-DOS). This makes the screen updating a lot slower, making it possible to see what is happening.

When you are using an hpterm you probably run into a few problems. The best thing to do is to use an xterm instead. If you want to use an hpterm for some reason, try (re)setting some options:

:set t_sr=
:set t_al=
:set t_dl=
:set ttyfast redraw screen instead of scrolling
:set weirdinvert makes highlighting work better, but slows down screen updating a lot

21. Differences from Vi and Ex

Throughout this document differences between Vim and Vi/Ex are given in curly braces. This chapter only lists what has not been mentioned in previous chapters. Also see vim_diff.html for an overview.
21.1 Missing commands
A large number of the "Ex" commands (the commands that start with a colon) are included. However, there is no Ex mode.

These commands are in Vi, but not in Vim.
Q {Vi: go to Ex mode}
:a[ppend] {Vi: append text}
:c[hange] {Vi: replace lines}
:i[nsert] {Vi: insert text}
:o[pen] {Vi: start editing in open mode}
:z {Vi: print some lines}

21.2 Missing options
These options are in the Unix Vi, but not in Vim. If you try to set one of them you won't get an error message, but the value is not used and cannot be printed.
autoprint (ap) toggle (default on)
beautify (bf) toggle (default off)
flash (fl) toggle (default ??)
hardtabs (ht) number (default 8) number of spaces that a <Tab> moves on the display
mesg toggle (default on)
novice toggle (default ??)
open toggle (default on)
optimize (op) toggle (default on)
prompt toggle (default on)
redraw toggle (default off)
slowopen (slow) toggle (default off)
sourceany toggle (default not documented)
ttytype string
window number (default 24)
w300 number (default 24)
w1200 number (default 24)
w9600 number (default 24)
21.3 Limits
Vim has only a few limits for the files that can be edited {Vi: can not handle <Nul> characters and characters above 128, has limited line length}.
Maximum line length On machines with 16-bit ints (Amiga and MS-DOS): 32767, otherwise 2147483647 characters. When reading a file longer lines are split.
Maximum number of lines 2147483647 lines.
Maximum file size Only limited by available disk space for the swap file.
Length of a file name Unix and Win32: 1024 characters, otherwise 128 characters.
Maximum display width Unix and Win32: 1024 characters, otherwise 255 characters
Information for undo and registers are kept in memory, thus when making (big) changes the amount of (virtual) memory available limits the number of undo levels and the text that can be kept in registers. Other things are also kept in memory: Command line history, error messages for Quickfix mode, etc.
Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 Part 8 Part 9
Send feedback on this page to Rajesh Kallingal
For Vim version 3.24. Last modification: 1996 Apr 25