home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume44
/
vim
/
part03
< prev
next >
Wrap
Internet Message Format
|
1994-08-16
|
71KB
From: mool@oce.nl (Bram Moolenaar)
Newsgroups: comp.sources.misc
Subject: v44i022: vim - Vi IMproved editor, v3.0, Part03/26
Date: 16 Aug 1994 21:17:21 -0500
Organization: Sterling Software
Sender: kent@sparky.sterling.com
Approved: kent@sparky.sterling.com
Message-ID: <32rrvh$kam@sparky.sterling.com>
X-Md4-Signature: 51bfa32793529618e4898ff205afa628
Submitted-by: mool@oce.nl (Bram Moolenaar)
Posting-number: Volume 44, Issue 22
Archive-name: vim/part03
Environment: UNIX, AMIGA, MS-DOS, Windows NT
Supersedes: vim: Volume 41, Issue 50-75
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# Contents: vim/doc/reference.doc.A vim/src/archie.c vim/src/archie.h
# Wrapped by kent@sparky on Mon Aug 15 21:43:58 1994
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:
echo ' "shar: End of archive 3 (of 26)."'
if test -f 'vim/doc/reference.doc.A' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vim/doc/reference.doc.A'\"
else
echo shar: Extracting \"'vim/doc/reference.doc.A'\" \(52085 characters\)
sed "s/^X//" >'vim/doc/reference.doc.A' <<'END_OF_FILE'
X
X
X
X Vim reference manual
X
X By Bram Moolenaar
X
X version 3.0
X
X
XThere is a contents listing at the end of this document.
X
XThe commands and options for multiple windows and buffers are explained in a
Xseparate document: windows.doc
X
X
X
X 1. Introduction
X
XVim stands for Vi IMproved. It used to be Vi IMitation, but that does not
Xreally cover it anymore. Vim is a text editor which includes almost all the
Xcommands from the Unix program "Vi" (and a lot new ones). It is very useful
Xfor editing programs and other ASCII text. All commands are given with the
Xkeyboard. There is no mouse support and there are no menus. This gives the
Xadvantage that you can keep your fingers on the keyboard and your eyes on
Xthe screen.
X
XThroughout this manual the differences between Vi and Vim are mentioned in
Xcurly braces. Read the file "difference.doc" for a summary of the
Xdifferences.
X
XThis manual refers to Vim on the Commodore Amiga computer. On other
Xcomputers and on terminals there may be small differences. For MSDOS this
Xis documented in msdos.doc. For UNIX this is in unix.doc.
X
XThis manual is a reference for all the Vim commands and options. A basic
Xknowledge of "Vi" is assumed. A summary of this manual can be found in the
Xfile vim.hlp. It can be accessed from within Vim with the <HELP> key (in
XMSDOS <F1>) and with the command ":help". The 'helpfile' option can be
Xset to the name of the help file, so you can put it in any place you like.
X
X
X 2. Notation
X
X[] Characters in square brackets are optional.
X
X[count] An optional number that may precede the command to multiply
X or iterate the command. If no number is given a count of one
X is used, unless otherwise noted. Note that in this manual
X the [count] is not mentioned in the description of the
X command, but only in the explanation. This was done to make
X the commands easier to lookup. If the "sc" option is on, the
X (partially) entered count is shown at the bottom of the
X window. You can use <DEL> to erase the last digit.
X
X["x] An optional register designation where text can be stored.
X The x is a single character between <a> and <z> or <A> and
X <Z> or <">, and in some cases (with the put command) between
X <0> and <9>, <%>, <:> or <.>. The uppercase and lower case
X letter designate the same register, but the lower case letter
X is used to overwrite the previous register contents, while the
X uppercase letter is used to append to the previous register
X contents. Without the ""x" or with """" the stored text is
X put into the unnamed register. See also "Copying and moving
X text".
X
X{} Curly braces denote parts of the command which must appear,
X but can take a number of different values. The differences
X between Vim and Vi are also given in curly braces (this will
X be clear from the context).
X
X{motion} A command that moves the cursor. They are listed in chapter
X 6. This is used after an "operator" command to move over the
X text that is to be operated upon. If the motion includes a
X count and the operator also had a count, the two counts are
X multiplied. For example: "2d3w" deletes six words.
X
X{visual} A piece of text that is started with the "v", "V" or CTRL-V
X command and ended by the cursor position. This is used
X before an "operator" to highlight the text that is to be
X operated upon. See the chapter on Visual mode.
X
X<character> A special character from the table below or a single ASCII
X character.
X
X<char1-char2> A single character from the range <char1> to <char2>. For
X example: <a-z> is a lower case letter. Multiple ranges may be
X concatenated. For example: <a-zA-Z0-9> is any alphanumeric
X character.
X
XCTRL-<char> <char> typed as a control character, that is, typing <char>
X while holding the CTRL key down. The case of <char> does not
X matter, thus CTRL-A and CTRL-a are equivalent.
X
X'option' An option, or parameter, that can be set to a value is
X enclosed in single quotes. See chapter 19.
X
X"command" In examples the commands you can type are enclosed in double
X quotes.
X
X
Xnotation meaning equivalent decimal value
X-----------------------------------------------------------------------
X<NUL> zero CTRL_@ 000 (internally 010)
X<BELL> bell CTRL-G 007
X<BS> backspace CTRL-H 008
X<TAB> tab CTRL-I 009
X<LF> linefeed CTRL-J 010
X<FF> formfeed CTRL-L 012
X<CR> carriage return CTRL-M 013
X<ESC> escape CTRL-[ 027
X<SPACE> space 032
X<DEL> delete 127
X<C_UP> cursor-up 128 (msdos: 176)
X<C_DOWN> cursor-down 129 (msdos: 177)
X<C_LEFT> cursor-left 130 (msdos: 178)
X<C_RIGHT> cursor-right 131 (msdos: 179)
X<SC_UP> shift-cursor-up 132 (msdos: 180)
X<SC_DOWN> shift-cursor-down 133 (msdos: 181)
X<SC_LEFT> shift-cursor-left 134 (msdos: 182)
X<SC_RIGHT> shift-cursor-right 135 (msdos: 183)
X<F1> - <F10> function keys 1 to 10 136 - 145 (msdos: 184 - 193)
X<SF1> - <SF10> shift-function keys 1 to 10 146 - 155 (msdos: 194 - 203)
XHELP> help key 156 (msdos: 204)
X<UNDO> undo key 157 (msdos: 205)
X-----------------------------------------------------------------------
XNote: The shifted cursor keys, the help key and the undo key are only
Xavailable on a few terminals. On some terminals the function keys 11 to 20
Xare used instead of the shifted function keys. On the Amiga shifted function
Xkey 10 produces a code (CSI) that is also used by key sequences. It will be
Xrecognized only after typing another key.
X
X
X 3. Starting Vim
X
X3.1 Command line
X
XMost often Vim is started to edit a single file with the command
X
X vim file
X
XMore generally Vim is started with:
X
X vim [options] [filelist]
X
XIf the filelist is missing, the editor will start with an empty buffer.
XOtherwise exactly one out of the following three may be used to choose one
Xor more files to be edited.
X
Xfile .. A list of file names. The first one will be the current file
X and read into the buffer. The cursor will be positioned on
X the first line of the buffer.
X
X-t {tag} A tag. "tag" is looked up in the tags file, the associated
X file becomes the current file and the associated command is
X executed. Mostly this is used for C programs. In that case
X "tag" should be a function name. The effect is that the file
X containing that function becomes the current file and the
X cursor is positioned on the start of the function (see the
X section "tag searches").
X
X-e [errorfile] QuickFix mode. The file with the name [errorfile] is read
X and the first error is displayed. If [errorfile] is not
X given, the 'errorfile' option is used for the file name
X (default "AztecC.Err" for the Amiga, "errors" for other
X systems). See section 5.5: "using the QuickFix mode".
X
XThe options, if present, must precede the filelist. The options may be given
Xin any order.
X
X+[num] The cursor will be positioned on line "num" for the first
X file being edited. If "num" is missing, the cursor will be
X positioned on the last line.
X
X+/{pat} The cursor will be positioned on the first line containing
X "pat" in the first file being edited (see the section
X "pattern searches" for the available search patterns).
X
X+{command}
X-c {command} "command" will be executed after the first file has been
X read. "command" is interpreted as an Ex command. If the
X "command" contains spaces it must be enclosed in double
X quotes (this depends on the shell that is used). Example:
X vim "+set si" main.c
X
X-r Recovery mode. The swap file is read to recover a
X crashed editing session. See the chapter "Recovery after a
X crash".
X
X-v View mode. The 'readonly' option will be set and no
X swap file will be written (see -n below). You can
X still edit the buffer, but will be prevented from
X accidentally overwriting a file. If you forgot that you are
X in View mode and did make some changes, you can overwrite
X a file by adding an exclamation mark to the Ex command, as in
X ":w!". The 'readonly' option can be reset with ":set noro"
X (see the options chapter). Calling the executable "view"
X has the same effect as the -v option. If your system does
X not support links and you do not want to have the executable
X twice you could make an alias: "alias view vim -v".
X
X-b Binary mode. The 'textauto', 'textmode' and 'expandtab'
X options will be reset. The 'textwidth' option is set to 0.
X 'modelines' is set to 0. The 'binary' option is set. This is
X done after reading the .vimrc/.exrc files but before reading
X a file. See also 5.6: "Editing binary files".
X
X-n No swap file will be used. Recovery after a crash will be
X impossible. Handy if you want to view or edit a file on a
X very slow medium (e.g. floppy). Can also be done with ":set
X uc=0". You can switch it on again by setting the 'uc' option
X to some value, e.g. ":set uc=100". Any files already being
X edited will not be affected by this.
X
X-o[N] Open N windows. If [N] is not given, one window is opened
X for every file given as argument. If there is not enough
X room, only the first few files get a window. If there are
X more windows than arguments, the last few windows will be
X editing an empty file.
X
X-T {terminal} Set the terminal type to "terminal". This influences the
X codes that Vim will send to your terminal. This is normally
X not needed, because Vim will be able to find out what type
X of terminal you are using (See chapter 20).
X
X-d {device} Amiga only: The "device" is opened to be used for editing.
X Normally you would use this to set the window position and
X size: "-d con:x/y/width/height", e.g.
X "-d con:30/10/600/150". But you can also use it to start
X editing on another device, e.g. AUX:.
X
X-x Amiga only: Do not restart Vim to open a new window. This
X option should be used when Vim is started by a program that
X will wait for the edit session to finish (e.g. mail or
X readnews). See section 3.3.
X
X-s {scriptin} The script file "scriptin" is read. The characters in the
X file are interpreted as if you had typed them. The same can
X be done with the command ":source! {scriptin}". If the end
X of the file is reached before the editor exits, further
X characters are read from the keyboard. See also the section
X "complex repeats".
X
X-w {scriptout} All the characters that you type are recorded in the file
X "scriptout", until you exit Vim. This is useful if you want
X to create a script file to be used with "vim -s" or
X ":source!". See also the section "complex repeats".
X
XExample for using a script file to change a name in several files:
X Create a file "subs.vi" containing substitute commands and a :wq
X command:
X
X :%s/Jones/Smith/g
X :%s/Allen/Peter/g
X :wq
X
X Execute Vim on all files you want to change:
X
X foreach i ( *.let ) vim -s subs.vi $i
X
XIf the executable is called "view" Vim will start in Readonly mode. This is
Xuseful if you can make a hard or symbolic link from "view" to "vim".
XStarting in Readonly mode can also be done with "vim -v".
X
X
X3.2 Workbench (Amiga only)
X
XVim can be started from the workbench by clicking on its icon twice. It will
Xthen start with an empty buffer.
X
XVim can be started to edit one or more files by using a "Project" icon. The
X"Default Tool" of the icon must be the full pathname of the Vim executable.
XThe name of the ".info" file must be the same as the name of the text file.
XBy clicking on this icon twice, Vim will be started with the filename as
Xcurrent filename, which will be read into the buffer (if it exists). You can
Xedit multiple files by pressing the shift key while clicking on icons, and
Xclicking twice on the last one. The "Default Tool" for all these icons must
Xbe the same.
X
XIt is not possible to give arguments to Vim, other than filenames, from the
Xworkbench.
X
X
X3.3 Vim window (Amiga only)
X
XVim will run in the CLI window where it was started. If Vim was started with
Xthe "run" or "runback" command, or if Vim was started from the workbench, it
Xwill open a window of its own.
X
XTechnical detail:
X To open the new window a little trick is used. As soon as Vim
X recognizes that it does not run in a normal CLI window, it will
X create a script file in t:. This script file contains the same
X command as how Vim was started, and an "endcli" command. This script
X file is then executed with a "newcli" command (the "c:run" and
X "c:newcli" commands are required for this to work). The script file
X will hang around until reboot, or until you delete it. This method
X is required to get the ":sh" and ":!" commands to work correctly.
X But when Vim was started with the -e option (Quickfix mode) or with
X the -x option, this method is not used. The reason for this is that
X when a compiler starts Vim with the -e option it will wait for a
X return code. With the script trick the compiler cannot get the
X return code. The -x option can be used when Vim is started by a mail
X program which also waits for the edit session to finish. As a
X consequence the ":sh" and ":!" commands are not available when the
X -e or -x option is used.
X
XVim will automatically recognize the window size and react to window
Xresizing. Under Amiga DOS 1.3 it is advised to use the fastfonts program
X"FF" to speed up display redrawing.
X
X
X3.4 Initialization
X
XWhen Vim starts running it does initializations in the following order. If
Xan environment variable is used, it is executed as a single Ex command line.
XMultiple commands must be separated with <|> or <LF>. If a file is used,
Xeach line is executed as an Ex command line.
X
X1. Four places are searched for initializations. The first that exists is
X used, the others are ignored.
X 1. The environment variable VIMINIT
X 2. The file "s:.vimrc" (for Unix: "$HOME/.vimrc")
X 3. The environment variable EXINIT
X 4. The file "s:.exrc" (for Unix: "$HOME/.exrc")
X
X2. If the 'exrc' option is set (default is 'noexrc'), the current directory
X is searched for two files. The first that exists is used, the other is
X ignored.
X 1. The file ".vimrc"
X 2. The file ".exrc"
X
X3. The environment variable SHELL, if it exists, is used to set the
X 'shell' option. With MSDOS the COMPSPEC variable is used if SHELL does
X not exist. The 'shellpipe' option is set according to the name of the
X shell.
X
X4. The environment variable TERM, if it exists, is used to set the 'term'
X option.
X
XThe first can be used to set your default settings and mappings for all edit
Xsessions. The second one for sessions in a certain directory (note that the
X'exrc' option is default off). See the section "Saving settings" for how to
Xcreate a file with commands to recreate the current settings.
X
XIf the VIMINIT environment variable or ".vimrc" exist the EXINIT and ".exrc"
Xare skipped. This can be used to initialize Vim without interfering with
Xanother version of Vi.
X
XOn the Amiga two types of environment variables exist. The ones set with the
XDOS 1.3 (or later) setenv command are recognized. See the AmigaDos 1.3
Xmanual. The environment variables set with the old Manx Set command (before
Xversion 5.0) are not recognized.
X
XOn MS-DOS systems Vim assumes that all the "_vimrc" and "_exrc" files have
X<CR><LF> pairs as line separators. This will give problems if you have a
Xfile with only <LF>s and have a line like ":map xx yy^M". The trailing ^M
Xwill be ignored.
X
XWhile reading the ".vimrc" or the ".exrc" file in the current directory some
Xcommands can be disabled for security reasons by setting the 'secure'
Xoption. Otherwise it would be possible to create a .exrc that contains nasty
Xcommands, which another user may automatically execute when he starts Vim it
Xthat directory. The disabled commands are the ones that start a shell and
Xthe ones that write to a file. The ":map" commands are echoed, so you can
Xsee which keys are being mapped.
X
XYou can reset the 'secure' option in the EXINIT or VIMINIT environment
Xvariable or in the global ".exrc" or ".vimrc" file. This is not possible in
X".vimrc" or ".exrc" in the current directory, for obvious reasons.
X
XOn unix systems this only happens if you are not the owner of the ".vimrc"
Xor ".exrc" file. Warning: If you unpack an archive that contains a .exrc
Xfile, it will be owned by you. You won't have the security protection. Check
Xthe .exrc file before you start Vim in that directory, or reset the 'exrc'
Xoption.
X
X
X3.5 Suspending
X
XCTRL-Z Suspend the editor. Same as ":stop".
X
X:sus[pend][!] or
X:st[op][!] Suspend the editor. If the <!> is not given,
X the buffer was changed, autowrite is set and
X a filename is known, the buffer will be
X written.
X
XOn many UNIX systems it is possible to suspend Vim with CTRL-Z. This is only
Xpossible in Command mode (see next chapter). Vim will continue if you make it
Xthe foreground job again. On other systems CTRL-Z will start a new shell.
XThis is the same as the ":sh" command. Vim will continue if you exit from the
Xshell.
X
X
X 4. Modes
X
X4.1 Introduction
X
XVim has four basic modes:
X
XCommand mode In Command mode you can enter all the editor
X commands. If you start the editor you are in this
X mode (unless you have set the 'insertmode' option,
X see below).
X
XInsert mode In Insert mode the text you type is inserted into the
X buffer. If the 'showmode' option is set (which is
X default), the string "-- INSERT --" is shown at the
X bottom of the window.
X
XReplace mode Replace mode is a special case of Insert mode. You
X can do the same things as in Insert mode, but for
X each character you enter (except some special
X characters) one character of the existing text is
X deleted. If the 'showmode' option is set (which is
X default), the string "-- REPLACE --" is shown at the
X bottom of the window.
X
XCommand_line mode In Command_line mode you can enter one line of text
X at the bottom of the window. This is for the Ex
X commands <:>, the pattern search commands <?></> and
X the filter command <!>.
X
XMore explanation on the insert, replace and Command_line mode is further on
Xin this chapter.
X
X
X4.2 Switching from mode to mode
X
XIf for any reason you do not know in which mode you are, you can always get
Xback to Command mode by typing <ESC> twice. You will know you are back in
XCommand mode when you see the screen flash or hear the bell after you type
X<ESC>.
X
X- go from Command mode to Insert mode by giving one of the commands
X "iIaAoOcCsS".
X- go from Command mode to Replace mode with the "R" command (not the "r"
X command!).
X- go from Command mode to Command_line mode with the one of the commands
X ":/?!".
X
X- go from insert or Replace mode to Command mode with <ESC> (twice in some
X rare cases).
X- go from Command_line mode to Command mode by:
X - hitting <CR> or <LF>, which causes the entered command to be executed
X - deleting the complete line (e.g. with CTRL-U) and giving a final <BS>
X - hitting CTRL-C or <ESC>, which quits the command line without executing
X the command.
X In the last case <ESC> may be the character defined with the 'wildchar'
X option, and start command line completion. You can ignore that and type
X <ESC> again. {vi: when hitting <ESC> the command line is executed. This is
X unexpected for most people, therefore it was changed in Vim. But when the
X <ESC> is part of a mapping the command line is executed. If you want the
X vi behaviour also when typing <ESC> use ":cmap ^V<ESC> ^V^M"}
X
XIf the 'insertmode' option is set, editing a file will start in Insert mode.
X
X
X4.3 Insert and Replace mode
X
X4.3.1 special keys
X
XIn insert and Replace mode the following characters have a special meaning,
Xother characters are inserted directly. To insert one of these special
Xcharacters into the buffer, precede it with CTRL-V. To insert a <NUL>
Xcharacter use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems you have to
Xuse "CTRL-V 003" to insert a CTRL-C.
X
Xchar action
X-----------------------------------------------------------------------
XCTRL-@ Insert previously inserted text and stop insert. {Vi: only
X when typed as first char, only up to 128 chars}
XCTRL-A Insert previously inserted text. {not in Vi}
XCTRL-B Toggle the 'revins' option (B for Backwards). {not in Vi}
XCTRL-C Quit insert mode, back to command mode. Do not check for
X abbreviations.
XCTRL-D Delete one shiftwidth of indent at the start of the current
X line. See also 'shiftround' option. When preceded with <^>
X or <0> delete all indent in the current line. With <^> the
X indent is restored in the next line. This is useful when
X inserting a label. {Vi: CTRL-D works only when used after
X autoindent}
XCTRL-E Insert the character which is below the cursor. {not in Vi}
XCTRL-H <BS> Delete the character before the cursor (see below). {Vi:
X does not delete autoindents}
XCTRL-I <TAB> Insert a tab. If the 'expandtab' option is on, the
X equivalent number of spaces is inserted (use CTRL-V <TAB> to
X avoid the expansion). See also the 'smarttab' option, section
X 4.3.4.
XCTRL-J <LF> Begin new line.
XCTRL-K {char1} {char2}
X Enter digraph (see 4.7). {not in Vi}
XCTRL-M <CR> Begin new line.
XCTRL-N Find next keyword (see 4.3.7). {not in Vi}
XCTRL-O Execute one Command mode command. See below. {not in Vi}
XCTRL-P Find previous keyword (see 4.3.7). {not in Vi}
XCTRL-R <0-9a-z"%:>
X Insert the contents of a numbered or named register. The
X text is inserted as if you typed it, but mappings and
X abbreviations are not used. If you have options like
X 'textwidht' or 'autoindent' set, this will influence what
X will be inserted. Use <"> for the unnamed register,
X containing the text of the last delete or yank. Use <%> for
X the current file name. Use <:> for the last command line. See
X the chapter on copying and moving text about registers. {<%>,
X <"> and <:> not in Vi}
XCTRL-T Insert one shiftwidth of indent at the start of the current
X line. See also 'shiftround' option. {Vi: only when in
X autoindent}
XCTRL-U Delete all entered characters in the current line (see
X below).
XCTRL-V Insert next non-digit literally. Up to three digits form the
X decimal value of a single byte. The non-digit and the three
X digits are not considered for mapping. {Vi: no decimal byte
X entry}
XCTRL-W Delete the word before the cursor (see below). See the
X section "word motions" for the definition of a word.
XCTRL-Y Insert the character which is above the cursor. {not in Vi}
XCTRL-[ or <ESC> End insert or Replace mode, back to Command mode.
X<DEL> Same as CTRL-H <BS>
X-----------------------------------------------------------------------
X
XThe effect of the <BS>, <DEL>, CTRL-W and CTRL-U depends on the 'backspace'
Xoption (unless 'revins' is set):
X
Xbackspace action
X option
X 0 delete stops in column 1 and start position of insert
X 1 delete stops at start position of insert
X 2 delete always, CTRL-W and CTRL-U stop once at start position of
X insert
X
XIf the 'backspace' option is non-zero and the cursor is in column 1 when one
Xof the three keys is used, the current line is joined with the previous
Xline. This effectively deletes the newline in front of the cursor. {Vi: does
Xnot cross lines, does not delete past start position of insert}
X
XWith CTRL-V followed by one, two or three digits you can enter the decimal
Xvalue of a byte, except 10. Normally CTRL-V is followed by three digits. The
Xformed byte is inserted as soon as you type the third digit. If you type
Xonly one or two digits and then a non-digit, the decimal value of those one
Xor two digits form the byte. After that the non-digit is dealt with in the
Xnormal way. If you enter a value of 10, it will end up in the file as a 0.
XThe 10 is a <LF>, which is used internally to represent the <NUL> character.
XWhen writing the buffer to a file the <LF> character is translated into
X<NUL>. The <LF> character is written at the end of each line. Thus if you
Xwant to insert a <LF> character in a file you will have to make a line
Xbreak.
X
X
X4.3.2 special special keys
X
XThe following keys are special. They stop the current insert, do something
Xand then restart insertion. This means you can do something without getting
Xout of Insert mode. This is very handy if you prefer to use the Insert mode
Xall the time, just like editors that don't have a separate Command mode. You
Xmay also want to set the 'backspace' option to 2 and set the 'insertmode'
Xoption. You can use CTRL-O if you want to map a function key to a command.
X
XThe changes (inserted or deleted characters) before and after these keys can
Xbe undone separately. Only the last change can be redone and always behaves
Xlike an "i" command.
X
Xchar action
X-----------------------------------------------------------------------
X<C_UP> cursor one line up
X<C_DOWN> cursor one line down
X<C_LEFT> cursor one character left
X<C_RIGHT> cursor one character right
X<SC_UP> move window one page up
X<SC_DOWN> move window one page down
X<SC_LEFT> cursor one word back (like "b" command)
X<SC_RIGHT> cursor one word forward (like "w" command)
XCTRL-O execute one command and return to Insert mode
X-----------------------------------------------------------------------
X
XThe CTRL-O command has one side effect: If the cursor was beyond the end of
Xthe line it will be put on the last character in the line.
XThe shifted cursor keys are not available on all terminals.
X
XWhen the 'whichwrap' option is set appropriately, the <C_LEFT> and <C_RIGHT>
Xkeys on the first/last character in the line make the cursor wrap to the
Xprevious/next line.
X
X
X4.3.3 'textwidth' and 'wrapmargin' option
X
XThe 'textwidth' option can be used to automatically break a line before it
Xgets too long. Set the 'textwidth' option to the desired maximum line
Xlength. If you then type more characters (not spaces or tabs), the
Xlast word will be put on a new line (unless it is the only word on the
Xline). If you set 'textwidth' to 0, this feature is disabled.
X
XThe 'wrapmargin' option does almost the same. The difference is that
X'textwidth' has a fixed width while 'wrapmargin' depends on the width of the
Xscreen. When using 'wrapmargin' this is equal to using 'textwidth' with a
Xvalue equal to (columns - 'wrapmargin'), where columns is the width of the
Xscreen.
X
XWhen 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used.
X
XThe line is only broken automatically when using insert mode, or when
Xappending to a line. When in replace mode and the line length is not
Xchanged, the line will not be broken.
X
XIf you want to format a block of text you can use the "Q" operator. Type "Q"
Xand a movement command to move the cursor to the end of the block. In many
Xcases the command "Q}" will do what you want (format until the end of
Xparagraph). Or you can use visual mode: hit "v", move to the end of the
Xblock and hit "Q".
X
X
X4.3.4 'expandtab' and 'smarttab' options
X
XIf the 'expandtab' option is set, spaces will be used to fill the amount of
Xwhitespace of the tab. If you want to enter a real <TAB> type CTRL-V first.
XThe 'expandtab' option is default off. Note that in Replace mode a single
Xcharacter is replaced by several spaces. The result of this is that the
Xnumber of characters in the line increases. Backspacing will delete one
Xspace at a time. The original text will be put back in a place where you
Xwould not expect it. {not in Vi}
X
XWhen the 'smarttab' option is set a TAB in front of a line inserts
X'shiftwidth' positions, 'tabstop' in other places. This means that often
Xspaces instead of a TAB character is inserted. When not set a TAB always
Xinserts 'tabstop' positions, 'shiftwidth' is only used for ">>" and the like.
X{not in Vi}
X
X
X4.3.5 typing backwards
X
XIf the 'revins' (reverse insert) option is set, inserting happens backwards.
XThis can be used to type Hebrew. When inserting characters the cursor is not
Xmoved and the text moves rightwards. A <BS> deletes the character under the
Xcursor. CTRL-W and CTRL-U also work in the opposite direction. <BS>, CTRL-W
Xand CTRL-U do not stop at the start of insert or end of line, no matter how
Xthe 'backspace' option is set.
X
XIn Replace mode the cursor is moved leftwards. <BS> will restore the
Xcharacter right of the cursor.
X
XIn insert or Replace mode the 'revins' option can be toggled with CTRL-B.
X
XIf the 'showmode' option is set, "-- REVERSE INSERT --" or
X"-- REVERSE REPLACE --" will be shown in the status line.
X
X
X4.3.6 Replace mode
X
XIn Replace mode one character in the line is deleted for every character you
Xtype. If there is no character to delete (at the end of the line), the
Xtyped character is appended (as in Insert mode). Thus the number of
Xcharacters in a line stays the same until you get to the end of the line.
X
XBe careful with <TAB> characters. If you type a normal printing character in
Xits place, the number of characters is still the same, but the number of
Xcolumns will become smaller.
X
XIf you delete characters in Replace mode (with <BS>, <DEL>, CTRL-W or
XCTRL-U), you really delete your changes. The characters that were replaced
Xare restored. If you had typed past the existing text, the characters you
Xadded are deleted.
X All this only works in the current line. If you have started a new line
X(replaced a character with a <CR>) Vim no longer remembers what happened in
Xthe previous line. If you backspace over the newline (only possible if the
X'backspace' option is non-zero), the two lines will be joined again, but
Xtyping further backspaces will not restore the original text. Only the
Xcursor is moved.
X If the 'expandtab' option is set, a <TAB> will replace one character
Xwith several spaces. When backspacing over these spaces, the original text
Xwill appear in a position where you would not expect it.
X
X
X4.3.7 Keyword completion
X
XIn insert and replace mode the keys CTRL-N and CTRL-P can be used to
Xcomplete the keyword that is in front of the cursor. This is useful if you
Xare writing a program that has complicated variable names, and you want to
Xcopy a name from the text before of after the cursor.
X
XIf there is an identifier in front of the cursor (a name made out of
Xalphanumeric characters and <_>) it is used as the search pattern, with "\<"
Xprepended (meaning: start of a word). Otherwise "\<[a-zA-Z_]" is used as
Xsearch pattern (start of any identifier).
X
XWith CTRL-N (next) the search goes forward, with CTRL-P (previous) the
Xsearch goes backward. The first time the search starts where the cursor is.
XThe next times the search starts at the last found position. If you type any
Xother character than CTRL-P or CTRL-N the current text is accepted and the
Xsearch pattern is forgotten.
X
XIf the search found a match, it is inserted at the cursor position. Any
Xprevious match is replaced. If no match was found, Vim will beep.
X
XIf there is not a valid identifier character before the cursor, any
Xidentifier is matched.
X eg. to get:
X printf("(%g, %g, %g)", vector[0], vector[1], vector[2]);
X just type:
X printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]);
X
XMultiple repeats of the same completion are skipped.
X
XIf there is only one completion found, then a second CTRL-P or CTRL-N will
Xgive the message 'No other matches'.
X
XIf the only match in the file is an exact match, where no extra characters
Xwould be typed, then the message 'Exact match only' is given (this is also
Xuseful for checking that you typed the symbol correctly).
X
XThe mode (--INSERT--) is shown, unless there is another more important
Xmessage (eg Pattern not found). This other message will stay until another
Xkey is hit, and then the mode is shown again.
X
XOnly matches where something extra will be added are used.
X eg. to get:
X printf("name = %s\n", name);
X just type:
X printf("name = %s\n", n^P);
XThe 'n' in '\n' is skipped.
X
X
X4.4 Command_line mode
X
XCommand_line mode is used to enter Ex commands <:>, search patterns </><?>
Xand filter commands <!>.
X
X
X4.4.1 Command line editing
X
XNormal characters are inserted in front of the cursor position. You can move
Xaround in the command line with the left and right cursor keys. {Vi: can
Xonly alter the last character in the line}
X
XThe command lines that you enter are remembered in a history table. You can
Xrecall them with the up and down cursor keys. Use the 'history' option to
Xset the number of lines that are remembered (default 20).
X
XThere is an automatic completion of names on the command line, see 4.4.2.
X
XCTRL-V Insert next non-digit literally. Up to three digits form the
X decimal value of a single byte. The non-digit and the three
X digits are not considered for mapping. This works the same
X way as in Insert mode (see above).
X<C_LEFT> cursor left
X<C_RIGHT> cursor right
X<SC_LEFT> cursor one word left
X<SC_RIGHT> cursor one word right
XCTRL-B cursor to begin of command line
XCTRL-E cursor to end of command line
X
X<BS> delete the character in front of the cursor
X<DEL> delete the character under the cursor (at end of line:
X character in front of the cursor)
XCTRL-W delete the word in front of the cursor
XCTRL-U remove all characters
X
X Note: if the command line becomes empty with one of the
X delete commands, command line mode is quit.
X
X{char1} <BS> {char2} or
XCTRL-K {char1} {char2}
X enter digraph (see 4.7). {not in Vi}
X
X<CR> or <LF> start entered command
X<ESC> when typed: quit command line without executing
X in macros: start entered command
XCTRL-C quit command line without executing
X
X<C_UP> recall older command line from history
X<C_DOWN> recall more recent command line from history
X
X<SC_UP> recall older command line from history, which begin matches
X the current command line (see below).
X<SC_DOWN> recall more recent command line from history, which begin
X matches the current command line (see below).
X
XCTRL-D command line completion (see 4.4.2)
X'wildchar' option
X command line completion (see 4.4.2)
XCTRL-N command line completion (see 4.4.2)
XCTRL-P command line completion (see 4.4.2)
XCTRL-A command line completion (see 4.4.2)
XCTRL-L command line completion (see 4.4.2)
X
XThe <SC_UP> and <SC_DOWN> keys take the current command line as search
Xstring. The beginning of the next/previous command lines are compared against
Xthis string. The fist line that matches is the new command line. When typing
Xthese two keys repeatedly, the same string is used again. For example this
Xcan be used to find the previous substitute command: Type ":s" and then
X<SC_UP>. The same could be done by typing <C_UP> a number of times until the
Xdesired command line is shown. (Note: the shifted arrow keys do not work on
Xall terminals)
X
X
X4.4.2 Command line completion
X
XWhen editing the command line a few commands can be used to complete the
Xword before the cursor. This is available for:
X
X- Command names, at the start of the command line. Works always.
X- tags, only after the ":tag" command.
X- file names, only after a command that accepts a file name or a setting for
X an option that can be set to a file name. This is called file name
X completion.
X- options, only after the ":set" command.
X
XThese are the commands that can be used:
X
XCTRL-D List names that match the pattern in front of the cursor.
X When showing file names, directories are highlighted (see
X 'highlight' option)
X'wildchar' option
X A match is done on the pattern in front of the cursor. The
X match, or if there are several, the first match, is inserted
X in place of the pattern. (Note: does not work inside a
X macro, because TAB or ESC is mostly used as 'wildchar', and
X these have a special meaning in some macros)
X When typed again, and there were multiple matches, the next
X match is inserted. After the last match the first is used
X again (wrap around).
XCTRL-N After using 'wildchar' which got multiple matches: go to next
X match. Otherwise: Recall more recent command line from history.
XCTRL-P After using 'wildchar' which got multiple matches: go to
X previous match. Otherwise: Recall older command line from
X history.
XCTRL-A All names that match the pattern in front of the cursor are
X inserted.
XCTRL-L A match is done on the pattern in front of the cursor. If
X there is one match, it is inserted in place of the pattern.
X If there are multiple matches the longest common part is
X inserted in place of the pattern.
X
XThe 'wildchar' option defaults to <TAB> (CTRL-E when compiled with
XCOMPATIBLE; in a previous version <ESC> was used). In the pattern standard
Xwildcards <*> and <?> are accepted. <*> matches any string, <?> matches
Xexactly one character.
X
XFor filename completion you can use the 'suffixes' option to set a priority
Xbetween files with almost the same name. If there are multiple matches,
Xthose files with an extension that is in the 'suffixes' option are ignored.
XThe default is ".bak.o.h.info.swp", which means that files with the
Xextensions ".bak", ".o", ".h", ".info" and ".swp" are sometimes ignored. It
Xis impossible to ignore suffixes with two dots. Examples:
X
Xpattern: files: match:
Xtest* test.c test.h test.o test.c
Xtest* test.h test.o test.h and test.o
Xtest* test.i test.h test.c test.i and test.c
X
XIf there is more than one matching file (after ignoring the ones matching
Xthe 'suffixes' option) the first file name is inserted. You can see that
Xthere is only one match when you type 'wildchar' twice and the completed
Xmatch stays the same. You can get to the other matches by entering
X'wildchar', CTRL-N or CTRL-P. All files are included, also the ones with
Xextensions matching the 'suffixes' option.
X
X
X4.4.3 Ex command lines
X
XThe Ex commands have a few specialties:
X
X<"> at the start of a line causes the whole line to be ignored. <">
Xafter a command causes the rest of the line to be ignored. This can be used
Xto add comments. Example:
X :set ai "set 'autoindent' option
XIt is not possible to add a comment to a shell command ":!cmd" or to the
X":map" command and friends, because they see the <"> as part of their
Xargument.
X
X<|> can be used to separate commands, so you can give multiple commands in
Xone line. The commands ":global", "vglobal" and ":!" see the <|> as their
Xargument, and can therefore not be followed by another command. If you want
X<|> to be included in a command, precede it with <\>. Note that this is
Xconfusing (inherited from vi). If you give a command with ":!" you don't
Xhave to use a backslash, with ":r !" you have to. And with ":g" the <|> is
Xincluded in the command, with ":s" it is not. Examples:
X :!ls | wc view the output of two commands
X :r !ls \| wc insert the same output in the text
X :%g/foo/p|> moves all matching lines one shiftwidth
X :%s/foo/bar/|> moves one line one shiftwidth
XYou can also use <LF> to separate commands in the same way as with <|>. But
Xusing <|> is the preferred method.
X
XWhen the character <%> or <#> is used where a filename is expected, they are
Xexpanded to the current and alternate filename (see the chapter "editing
Xfiles").
X
XEmbedded spaces in filenames are allowed if one filename is expected as
Xargument. Trailing spaces will be ignored, unless escaped with a backslash
Xor CTRL-V. Note that the ":next" command uses spaces to separate file names.
XEscape the spaces to include them in a file name. Example:
X :next foo\ bar goes\ to school\
Xstarts editing the three files "foo bar", "goes to" and "school ".
X
XWhen you want to use the special characters <"> or <|> in a command, or want
Xto use <%> or <#> in a filename, precede them with a backslash. The backslash
Xis not required in a range and in the ":substitute" command.
X
X
X4.4.4 Ex command line ranges
X
XSome Ex commands accept a line range in front of them. This is noted as
X[range]. It consists of one or more line specifiers, separated with <,> or
X<;>. When separated with <;> the cursor position will be set to that line
Xbefore interpreting the next line specifier. The default line specifier for
Xmost commands is the cursor position, but the commands ":write" and
X":global" have the whole file (1,$) as default. If more line specifiers are
Xgiven than required for the command, the first one(s) will be ignored.
X
XLine numbers may be specified with:
X {number} an absolute line number
X . the current line
X $ the last line in the file
X % equal to 1,$ (the entire file)
X 't position of mark t (lower case)
X /{pattern}[/] the next line where {pattern} matches
X ?{pattern}[?] the previous line where {pattern} matches
X
XEach may be followed (several times) by <+> or <-> and an optional number.
XThis number is added or subtracted from the preceding line number. If the
Xnumber is omitted, 1 is used.
X
XThe "/" and "?" may be preceded with another address. The search starts from
Xthere. The "/" and "?" after {pattern} are required to separate the pattern
Xfrom anything that follows.
X
XThe {number} must be between 0 and the number of lines in the file. A 0 is
Xinterpreted as a 1, except with the commands tag, pop and read.
X
XExamples:
X .+3 three lines below the cursor
X /that/+1 the line below the next line containing "that"
X .,$ from current line until end of file
X 0/that the first line containing "that"
X
XSome commands allow for a count after the command. This count is used as the
Xnumber of lines to be used, starting with the line given in the last line
Xspecifier (the default is the cursor line). The commands that accept a count
Xare the ones that use a range but do not have a file name argument (because
Xa file name can also be a number).
X
XExamples:
X :s/x/X/g 5 substitute <x> by <X> in the current line and four
X following lines
X :23d 4 delete lines 23, 24, 25 and 26
X
XA range should have the lower line number first. If this is not the case, Vim
Xwill ask you if it should swap the line numbers. This is not done within the
Xglobal command ":g".
X
XWhen giving a count before entering ":", this is translated into:
X :.,.+(count - 1)
XIn words: The 'count' lines at and after the cursor. Example: To delete
Xthree lines:
X 3:d<CR> is translated into: .,.+2d<CR>
X
X
X4.5 The window contents
X
XIn command and Insert/Replace mode the screen window will show the current
Xcontents of the buffer: What You See Is What You Get. {Vi: when changing
Xtext a <$> is placed on the last changed character; The window is not always
Xupdated on slow terminals} Lines longer than the window width will wrap,
Xunless the 'wrap' option is off (see below). The bottom lines in the window
Xmay start with one of these two characters:
X
X<@> The next line is too long to fit in the window.
X<~> Below the last line in the buffer.
X
XIf the bottom line is completely filled with <@>, the line that is at the
Xtop of the window is too long to fit in the window. If the cursor is on this
Xline you can't see what you are doing, because this part of the line is not
Xshown. However, the part of the line before the <@>s can be edited normally.
X{Vi: gives an "internal error" on lines that do not fit in the window}
X
XIf the 'wrap' option is off, long lines will not wrap. Only the part that
Xfits on the screen is shown. If the cursor is moved to a part of the line
Xthat is not shown, the screen is scrolled horizontally. The advantage of
Xthis method is that columns are shown as they are and lines that cannot fit
Xon the screen can be edited. The disadvantage is that you cannot see all the
Xcharacters of a line at once. The 'sidescroll' option can be set to the
Xminimal number of columns to scroll. {Vi: has no 'wrap' option}
X
XAll normal ASCII characters are displayed directly on the screen. The <TAB>
Xis replaced by the number of spaces that it represents. Other non-printing
Xcharacters are replaced by "^<char>", where <char> is the non-printing
Xcharacter with 64 added. Thus character 7 (bell) will be shown as "^G".
XCharacters between 127 and 160 are replaced by "~<char>", where <char> is
Xthe character with 64 subtracted. These characters occupy more than one
Xposition on the screen. The cursor can only be positioned on the first one.
X
XIf you set the 'number' option, all lines will be preceded with their
Xnumber.
X
XIf you set the 'list' option, <TAB> characters will not be shown as several
Xspaces, but as "^I". A <$> will be placed at the end of the line, so you can
Xfind trailing blanks.
X
XIn Command_line mode only the command line itself is shown correctly. The
Xdisplay of the buffer contents is updated as soon as you go back to Command
Xmode.
X
XSome commands hand over the window to external commands (e.g. ":shell" and
X"="). After these commands are finished the window may be clobbered with
Xoutput from the external command, so it needs to be redrawn. This is also
Xthe case if something is displayed on the status line that is longer than
Xthe width of the window. If you are expected to have a look at the screen
Xbefore it is redrawn, you get this message:
X
X Press RETURN or enter command to continue
X
XAfter you type a key the screen will be redrawn and Vim continues. If you
Xtype <CR>, <SP> or <LF> nothing else happens. If you type any other key, it
Xwill be interpreted as (the start of) a new command. {Vi: only <:> commands
Xare interpreted}
X
XThe last line of the window is used for status and other messages. The
Xstatus messages will only be used if an option is on:
X
Xstatus message option default unix default
Xcurrent mode 'showmode' on on
Xcommand characters 'showcmd' on off
Xcursor position 'ruler' off off
X
XThe current mode is "-- INSERT --" or "-- REPLACE --". The command
Xcharacters are those that you typed but were not used yet. {Vi: does not
Xshow the characters you typed or the cursor position}
X
XIf you have a slow terminal you can switch off the status messages to speed
Xup editing:
X :set nosc noru nosm
X
XIf there is an error, an error message will be shown for at least one second
X(in reverse video). {Vi: error messages may be overwritten with other
Xmessages before you have a chance to read them}
X
XSome commands show how many lines were affected. Above which threshold this
Xhappens can be controlled with the 'report' option (default 2).
X
XOn the Amiga Vim will run in a CLI window. The name Vim and the full name of
Xthe current filename will be shown in the title bar. When the window is
Xresized, Vim will automatically redraw the window. You may make the window as
Xsmall as you like, but if it gets too small not a single line will fit in it.
XMake it at least 40 characters wide to be able to read most messages on the
Xlast line.
X
XOn most Unix systems window resize works ok. {Vi: not ok}
X
X
X4.6 Abbreviations
X
XAbbreviations are used in insert mode, Replace mode and Command_line mode.
XIf you enter a word that is an abbreviation, it is replaced by the word it
Xstands for. This can be used to save typing for often used long words.
X
XThere are two types of abbreviations: The "full-id" type consists entirely
Xof id characters (letters, digits and <_> characters). This is the most
Xcommon abbreviation. The "non-id" type ends in an id character, but all the
Xother characters are not id characters. Examples of a "full-id" type are
X"foo" and "c_1". Examples of a "non-id" type are "#i" and "$/7". Examples of
Xstrings that will not be recognized as an abbreviation are "a.b", "a b" and
X"_$ar".
X
XThe "full-id" abbreviation is recognized if:
X- A character is typed that is not an id character. This can also be
X the <ESC> that ends insert mode or the <CR> that ends a command.
X- The characters in front of the cursor match the abbreviation.
X- In front of the match is a non-id character, or this is where the line or
X insertion starts. Exception: when the abbreviation is only one character,
X it is not recognized if there is a non-id character in front of it, other
X than a space or a TAB.
X
XThe "non-id" abbreviation is recognized if:
X- A character is typed that is not an id character. This can also be
X the <ESC> that ends insert mode or the <CR> that ends a command.
X- The characters in front of the cursor match the abbreviation.
X- In front of the match is an id character, or a space or a TAB, or this is
X where the line or insertion starts.
X
XExample: ":ab foo four old otters". Note that spaces in the <rhs> are
Xallowed and included in the replacement string. If you now insert the word
X"foo" with a space before and after it, it will be replaced by "four old
Xotters". If you would type "foobar" or "barfoo" nothing happens.
X
XTo avoid the abbreviation in insert mode type part of the abbreviation, exit
Xinsert mode with <ESC>, re-enter insert mode with "a" and type the rest. In
XCommand_line mode you can type CTRL-V twice somewhere in the abbreviation to
Xavoid it to be replaced. A CTRL-V in front of a normal character is mostly
Xignored otherwise.
X
XThere are no default abbreviations.
X
XAbbreviations are never recursive. You can use ":ab f f-o-o" without any
Xproblem. But abbreviations can be mapped. {some versions of vi support
Xrecursive abbreviations, for no apparent reason}
X
XAbbreviations are disabled if the 'paste' option is set.
X
X:ab[breviate] list all abbreviations. The character in the first
X column indicates the mode where the abbreviation is
X used: 'i' for insert mode, 'c' for Command_line
X mode, '!' for both.
X
X:ab[breviate] <lhs> list the abbreviations that start with <lhs>
X
X:ab[breviate] <lhs> <rhs>
X add abbreviation for <lhs> to <rhs>. If <lhs> already
X existed it is replaced with the new <rhs>. <rhs> may
X contain spaces.
X
X:una[bbreviate] <lhs> remove abbreviation for <lhs> from the list
X
X:norea[bbrev] [lhs] [rhs]
X same as ":ab", but no remapping for this <rhs> {not
X in Vi}
X
X:ca[bbrev] [lhs] [rhs] same as ":ab", but for Command_line mode only. {not
X in Vi}
X
X:cuna[bbrev] <lhs> same as ":una", but for Command_line mode only. {not
X in Vi}
X
X:cnorea[bbrev] [lhs] [rhs]
X same as ":ab", but for Command_line mode only and no
X remapping for this <rhs> {not in Vi}
X
X:ia[bbrev] [lhs] [rhs] same as ":ab", but for insert mode only. {not in Vi}
X
X:iuna[bbrev] <lhs> same as ":una", but for insert mode only. {not in
X Vi}
X
X:inorea[bbrev] [lhs] [rhs]
X same as ":ab", but for insert mode only and no
X remapping for this <rhs> {not in Vi}
X
X
X4.7 Digraphs
X
X:dig[raphs] show currently defined digraphs. {not in Vi}
X
X:dig[raphs] {char1}{char2} {number} ...
X Add digraph {char1}{char2} to the list. {number} is
X the decimal representation of the character.
X
XDigraphs are used to enter characters that normally cannot be entered by
Xan ordinary keyboard. These are mostly accented characters which have the
Xeighth bit set. The digraphs are easier to remember than the decimal number
Xthat can be entered with CTRL-V (see above).
X
XVim must have been compiled with the 'digraphs' option enabled. If not, the
X":digraph" command will display an error message.
X
XThere are two methods to enter digraphs:
X CTRL-K {char1} {char2} or
X {char1} <BS> {char2}
XThe first is always available. The second only when the 'digraph' option is
Xset.
X
XOnce you have entered the digraph the character is treated like a normal
Xcharacter, taking up only one character in the file and on the screen.
XExample:
X <|> <BS> <|> will enter the double <|> character (166)
X <a> <BS> <^> will enter an <a> with a hat (226)
X CTRL-K <-> <-> will enter a minus sign (173)
X
XThe default digraphs are listed in the file digraph.doc. They are meant for
Xthe Amiga character set, which is some international standard. With another
Xcharacter set they may be illogical.
X
XFor CTRL-K there is one general digraph: CTRL-K <SPACE> {char} will enter
X{char} with the highest bit set. This can be used to enter meta-characters.
X
XThe <ESC> character cannot be part of a digraph. When hitting <ESC> entering
Xthe digraph is aborted and insert mode too.
X
XIf you accidently typed an <a> that should be an <e>, you will type <a> <BS>
X<e>. But that is a digraph, so you will not get what you want. To avoid this,
Xuse <DEL> instead of <BS>. Or don't set the 'digraph' option and use CTRL-K
Xto enter digraphs.
X
X
X 5. Editing files
X
X5.1 Introduction
X
XEditing a file with Vim means:
X
X1. reading the file into the internal buffer
X2. changing the buffer with editor commands
X3. writing the buffer into a file
X
XAs long as you don't write the buffer, the original file remains unchanged.
XIf you start editing a file (read a file into the buffer), the file name is
Xremembered as the "current filename".
X
XIf there already was a current filename, then that one becomes the alternate
Xfile name. All filenames are remembered in the file list. When you enter a
Xfilename, for editing (e.g. with ":e filename") or writing (e.g. with (:w
END_OF_FILE
if test 52085 -ne `wc -c <'vim/doc/reference.doc.A'`; then
echo shar: \"'vim/doc/reference.doc.A'\" unpacked with wrong size!
elif test -f 'vim/doc/reference.doc.B' && test -f 'vim/doc/reference.doc.C' && test -f 'vim/doc/reference.doc.D'; then
echo shar: Combining \"'vim/doc/reference.doc'\" \(210836 characters\)
cat 'vim/doc/reference.doc.A' 'vim/doc/reference.doc.B' 'vim/doc/reference.doc.C' 'vim/doc/reference.doc.D' > 'vim/doc/reference.doc'
if test 210836 -ne `wc -c <'vim/doc/reference.doc'`; then
echo shar: \"'vim/doc/reference.doc'\" combined with wrong size!
else
rm vim/doc/reference.doc.A vim/doc/reference.doc.B vim/doc/reference.doc.C vim/doc/reference.doc.D
fi
fi
# end of 'vim/doc/reference.doc.A'
fi
if test -f 'vim/src/archie.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vim/src/archie.c'\"
else
echo shar: Extracting \"'vim/src/archie.c'\" \(13434 characters\)
sed "s/^X//" >'vim/src/archie.c' <<'END_OF_FILE'
X/* vi:ts=4:sw=4
X *
X *
X * VIM - Vi IMproved
X *
X * Code Contributions By: Bram Moolenaar mool@oce.nl
X * Tim Thompson twitch!tjt
X * Tony Andrews onecom!wldrdg!tony
X * G. R. (Fred) Walter watmath!watcgl!grwalter
X */
X/*
X * archie.c -- RISC OS + UnixLib specific code.
X *
X * A lot of this file was written by Juergen Weigert.
X *
X * It was then hacked to pieces by Alun Jones to work on the Acorn
X * Archimedes!
X */
X
X#include "vim.h"
X#include "globals.h"
X#include "param.h"
X#include "proto.h"
X
X#include <fcntl.h>
X#include <time.h>
X#include <unistd.h>
X#include <sys/types.h>
X#include <sys/os.h>
X#include <signal.h>
X
X#include <termio.h>
X
Xstatic int Read __ARGS((char *, long));
Xstatic int WaitForChar __ARGS((int));
Xstatic int RealWaitForChar __ARGS((int));
Xstatic void fill_inbuf __ARGS((void));
X
Xstatic int do_resize = FALSE;
X
X/* I'm sure this should be defined in UnixLib, but it ain't!
X */
Xshort ospeed;
X
X void
Xmch_write(s, len)
X char *s;
X int len;
X{
X int i;
X for (i=0; i<len; i++)
X {
X os_vdu(s[i]);
X }
X}
X
X/*
X * GetChars(): low level input funcion.
X * Get a characters from the keyboard.
X * If time == 0 do not wait for characters.
X * If time == n wait a short time for characters.
X * If time == -1 wait forever for characters.
X */
X int
XGetChars(buf, maxlen, time)
X char *buf;
X int maxlen;
X int time;
X{
X if (time >= 0)
X {
X if (WaitForChar(time) == 0) /* no character available */
X return 0;
X }
X else /* time == -1 */
X {
X /*
X * If there is no character available within 2 seconds (default)
X * write the autoscript file to disk
X */
X if (WaitForChar((int)p_ut) == 0)
X updatescript(0);
X }
X
X WaitForChar(-1);
X return Read(buf, (long)maxlen);
X}
X
X void
Xvim_delay()
X{
X clock_t now;
X
X now = clock();
X while (clock() < now + CLOCKS_PER_SEC/2);
X}
X
X/*
X * No job control. Fake it by starting a new shell.
X */
X void
Xmch_suspend()
X{
X outstr("new shell started\n");
X call_shell(NULL, 0, 1);
X}
X
X void
Xmch_windinit()
X{
X Columns = 80;
X Rows = 24;
X
X flushbuf();
X
X mch_get_winsize();
X}
X
X/*
X * Check_win checks whether we have an interactive window.
X */
X
X void
Xcheck_win(argc, argv)
X int argc;
X char **argv;
X{
X if (!isatty(0) || !isatty(1))
X {
X fprintf(stderr, "VIM: no controlling terminal\n");
X exit(2);
X }
X}
X
X/*
X * fname_case(): Set the case of the filename, if it already exists.
X * This will cause the filename to remain exactly the same.
X */
X void
Xfname_case(name)
X char *name;
X{
X}
X
X void
Xsettitle(str)
X char *str;
X{
X}
X
X void
Xresettitle()
X{
X}
X
X/*
X * Get name of current directory into buffer 'buf' of length 'len' bytes.
X * Return non-zero for success.
X */
X int
Xdirname(buf, len)
X char *buf;
X int len;
X{
X extern int errno;
X extern char *sys_errlist[];
X
X if (getcwd(buf,len) == NULL)
X {
X strcpy(buf, sys_errlist[errno]);
X return 0;
X }
X return 1;
X}
X
X/*
X * get absolute filename into buffer 'buf' of length 'len' bytes
X */
X int
XFullName(fname, buf, len)
X char *fname, *buf;
X int len;
X{
X int l;
X char olddir[MAXPATHL];
X char *p;
X int c;
X int retval = 1;
X
X if (fname == NULL) /* always fail */
X return 0;
X
X *buf = 0;
X if (*fname != '/')
X {
X /*
X * If the file name has a path, change to that directory for a moment,
X * and then do the getwd() (and get back to where we were).
X * This will get the correct path name with "../" things.
X */
X if ((p = strrchr(fname, '/')) != NULL)
X {
X if (getcwd(olddir, MAXPATHL) == NULL)
X {
X p = NULL; /* can't get current dir: don't chdir */
X retval = 0;
X }
X else
X {
X c = *p;
X *p = NUL;
X chdir("\\"); /* Try to maintain PSD */
X if (chdir(fname))
X retval = 0;
X else
X fname = p + 1;
X *p = c;
X }
X }
X if (getcwd(buf, len) == NULL)
X {
X retval = 0;
X *buf = NUL;
X }
X l = strlen(buf);
X if (l && buf[l - 1] != '/')
X strcat(buf, "/");
X if (p)
X {
X chdir("\\"); /* Maintain PSD */
X chdir(olddir);
X }
X }
X strcat(buf, fname);
X return retval;
X}
X
X/*
X * get file permissions for 'name'
X */
X long
Xgetperm(name)
X char *name;
X{
X struct stat statb;
X
X if (stat(name, &statb))
X return -1;
X return statb.st_mode;
X}
X
X/*
X * set file permission for 'name' to 'perm'
X */
X int
Xsetperm(name, perm)
X char *name;
X int perm;
X{
X return chmod(name, perm);
X}
X
X/*
X * check if "name" is a directory
X */
X int
Xisdir(name)
X char *name;
X{
X struct stat statb;
X
X if (stat(name, &statb))
X return -1;
X return (statb.st_mode & S_IFMT) == S_IFDIR;
X}
X
X void
Xmch_windexit(r)
X int r;
X{
X settmode(0);
X stoptermcap();
X flushbuf();
X stopscript(); /* remove autoscript file */
X exit(r);
X}
X
X void
Xmch_settmode(raw)
X int raw;
X{
X static int old225, old226, old4;
X int retvals[3];
X static struct termio told;
X struct termio tnew;
X
X if (raw)
X {
X /* Make arrow keys act as function keys.
X */
X os_byte(4, 2, 0, retvals);
X old4 = retvals[1];
X /* Now make function keys return NULL followed by a character.
X * Remember the old value for resetting.
X */
X os_byte(225, 0xC0, 0, retvals);
X old225 = retvals[1];
X os_byte(226, 0xD0, 0, retvals);
X old226 = retvals[1];
X
X ioctl(0, TCGETA, &told);
X tnew = told;
X tnew.c_iflag &= ~(ICRNL | IXON); /* ICRNL enables typing ^V^M */
X /* IXON enables typing ^S/^Q */
X tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE);
X tnew.c_cc[VMIN] = 1; /* return after 1 char */
X tnew.c_cc[VTIME] = 0; /* don't wait */
X ioctl(0, TCSETA, &tnew);
X }
X else
X {
X os_byte(4, old4, 0, retvals);
X os_byte(225, old225, 0, retvals);
X os_byte(226, old226, 0, retvals);
X ioctl(0, TCSETA, &told);
X }
X}
X
X/*
X * Try to get the current window size:
X * 1. with an ioctl(), most accurate method
X * 2. from the environment variables LINES and COLUMNS
X * 3. from the termcap
X * 4. keep using the old values
X */
X int
Xmch_get_winsize()
X{
X int old_Rows = Rows;
X int old_Columns = Columns;
X char *p;
X
X Columns = 0;
X Rows = 0;
X
X/*
X * 1. try using an ioctl. It is the most accurate method.
X */
X {
X struct winsize ws;
X
X if (ioctl(0, TIOCGWINSZ, &ws) == 0)
X {
X Columns = ws.ws_col;
X Rows = ws.ws_row;
X }
X }
X
X/*
X * 2. get size from environment
X */
X if (Columns == 0 || Rows == 0)
X {
X if ((p = (char *)getenv("LINES")))
X Rows = atoi(p);
X if ((p = (char *)getenv("COLUMNS")))
X Columns = atoi(p);
X }
X
X/*
X * 3. try reading the termcap
X */
X if (Columns == 0 || Rows == 0)
X {
X extern void getlinecol();
X
X getlinecol(); /* get "co" and "li" entries from termcap */
X }
X
X/*
X * 4. If everything fails, use the old values
X */
X if (Columns <= 0 || Rows <= 0)
X {
X Columns = old_Columns;
X Rows = old_Rows;
X return 1;
X }
X debug2("mch_get_winsize: %dx%d\n", (int)Columns, (int)Rows);
X
X Rows_max = Rows; /* remember physical max height */
X
X check_winsize();
X script_winsize();
X
X/* if size changed: screenalloc will allocate new screen buffers */
X return (0);
X}
X
X void
Xmch_set_winsize()
X{
X /* should try to set the window size to Rows and Columns */
X}
X
X int
Xcall_shell(cmd, dummy, cooked)
X char *cmd;
X int dummy;
X int cooked;
X{
X int x;
X char newcmd[1024];
X
X flushbuf();
X
X if (cooked)
X settmode(0); /* set to cooked mode */
X
X if (cmd == NULL)
X x = system(p_sh);
X else
X {
X sprintf(newcmd, "*%s", cmd);
X x = system(newcmd);
X }
X if (x == 127)
X {
X emsg("Cannot execute shell sh");
X outchar('\n');
X }
X else if (x)
X {
X smsg("%d returned", x);
X outchar('\n');
X }
X
X if (cooked)
X settmode(1); /* set to raw mode */
X return x;
X
X}
X
X/*
X * The input characters are buffered to be able to check for a CTRL-C.
X * This should be done with signals, but I don't know how to do that in
X * a portable way for a tty in RAW mode.
X */
X
X#define INBUFLEN 50
Xstatic unsigned char inbuf[INBUFLEN]; /* internal typeahead buffer */
Xstatic int inbufcount = 0; /* number of chars in inbuf[] */
X
X static int
XRead(buf, maxlen)
X char *buf;
X long maxlen;
X{
X if (inbufcount == 0) /* if the buffer is empty, fill it */
X fill_inbuf();
X if (maxlen > inbufcount)
X maxlen = inbufcount;
X memmove(buf, inbuf, maxlen);
X inbufcount -= maxlen;
X if (inbufcount)
X memmove(inbuf, inbuf + maxlen, inbufcount);
X return (int)maxlen;
X}
X
X void
Xbreakcheck()
X{
X/*
X * check for CTRL-C typed by reading all available characters
X */
X if (RealWaitForChar(0)) /* if characters available */
X fill_inbuf();
X}
X
X static void
Xfill_inbuf()
X{
X int len;
X
X if (inbufcount >= INBUFLEN) /* buffer full */
X return;
X
X for (len=0; len < INBUFLEN-inbufcount; len++)
X {
X int key;
X
X key = os_inkey(0);
X if (key==-1)
X {
X break;
X }
X inbuf[inbufcount+len] = key;
X }
X
X while (len-- > 0)
X {
X /*
X * if a CTRL-C was typed, remove it from the buffer and set got_int
X */
X if (inbuf[inbufcount] == 3)
X {
X /* remove everything typed before the CTRL-C */
X memmove(inbuf, inbuf + inbufcount, len + 1);
X inbufcount = 0;
X got_int = TRUE;
X }
X ++inbufcount;
X }
X}
X
X/*
X * Wait "ticks" until a character is available from the keyboard or from inbuf[]
X * ticks = -1 will block forever
X */
X
X static int
XWaitForChar(ticks)
X int ticks;
X{
X if (inbufcount) /* something in inbuf[] */
X return 1;
X return RealWaitForChar(ticks);
X}
X
X/*
X * Wait "ticks" until a character is available from the keyboard
X * ticks = -1 will block forever
X */
X static int
XRealWaitForChar(ticks)
X int ticks;
X{
X int key;
X
X if (ticks == -1)
X {
X key = os_get();
X }
X else
X {
X key = os_inkey(ticks/10);
X }
Xdebug3("RWFC(%d) got %d (%c)\n", ticks, key, key);
X
X if (key != -1)
X {
X /* Unfortunately the key has now been taken from the
X * buffer, so we need to put it in outselves. It's a
X * shame, but the other way I can think of involves a
X * keyboard scan, and this would return for SHIFT, etc.
X */
X if (inbufcount < INBUFLEN)
X {
X inbuf[inbufcount++] = key;
X }
X }
X return (key != -1);
X}
X
X/*
X * ExpandWildCard() - this code does wild-card pattern matching using the shell
X *
X * Mool: return 0 for success, 1 for error (you may loose some memory) and
X * put an error message in *file.
X *
X * num_pat is number of input patterns
X * pat is array of pointers to input patterns
X * num_file is pointer to number of matched file names
X * file is pointer to array of pointers to matched file names
X * On Unix we do not check for files only yet
X * list_notfound is ignored
X */
X
Xextern char *mktemp __ARGS((char *));
X#ifndef SEEK_SET
X# define SEEK_SET 0
X#endif
X#ifndef SEEK_END
X# define SEEK_END 2
X#endif
X
X int
XExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound)
X int num_pat;
X char **pat;
X int *num_file;
X char ***file;
X int files_only;
X int list_notfound;
X{
X char tmpname[TMPNAMELEN];
X char *command;
X int i;
X int dir;
X size_t len;
X FILE *fd;
X char *buffer;
X char *p;
X
X *num_file = 0; /* default: no files found */
X *file = (char **)"";
X
X /*
X * If there are no wildcards, just copy the names to allocated memory.
X * Saves a lot of time, because we don't have to run glob.
X */
X if (!have_wildcard(num_pat, pat))
X {
X *file = (char **)alloc(num_pat * sizeof(char *));
X if (*file == NULL)
X {
X *file = (char **)"";
X return 1;
X }
X for (i = 0; i < num_pat; i++)
X (*file)[i] = strsave(pat[i]);
X *num_file = num_pat;
X return 0;
X }
X
X/*
X * get a name for the temp file
X */
X strcpy(tmpname, TMPNAME2);
X if (*mktemp(tmpname) == NUL)
X {
X emsg(e_notmp);
X return 1;
X }
X
X len = TMPNAMELEN + 10;
X for (i = 0; i < num_pat; ++i) /* count the length of the patterns */
X len += strlen(pat[i]) + 1;
X command = (char *)alloc(len);
X if (command == NULL)
X return 1;
X strcpy(command, "glob >"); /* built the shell command */
X strcat(command, tmpname);
X for (i = 0; i < num_pat; ++i)
X {
X strcat(command, " ");
X strcat(command, pat[i]);
X }
X i = call_shell(command, 0, FALSE); /* execute it */
X free(command);
X if (i) /* call_shell failed */
X {
X remove(tmpname);
X sleep(1); /* give the user a chance to read error messages */
X must_redraw = CLEAR; /* probably messed up screen */
X return 1;
X }
X
X/*
X * read the names from the file into memory
X */
X fd = fopen(tmpname, "r");
X if (fd == NULL)
X {
X emsg(e_notopen);
X return 1;
X }
X
X fseek(fd, 0L, SEEK_END);
X len = ftell(fd); /* get size of temp file */
X fseek(fd, 0L, SEEK_SET);
X buffer = (char *)alloc(len + 1);
X if (buffer == NULL)
X {
X remove(tmpname);
X fclose(fd);
X return 1;
X }
X i = fread(buffer, 1, len, fd);
X fclose(fd);
X remove(tmpname);
X if (i != len)
X {
X emsg(e_notread);
X free(buffer);
X return 1;
X }
X
X buffer[len] = NUL; /* make sure the buffers ends in NUL */
X i = 0;
X for (p = buffer; p < buffer + len; ++p)
X if (*p == NUL) /* count entry */
X ++i;
X if (len)
X ++i; /* count last entry */
X
X *num_file = i;
X *file = (char **)alloc(sizeof(char *) * i);
X if (*file == NULL)
X {
X free(buffer);
X *file = (char **)"";
X return 1;
X }
X p = buffer;
X
X for (i = 0; i < *num_file; ++i)
X {
X (*file)[i] = p;
X while (*p && p < buffer + len) /* skip entry */
X ++p;
X ++p; /* skip NUL */
X }
X for (i = 0; i < *num_file; ++i)
X {
X dir = (isdir((*file)[i]) > 0);
X if (dir < 0) /* if file doesn't exist don't add '.' */
X dir = 0;
X p = alloc((unsigned)(strlen((*file)[i]) + 1 + dir));
X if (p)
X {
X strcpy(p, (*file)[i]);
X if (dir)
X strcat(p, ".");
X }
X (*file)[i] = p;
X }
X free(buffer);
X return 0;
X}
X
X void
XFreeWild(num, file)
X int num;
X char **file;
X{
X if (file == NULL || num == 0)
X return;
X while (num--)
X free(file[num]);
X free(file);
X}
X
X int
Xhas_wildcard(p)
X char *p;
X{
X return strpbrk(p, "*#") != NULL;
X}
X
X int
Xhave_wildcard(num, file)
X int num;
X char **file;
X{
X register int i;
X
X for (i = 0; i < num; i++)
X if (has_wildcard(file[i]))
X return 1;
X return 0;
X}
END_OF_FILE
if test 13434 -ne `wc -c <'vim/src/archie.c'`; then
echo shar: \"'vim/src/archie.c'\" unpacked with wrong size!
fi
# end of 'vim/src/archie.c'
fi
if test -f 'vim/src/archie.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vim/src/archie.h'\"
else
echo shar: Extracting \"'vim/src/archie.h'\" \(285 characters\)
sed "s/^X//" >'vim/src/archie.h' <<'END_OF_FILE'
X/* vi:ts=4:sw=4
X *
X * VIM - Vi IMproved by Bram Moolenaar
X *
X * Read the file "credits.txt" for a list of people who contributed.
X * Read the file "uganda.txt" for copying and usage conditions.
X */
X
X/*
X * Archimedes Machine-dependent things
X */
X
X/*
X * sorry, this file is missing
X */
END_OF_FILE
if test 285 -ne `wc -c <'vim/src/archie.h'`; then
echo shar: \"'vim/src/archie.h'\" unpacked with wrong size!
fi
# end of 'vim/src/archie.h'
fi
echo shar: End of archive 3 \(of 26\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 26 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still must unpack the following archives:
echo " " ${MISSING}
fi
exit 0
exit 0 # Just in case...