home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume44
/
vim
/
part04
< prev
next >
Wrap
Internet Message Format
|
1994-08-16
|
71KB
From: mool@oce.nl (Bram Moolenaar)
Newsgroups: comp.sources.misc
Subject: v44i023: vim - Vi IMproved editor, v3.0, Part04/26
Date: 16 Aug 1994 21:17:29 -0500
Organization: Sterling Software
Sender: kent@sparky.sterling.com
Approved: kent@sparky.sterling.com
Message-ID: <32rrvp$kb4@sparky.sterling.com>
X-Md4-Signature: 0445d194de70481e701871c436694bd3
Submitted-by: mool@oce.nl (Bram Moolenaar)
Posting-number: Volume 44, Issue 23
Archive-name: vim/part04
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.B vim/src/termlib.c
# Wrapped by kent@sparky on Mon Aug 15 21:43:59 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 4 (of 26)."'
if test -f 'vim/doc/reference.doc.B' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vim/doc/reference.doc.B'\"
else
echo shar: Extracting \"'vim/doc/reference.doc.B'\" \(50511 characters\)
sed "s/^X//" >'vim/doc/reference.doc.B' <<'END_OF_FILE'
Xfilename"), the filename is added to the list. You can use this list to
Xremember which files you edited and to quickly switch from one file to
Xanother with the CTRL-^ command (e.g. to copy text). First type the number
Xof the file and then hit CTRL-^. {Vi: only one alternate filename}
X
XIn Ex commands (the ones that start with a colon) <%> is replaced by the
Xcurrent filename and <#> is replaced by the alternate filename. The older
Xalternate filenames are "#1", "#2", etc. "#0" is the same as "#". If a
X"<" is appended to <%>, <#> or "#n" the extension of the file name is
Xremoved (everything after and including the last '.' in the file name).
X
X % current file name
X %< current file name without extension
X # alternate file name for current window
X #< idem, without extension
X #31 alternate file number 31
X #31< idem, without extension
X
XCTRL-G or
X:f[ile] Prints the current filename (as typed) and the
X cursor position. {vi does not include column number}
X
X{count}CTRL-G Prints the current filename with full path and the
X cursor position.
X
X:f[ile] {name} Sets the current filename to {name}.
X
X:buffers
X:files List all the currently known file names. See
X 'windows.doc'. {not in vi}
X
XVim will remember the full path name of a file name that you enter. In most
Xcases when the file name is displayed only the name you typed is shown, but
Xthe full path name is being used if you used the ":cd" command.
X
XIf the environment variable 'HOME' is set, and the file name starts with
Xthat string, it is often displayed with HOME replaced by "~". This was done
Xto keep file names short. When reading or writing files the full name is
Xstill used, the "~" is only used when displaying file names.
X
XWhen writing the buffer, the default is to use the current filename. Thus
Xwhen you give the "ZZ" or ":wq" command, the original file will be
Xoverwritten. If you do not want this, the buffer can be written into another
Xfile by giving a filename argument to the ":write" command. For example:
X
X vim testfile
X [change the buffer with editor commands]
X :w newfile
X :q
X
XThis will create a file "newfile", that is a modified copy of "testfile".
XThe file "testfile" will remain unchanged. Anyway, if the 'backup' option is
Xset, Vim renames the original file before it will be overwritten. You can
Xuse this file if you discover that you need the original file. See also the
X'patchmode' option. The name of the backup file is the same as the original
Xfile with ".bak" appended. Any <.> is replaced by <_> on MSDOS machines, when
XVim has detected that an MSDOS-like filesystem is being used (e.g. messydos or
Xcrossdos) and when the 'shortname' option is set.
X
XTechnical: On the Amiga you can use 30 characters for a file name. But on an
X MSDOS-compatible filesystem only 8 plus 3 characters are
X available. Vim tries to detect the type of filesystem when it is
X creating the .swp file. If an MSDOS-like filesystem is suspected,
X a flag is set that has the same effect as setting the 'shortname'
X option. This flag will be reset as soon as you start editing a
X new file. The flag will be used when making the filename for the
X ".swp" and ".bak" files for the current file. But when you are
X editing a file in a normal filesystem and write to an MSDOS-like
X filesystem the flag will not have been set. In that case the
X creation of the ".bak" file may fail and you will get an error
X message. Use the 'shortname' option in this case.
X
XWhen you started editing without giving a file name, "No File" is displayed in
Xmessages. If a ":write file" or ":read file" command is used, the file name
Xfor the current file is set to the file name in that command. This is useful
Xwhen starting Vim without an argument and then doing ":read file" to start
Xediting a file. Or when entering text in an empty buffer and then writing it
Xto a file. Because the file name was set without really starting to edit that
Xfile, you are protected from overwriting that file. This is done by setting
Xthe "notedited" flag. You can see if this flag is set with the CTRL-G or
X":file" command. It will include "[Not edited]" when the "notedited" flag is
Xset. When writing the buffer to the current file name (with ":w!"), the
X"notedited" flag is reset.
X
XVim remembers whether you have changed the buffer. You are protected from
Xlosing the changes you made. If you try to quit without writing, or want to
Xstart editing another file, this will be refused. In order to overrule this
Xprotection add a <!> to the command. The changes will then be lost. For
Xexample: ":q" will not work if the buffer was changed, but ":q!" will. To see
Xwhether the buffer was changed use the "CTRL-G" command. The message includes
Xthe string "[Modified]" if the buffer has been changed.
X
X
X5.2 Editing a file
X
X:e[dit] [+cmd] Edit the current file, unless changes have been made.
X
X:e[dit]! [+cmd] Edit the current file always. Discard any changes to
X the buffer.
X
X:e[dit] [+cmd] {file} Edit {file}, unless changes have been made.
X
X:e[dit]! [+cmd] {file} Edit {file} always. Discard any changes to the
X buffer.
X
X:e[dit] #[count] Edit the [count]th alternate filename (as shown by
X :files). This command does the same as [count] CTRL-^.
X
X:ex [+cmd] [file] Same as :edit. {Vi: go from visual to Ex mode}
X
X:vi[sual] [+cmd] [file] Same as :edit. {Vi: go from Ex to Visual mode}
X
X[count]CTRL-^ Edit [count]th alternate file (equivalent to ":e
X #[count]"). Without count this gets you to the
X previously edited file. This is a quick way to
X toggle between two (or more) files. If the
X 'autowrite' option is set and the buffer was
X changed, write it.
X
X]f
X[f
Xgf Edit the file whose name is under or after the
X cursor. Mnemonic: "goto file". This fails if the
X current file cannot be abandoned. {not in Vi}
X
X:cd On non-Unix systems: Print the current directory
X name. On Unix systems: Change the current directory
X to the home directory.
X
X:cd {path} Change the current directory to {path}. Does not
X change the meaning of an already entered file name,
X because its full path name is remembered.
X
X:chd[ir] [path] Same as :cd.
X
X:pwd Print the current directory name. {Vi: no pwd}
X
XThese commands are used to start editing a single file. This means that the
Xfile is read into the buffer and the current filename is set. You may use the
X":cd" command to get to another directory, so you will not have to type that
Xdirectory name in front of the filenames. One warning: After using ":cd" the
Xfull path name will be used for reading and writing files. On some networked
Xfile systems this may cause problems. The result of using the full path name
Xis that the file names currently in use will remain referring to the same
Xfile. Example: If you have a file a:test and a directory a:vim the commands
X":e test" ":cd vim" ":w" will overwrite the file a:test and not write
Xa:vim/test. But if you do ":w test" the file a:vim/test will be written,
Xbecause you gave a new file name and did not refer to a file name before the
X":cd".
X
XYou can use the ":e!" command if you messed up the buffer and want to start
Xall over again. The ":e" command is only useful if you have changed the
Xcurrent filename.
X
XThe [+cmd] can be used to position the cursor in the newly opened file:
X + Start at the last line.
X +{num} Start at line {num}.
X +/{pat} Start at first line containing {pat}. {pat} must not
X contain any spaces.
X +{command} Execute {command} after opening the new file.
X {command} is an Ex command. It must not contain
X spaces.
X
XWhen reading a file when the 'textmode' option is off (default for
Xnon-MSDOS) the <LF> character is interpreted as end-of-line. If 'textmode'
Xis on (default for MSDOS), <CR><LF> is also interpreted as end-of-line.
X
XWhen writing a file when the 'textmode' option is off a <LF> character is
Xused to separate lines. When the 'textmode' option is on <CR><LF> is used.
X
XYou can read a file with 'textmode' set and write it with 'textmode' reset.
XThis will replace all <CR><LF> pairs by <LF>. If you read a file with
X'textmode' reset and write with 'textmode' set, all <LF> characters will be
Xreplaced by <CR><LF>.
X
XIf you start editing a new file and the 'textauto' option is set, Vim will
Xtry to detect whether the lines in the file are separated by a single <LF>
X(as used on Unix and Amiga) or by a <CR><LF> pair (MSDOS). It reads up to
Xthe first <LF> and checks if there is a <CR> in front of it. If there is the
X'textmode' option is set, otherwise it is reset. If the 'textmode' option is
Xset on non-MSDOS systems the message "[textmode]" is shown to remind you
Xthat something unusual is happening. On MSDOS systems you get the message
X"[notextmode]" if the 'textmode' option is not set.
X
XBefore editing binary, executable or Vim script files you should set the
X'textmode' and 'textauto' options off. With 'textmode' on you risk that
Xsingle <LF> characters are unexpectedly replaced with <CR><LF>. A simple way
Xto do this is by starting Vim with the "-b" option.
X
X
X5.3 The argument list
X
XIf you give more than one filename when starting Vim, this list is
Xremembered as the argument list. Do not confuse this with the file list,
Xwhich you can see with the ":files" command. The argument list was already
Xpresent in vi, the file list is new in Vim. The file names in the argument
Xlist will also be present in the file list (unless they were deleted with
X":bdel").
X
XYou can use the argument list with the following commands:
X
X:ar[gs] Print the argument list, with the current file in
X square brackets.
X
X:[count]argu[ment] [count] [+cmd]
X Edit file [count] in the argument list, unless
X changes have been made and the 'autowrite' option is
X off. {Vi: no such command}
X
X:[count]argu[ment]! [count] [+cmd]
X Edit file [count] in the argument list, discard any
X changes to the current buffer. {Vi: no such command}
X
X:[count]n[ext] [+cmd] Edit [count] next file, unless changes have been
X made and the 'autowrite' option is off {Vi: no
X count}.
X
X:[count]n[ext]! [+cmd] Edit [count] next file, discard any changes to the
X buffer {Vi: no count}.
X
X:ar[gs] [+cmd] {filelist}
X:n[ext] [+cmd] {filelist}
X Define {filelist} as the new argument list and edit
X the first one, unless changes have been made and the
X 'autowrite' option is off.
X
X:ar[gs]! [+cmd] {filelist}
X:n[ext]! [+cmd] {filelist}
X Define {filelist} as the new argument list and edit
X the first one. Discard any changes to the buffer.
X
X:[count]N[ext] [count] [+cmd]
X Edit [count] previous file in argument list, unless
X changes have been made and the 'autowrite' option is
X off {Vi: no count}.
X
X:[count]N[ext]! [count] [+cmd]
X Edit [count] previous file in argument list. Discard
X any changes to the buffer {Vi: no count}.
X
X:[count]pre[vious] [count] [+cmd]
X Same as :Next {Vi: only in some versions}
X
X:rew[ind] [+cmd] Start editing the first file in the argument list,
X unless changes have been made and the 'autowrite'
X option is off.
X
X:rew[ind]! [+cmd] Start editing the first file in the argument list.
X Discard any changes to the buffer.
X
X:la[st] [+cmd] Start editing the last file in the argument list, unless
X changes have been made and the 'autowrite' option is
X off. {not in Vi}
X
X:la[st]! [+cmd] Start editing the last file in the argument list.
X Discard any changes to the buffer. {not in Vi}
X
X:[count]wn[ext] [+cmd] Write current file and start editing the [count]
X next file. {not in Vi}
X
X:[count]wn[ext] [+cmd] {file}
X Write current file to {file} and start editing the
X [count] next file, unless {file} already exists and
X the 'writeany' option is off. {not in Vi}
X
X:[count]wn[ext]! [+cmd] {file}
X Write current file to {file} and start editing the
X [count] next file. {not in Vi}
X
X:[count]wN[ext][!] [+cmd] [file]
X:[count]wp[revous][!] [+cmd] [file]
X Same as :wnext, but go to previous file instead of
X next. {not in Vi}
X
XThe [count] in the commands above defaults to one. For some commands it is
Xpossible to use two counts. The last one (rightmost one) is used.
X
XFor [+cmd] see 5.2.
X
XThe wildcards in the argument list are expanded and the filenames are sorted.
XThus you can use the command "vim *.c" to edit all the C files. From within
XVim the command ":n *.c" does the same.
X
XYou are protected from leaving Vim if you are not editing the last file in
Xthe argument list. This prevents you from forgetting that you were editing one
Xout of several files. To exit anyway try to exit twice. If there are changes
Xin the current buffer this will fail. You can exit anyway, and save any
Xchanges, with the ":wq!" command. To lose any changes use the ":q!" command.
X
X
X5.4 Writing and quitting
X
X:[range]w[rite][!] Write the specified lines to the current file.
X
X:[range]w[rite] {file} Write the specified lines to {file}, unless it
X already exists and the 'writeany' option is off.
X
X:[range]w[rite]! {file} Write the specified lines to {file}. Overwrite an
X existing file.
X
X:[range]w[rite][!] >> Append the specified lines to the current file.
X
X:[range]w[rite][!] >> {file}
X Append the specified lines to {file}. <!> forces the
X write even if file does not exist.
X
X:[range]w[rite] !{cmd} Execute {cmd} with [range] lines as standard input
X (note the space in front of the <!>).
X
XThe default [range] for the ":w" command is the whole buffer (1,$).
XIf a file name is give with ":w" it becomes the alternate file. This can be
Xused when the write fails and you want to try again later with ":w #".
X
X
X:q[uit] Quit, unless changes have been made or not editing
X the last file in the argument list.
X
X:q[uit]! Quit always, without writing.
X
X:cq Quit always, without writing, and return an error
X code. Used for Manx's QuickFix mode (see 5.5).
X
X:wq Write the current file. Exit if not editing the
X last file in the argument list.
X
X:wq! Write the current file and exit.
X
X:wq {file} Write to {file}. Exit if not editing the last
X file in the argument list.
X
X:wq! {file} Write to {file} and exit.
X
X:x[it][!] [file] Like ":wq", but write only when changes have been
X made.
X
X:exi[t][!] [file] Same as :xit.
X
XZZ Write current file, if modified, and exit (same as
X ":x").
X
XIf you write to an existing file (but do not append) while the 'backup' or
X'writebackup' option is on, a backup of the original file is made. On Unix
Xsystems the file is copied, on other systems the file is renamed. After the
Xfile has been successfully written and when the 'writebackup' option is on
Xand the 'backup' option is off, the backup file is deleted.
X
X'backup' 'writebackup' action
X off off no backup made
X off on backup made, deleted afterwards
X on off backup made, not deleted
X on on backup made, not deleted (default)
X
XOn Unix systems:
XWhen you write to an existing file, that file is truncated and then filled
Xwith the new text. This means that protection bits, owner and symbolic links
Xare unmodified. The backup file however, is a new file, owned by the user
Xwho edited the file. If it is not possible to create the backup file in the
Xsame directory as the original file, the directory given with the
X'backupdir' option is used (default: home directory).
X
XIf the creation of a backup file fails, the write is not done. If you want
Xto write anyway add a <!> to the command.
X
XIf the 'textmode' option is set <CR><LF> is used for end-of-line. This is
Xdefault for MSDOS. On other systems the message "[textmode]" is shown to
Xremind you that an usual end-of-line marker was used. If the 'textmode' is
Xnot set LF is used for end-of-line. On MSDOS the message "[notextmode]" is
Xshown. See also the 'textmode' and 'textauto' options.
X
X
X5.5 Using the QuickFix mode
X
XVim has a special mode to speedup the edit-compile-edit cycle. This is
Xinspired by the quickfix option of the Manx's Aztec C compiler on the Amiga.
XThe idea is to save the error messages from the compiler in a file and use
XVim to jump to the errors one by one. You can then examine each problem and
Xfix it, without having to remember all the error messages.
X
XIf you are using Manx's Aztec C compiler on the Amiga you should do the
Xfollowing:
X- Set the CCEDIT environment variable with the command
X mset "CCEDIT=vim -e"
X- Compile with the -qf option. If the compiler finds any errors, Vim is
X started and the cursor is positioned on the first error. The error message
X will be displayed on the last line. You can go to other errors with the
X commands mentioned below. You can fix the errors and write the file(s).
X- If you exit Vim normally the compiler will re-compile the same file. If you
X exit with the :cq command, the compiler will terminate. Do this if you
X cannot fix the error, or if another file needs to be compiled first.
X
XIf you are using another compiler you should save the error messages in a
Xfile and start Vim with "vim -e filename". An easy way to do this is with
Xthe ":make" command (see below). The 'errorformat' option should be set to
Xmatch the error messages from your compiler (see below).
X
XThe following commands can be used if you are in QuickFix mode:
X
X:cc [nr] Display error [nr]. If [nr] is omitted, the same
X error is displayed again. {not in Vi}
X
X:[count]cn Display the [count] next error in the list that
X includes a file name. If there are no file names at
X all, go the the [count] next error. {not in Vi}
X
X:[count]cp Display the [count] previous error in the list that
X includes a file name. If there are no file names at
X all, go the the [count] previous error. {not in Vi}
X
X:cq Quit Vim with an error code, so that the compiler
X will not compile the same file again. {not in Vi}
X
X:cf [errorfile] Read the error file and jump to the first error.
X This is done automatically when Vim is started with
X the -e option. You can use this command when you
X keep Vim running while compiling. If you give the
X name of the errorfile, the 'errorfile' option will
X be set to [errorfile] {not in Vi}
X
X:cl List all errors. {not in Vi}
X
X:make [arguments] 1. If the 'autowrite' option is set and the buffer
X was changed, write it.
X 2. Any existing 'errorfile' is deleted.
X 3. The program given with the 'makeprg' option is
X started (default "make") with the optional
X [arguments] and the output is saved in
X 'errorfile' (for Unix it is also echoed on the
X screen).
X 4. The 'errorfile' is then read and the first error
X is jumped to.
X 5. The 'errorfile' is deleted.
X {not in Vi}
X
XThe name of the file can be set with the 'errorfile' option. The default is
X"AztecC.Err" for the Amiga and "errors" for other systems. The format of the
Xfile from the Aztec compiler is:
X
X filename>linenumber:columnnumber:errortype:errornumber:errormessage
X
X filename name of the file in which the error was detected
X linenumber line number where the error was detected
X columnnumber column number where the error was detected
X errortype type of the error, normally a single <E> or <W>
X errornumber number of the error (for lookup in the manual)
X errormessage description of the error
X
XAnother compiler is likely to use a different format. You should set the
X'errorformat' option to a scanf-like string that describes the format. First
Xyou need to know how scanf works. Look in the documentation of your C
Xcompiler. Vim will understand eight conversion characters. Others are invalid.
X %f file name (finds a string)
X %l line number (finds a number)
X %c column number (finds a number)
X %t error type (finds a single character)
X %n error number (finds a number)
X %m error message (finds a string)
X %*<conv> any scanf non-assignable conversion
X %% the single <%> character
X
XExamples:
X"%f>%l:%c:%t:%n:%m" for the AztecC.Err file
X"%f:%l:\ %t%*[^0123456789]%n:\ %m" for Aztec C error messages
X"%f\ %l\ %t%*[^0123456789]%n:\ %m" for SAS C
X"\"%f\",%*[^0123456789]%l:\ %m" default for generic C compilers
X"%f:%l:%m" for GCC
X
XNote the backslash in front of a space and double quote. It is required for
Xthe :set command.
X
XThe "%f" and "%m" conversions have to detect the end of the string. They
Xshould be followed by a character that cannot be in the string. Everything
Xup to that character is included in the string. Be careful: "%f%l" will
Xinclude everything up to the first <%> in the file name. If the "%f" or "%m"
Xis at the end, everything up to the end of the line is included.
X
XIf a line is detected that does not completely match the 'errorformat', the
Xwhole line is put in the error message and the entry is marked "not valid"
XThese lines are skipped with the ":cn" and ":cp" commands (unless there is
Xno valid line at all). You can use ":cl" to display all the error messages.
X
XIf the error format does not contain a file name Vim cannot switch to the
Xcorrect file. You will have to do this by hand.
X
XIf you have a compiler that produces error messages that do not fit in the
Xformat string, you could write a program that translates the error messages
Xinto this format. You can use this program with the ":make" command by
Xchanging the 'makeprg' option. For example:
X ":set mp=make\ \\\|&\ error_filter".
XThe backslashes before the pipe character are required to avoid it to be
Xrecognized as a command separator. The backslash before each space is
Xrequired for the set command.
X
XThe ":make" command executes the command given with the 'makeprg' option.
XThis is done by passing the command to the shell given with the 'shell'
Xoption. This works almost like typing
X
X ":!{makeprg} [arguments] {shellpipe} {errorfile}".
X
X{makeprg} is the string given with the 'makeprg' option. Any command can be
Xused, not just "make". Characters <%> and <#> are expanded as usual on a
Xcommand line. You can use "#<" to insert the current filename without
Xextension, for example ":set makeprg=make\ #<.o".
X
X[arguments] is anything that is typed after ":make".
X{shellpipe} is the 'shellpipe' option.
X{errorfile} is the 'errorfile' option.
X
XThe 'shellpipe' option defaults to ">" for the Amiga and MSDOS. This means
Xthat the output of the compiler is saved in a file and not shown on the
Xscreen directly. For Unix "| tee" is used. The compiler output is shown on
Xthe screen and saved in a file the same time. Depending on the shell used
X"|& tee" or "2>&1| tee" is the default, so stderr output will be included.
X
XThere are some restrictions to the Quickfix mode on the Amiga. The
Xcompiler only writes the first 25 errors to the errorfile (Manx's
Xdocumentation does not say how to get more). If you want to find the others,
Xyou will have to fix a few errors and exit the editor. After recompiling,
Xup to 25 remaining errors will be found.
X
XOn the Amiga, if Vim was started from the compiler, the :sh and :! commands
Xwill not work, because Vim is then running in the same process as the
Xcompiler and these two commands may guru the machine then.
X
XIf you insert or delete lines, mostly the correct error location is still
Xfound because hidden marks are used (Manx's Z editor does not do this).
XSometimes, when the mark has been deleted for some reason, the message "line
Xchanged" is shown to warn you that the error location may not be correct. If
Xyou quit Vim and start again the marks are lost and the error locations may
Xnot be correct anymore.
X
X
X5.6 Editing binary files
X
XAlthough Vim was made to edit text files, it is possible to edit binary
Xfiles. The "-b" command line option (b for binary) sets some options for
Xediting binary files ('binary' on, 'textwidth' to 0, 'textmode' and
X'textauto' off, 'modelines' to 0, 'expandtab' off). Setting the 'binary'
Xoption has the same effect. Don't forget to do this before reading the file.
X
XThere are a few things to remember when editing binary files:
X- When editing executable files the number of characters must not change.
X Use only the "R" or "r" command to change text. Do not delete characters
X with "x" or by backspacing.
X- Set the 'textwidth' option to 0. Otherwise lines will unexpectedly be
X split in two.
X- When there are not many end-of-line characters, the lines will become very
X long. If you want to edit a line that does not fit on the screen reset the
X 'wrap' option. Horizontal scrolling is used then. If a line becomes too
X long (more than about 32767 characters on the Amiga, much more on 32-bit
X systems) you cannot edit that line. The line will be split when reading
X the file. It is also possible that you get an "out of memory" error when
X reading the file.
X- Make sure the 'textmode' and 'textauto' options are off before loading the
X file. In 'textmode' both <CR><LF> and <LF> are considered to end a line
X and when the file is written the <LF> will be replaced by <CR><LF>. The
X 'modelines' option should also be off, because there may be a string like
X ":vi:" in the file that would give unpredictable results.
X- <NUL> characters are shown on the screen as ^@. You can enter them with
X "CTRL-V CTRL-@" or "CTRL-V 000" {vi cannot handle <NUL> characters in the
X file}
X- To insert a <LF> character in the file split up a line. When writing the
X buffer to a file a <LF> will be written for the end of line.
X- Vim normally appends an end-of-line character at the end of the file if
X there is none. Setting the 'binary' option prevents this. If you want to
X add the final end-of-line, set the 'endofline' option. You can also read the
X value of this option to see if there was an end-of-line character for the
X last line (you cannot see this in the text).
X
X
X 6. Cursor motions
X
XThese commands move the cursor position. If the new position is off of the
Xscreen, the screen is scrolled to show the cursor (see also 'scrolljump'
Xoption).
X
XThe motion commands can be used after other commands, called operators, to
Xhave the command operate on the text that was moved over. That is the text
Xbetween the cursor position before and after the motion. If the motion
Xincludes a count and the operator also had a count, the two counts are
Xmultiplied. For example: "2d3w" deletes six words.
X The operator either affects whole lines, or the characters between
Xthe start and end position. Generally, motions that move between lines
Xaffect lines (are linewise), and motions that move within a line affect
Xcharacters. However, there are some exceptions.
X A character motion is either inclusive or exclusive. When inclusive,
Xthe start and end position of the motion are included in the operation.
XWhen exclusive, the last character towards the end of the buffer is not
Xincluded. Linewise motions always include the start and end position.
X Which motions are linewise, inclusive or exclusive is mentioned
Xbelow. There are however, two general exceptions:
X1. If the motion is exclusive and the end of the motion is in column 1, the
X end of the motion is moved to the end of the previous line and the motion
X becomes inclusive. Example: "}" ends at the first line after a paragraph,
X but "V}" will not include that line.
X2. If the motion is exclusive, the end of the motion is in column 1 and the
X start of the motion was at or before the first non-blank in the line, the
X motion becomes linewise. Example: If a paragraph begins with some blanks
X and you do "d}" while standing on the first non-blank, all the lines of
X the paragraph are deleted, including the blanks. If you do a put now, the
X deleted lines will be inserted below the cursor position.
X
XInstead of first giving the operator and then a motion you can use Visual
Xmode: mark the start of the text with <v>, move the cursor to the end of the
Xtext that is to be affected and then hit the operator. The text between the
Xstart and the cursor position is highlighted, so you can see what text will
Xbe operated upon. This allows much more freedom, but requires more key
Xstrokes and has limited redo functionality. See the chapter on Visual mode.
X
XIf you want to know where you are in the file use the "CTRL-G" command. If
Xyou set the 'ruler' option, the cursor position is continuously shown in the
Xstatus line (which slows down Vim a little).
X
XNOTE: Experienced users prefer the hjkl keys because they are always right
Xunder their fingers. Beginners often prefer the arrow keys, because they
Xdo not know what the hjkl keys do. The mnemonic value of hjkl is clear from
Xlooking at the keyboard. Think of j as an arrow pointing downwards.
X
X6.1 Left-right motions
X
Xh or
X<C_LEFT> or
XCTRL-H or
X<BS> [count] characters to the left (exclusive).
X
Xl or
X<C_RIGHT> or
X<SPACE> [count] characters to the right (exclusive).
X
X0 To the first character of the line (exclusive).
X
X^ To the first non-blank character of the line
X (exclusive).
X
X$ To the end of line [count] from the cursor
X (inclusive).
X
X| To column [count] (inclusive).
X
Xf<char> To [count]'th occurrence of <char> to the right. The
X cursor is placed on <char> (inclusive).
X
XF<char> To the [count]'th occurrence of <char> to the left.
X The cursor is placed on <char> (inclusive).
X
Xt<char> Till before [count]'th occurrence of <char> to the
X right. The cursor is placed on the character left of
X <char> (inclusive).
X
XT<char> Till after [count]'th occurrence of <char> to the
X left. The cursor is placed on the character right of
X <char> (inclusive).
X
X; Repeat latest f, t, F or T [count] times.
X
X, Repeat latest f, t, F or T in opposite direction
X [count] times.
X
XThese commands move the cursor to the specified column in the current line.
XThey stop at the first column and at the end of the line, except "$", which
Xmay move to one of the next lines.
X
X
X6.2 Up-down motions
X
Xk or
X<C_UP> or
XCTRL-P [count] lines upward (linewise).
X
Xj or
X<C_DOWN> or
XCTRL-J or
X<LF> or
XCTRL-N [count] lines downward (linewise).
X
X- <minus> [count] lines upward, on the first non-blank
X character (linewise).
X
X+ or
XCTRL-M or
X<CR> [count] lines downward, on the first non-blank
X character (linewise).
X
X_ <underscore> [count] - 1 lines downward, on the first non-blank
X character (linewise).
X
XG Goto line [count], default last line, on the first
X non-blank character (linewise).
X
X:[range] Set the cursor on the (last) specified line number
X (cannot be used with an operator).
X
X{count}% Go to {count} percentage in the file, on the first
X non-blank in the line (linewise). To compute the new
X line number this formula is used: {count} *
X number-of-lines / 100. {not in Vi}
X
XThese commands move to the specified line. They stop when reaching the first
Xor the last line. The first two commands put the cursor in the same column
X(if possible) as it was after the last command that changed the column,
Xexcept after the "$" command, then the cursor will be put on the last
Xcharacter of the line.
X
X
X6.3 Word motions
X
X<SC_RIGHT> or
Xw [count] words forward (exclusive).
X
XW [count] WORDS forward (exclusive).
X
Xe Forward to the end of word [count] (inclusive).
X
XE Forward to the end of WORD [count] (inclusive).
X
X<SC_LEFT> or
Xb [count] words backward (exclusive).
X
XB [count] WORDS backward (exclusive).
X
XThese commands move over words or WORDS. A word consists of a sequence of
Xletters, digits and underscores, or a sequence of other non-blank
Xcharacters, separated with white space (spaces, tabs, end of line). A WORD
Xconsists of a sequence of non-blank characters, separated with white space.
XAn empty line is also considered to be a word and a WORD.
X
XSpecial case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is
Xon a non-blank. This is because "cw" is interpreted as change-word, and a
Xword does not include the following white space. {Vi: "cw" when on a blank
Xfollowed by other blanks changes only the first blank; this is probably a
Xbug, because "dw" deletes all the blanks}
X
XAnother special case: When using the "w" motion in combination with an
Xoperator and the last word moved over is at the end of a line, the end of
Xthat word becomes the end of the operated text, not the first word in the
Xnext line.
X
XThe original vi implementation of "e" is buggy. For example, the "e" command
Xwill stop on the first character of a line if the previous line was empty.
XBut when you use "2e" this does not happen. In Vim "ee" and "2e" are the
Xsame, which is more logical. However, this causes a small incompatibility
Xbetween vi and Vim.
X
X
X6.4 Text object motions
X
X( [count] sentences backward (exclusive).
X
X) [count] sentences forward (exclusive).
X
X{ [count] paragraphs backward (exclusive).
X
X} [count] paragraphs forward (exclusive).
X
X]] [count] sections forward or to the next <{> in the
X first column. When used after an operator, then the
X <}> in the first column. (linewise).
X
X][ [count] sections forward or to the next <}> in the
X first column (linewise).
X
X[[ [count] sections backward or to the previous <{> in
X the first column (linewise).
X
X[] [count] sections backward or to the previous <}> in
X the first column (linewise).
X
XThese commands move over three kinds of text objects.
X
XA sentence is defined as ending at a <.>, <!> or <?> followed by either the
Xend of a line, or by a space. {Vi: two spaces} Any number of closing <)>,
X<]>, <"> and <'> characters my appear after the <.>, <!> or <?> before the
Xspaces or end of line. A paragraph and section boundary is also a sentence
Xboundary.
X
XA paragraph begins after each empty line, and also at each of a set of
Xparagraph macros, specified by the pairs of characters in the 'paragraphs'
Xoption. The default is "IPLPPPQPP LIpplpipbp", which corresponds to the
Xmacros ".IP", ".LP", etc. (these are nroff macros, the dot must be in the
Xfirst column). A section boundary is also a paragraph boundary. Note that
Xthis does not include a <{> or <}> in the first column.
X
XA section begins after a form-feed in the first column and at each of a set
Xof section macros, specified by the pairs of characters in the 'sections'
Xoption. The default is "SHNHH HUnhsh".
X
XThe "]" and "[" commands stop at the <{> or <}" in the first column. This is
Xuseful to find the start or end of a function in a C program. Note that the
Xfirst character of the command determines the search direction and the
Xsecond character the type of brace found.
X
X
X6.5 Pattern searches
X
X/{pattern}[/] Search forward for the [count]'th occurrence of
X {pattern} (exclusive).
X
X/{pattern}/{offset} Search forward for the [count]'th occurrence of
X {pattern} and go {offset} lines up or down (see
X below). (linewise).
X
X/ Search forward for the [count]'th latest used
X pattern with latest used {offset}.
X
X//{offset} Search forward for the [count]'th latest used
X pattern with new {offset}. If {offset} is empty no
X offset is used.
X
X* Search forward for the [count]'th occurrence of the
X ident after or under the cursor (exclusive). Only
X whole words are search for, like with the command
X "/\<indent\>". If there is no identifier after or
X under the cursor, any non-blank word is used to
X search for. {not in Vi}
X
X# Same as "*", but search backward. {not in Vi}
X
X?{pattern}[?] Search backward for the [count]'th previous
X occurrence of {pattern} (exclusive).
X
X?{pattern}?{offset} Search backward for the [count]'th previous
X occurrence of {pattern} and go {offset} lines up or
X down (see below) (linewise).
X
X? Search backward for the [count]'th latest used
X pattern with latest used {offset}.
X
X??{offset} Search backward for the [count]'th latest used
X pattern with new {offset}. If {offset} is empty no
X offset is used.
X
Xn Repeat the latest "/" or "?" [count] times. {Vi: no
X count}
X
XN Repeat the latest "/" or "?" [count] times in
X opposite direction. {Vi: no count}
X
XCTRL-C Interrupt current (search) command.
X
XThese commands search for the specified pattern. With "/" and "?" an
Xadditional offset may be given. There are two types of offsets: line offsets
Xand character offsets. {the character offsets are not in Vi}
X
XThe offset gives the cursor position relative to the found match:
X [num] [num] lines downwards, in column 1
X +[num] [num] lines downwards, in column 1
X -[num] [num] lines upwards, in column 1
X e[+num] [num] characters to the right of the end of the match
X e[-num] [num] characters to the left of the end of the match
X s[+num] [num] characters to the right of the start of the match
X s[-num] [num] characters to the left of the start of the match
X b[+num] [num] characters to the right of the start (begin) of the match
X b[-num] [num] characters to the left of the start (begin) of the match
X
XIf a <-> or <+> is given but [num] is omitted, a count of one will be used.
XWhen including an offset with 'e', the search becomes inclusive (the
Xcharacter the cursor lands on is included in operations).
X
XExamples:
X
Xpattern cursor position
X/test/+1 one line below "test", in column 1
X/test/e on the last t of "test"
X/test/s+2 on the <s> of "test"
X/test/b-3 three characters before "test"
X
XIf one of these commands is used after an operator, the characters between
Xthe cursor position before and after the search is affected. However, if a
Xline offset is given, the whole lines between the two cursor positions are
Xaffected.
X
XThe last used <pattern> and <offset> are remembered. They can be used to
Xrepeat the search, possibly in another direction or with another count. Note
Xthat two patterns are remembered: one for 'normal' search commands and one
Xfor the substitute command ":s". Each time an empty <pattern> is given, the
Xpreviously used <pattern> is used.
X
X{In vi the :tag command sets a new search pattern when the tag is searched
Xfor. In Vim this is not done, the previous search pattern is still
Xremembered}.
X
XIf the 'wrapscan' option is set (which is the default), searches wrap around
Xthe end of the buffer. If 'wrapscan' is not set, the backward search stops
Xat the beginning and the forward search stops at the end of the buffer. If
X'wrapscan' is set and the pattern was not found the error message "pattern
Xnot found" is given, and the cursor will not be moved. If 'wrapscan' is not
Xset the message becomes "search hit BOTTOM without match" when searching
Xforward, or "search hit TOP without match" when searching backward. If
Xwrapscan is set and the search wraps around the end of the file the message
X"search hit TOP, continuing at BOTTOM" or "search hit BOTTOM, continuing at
XTOP" is given when searching backwards or forwards respectively.
X
XThe "*" and "#" commands search for the identifier currently under the
Xcursor. If there is no identifier under the cursor, the first one to the
Xright is used. This identifier may only contain letters, digits and
Xunderscores. Note that if you type with ten fingers, the characters are easy
Xto remember: the "#" is under your left hand middle finger (search to the
Xleft and up) and the "*" is under your right hand middle finger (search to
Xthe right and down). If there is no identifier under or after the cursor, a
Xsearch is done for any word under or after the cursor. Blanks (<TAB>s and/or
X<SPACE>s) are recognized as delimiters for this word.
X
X
XThe definition of a pattern:
X
XPatterns may contain special characters, depending on the setting of the
X'magic' option.
X
X1. A pattern is one or more branches, separated by '\|'. It matches anything
X that matches one of the branches. Example: "foo\|bar" matches "foo" and
X "bar.
X
X2. A branch is one or more pieces, concatenated. It matches a match for the
X first, followed by a match for the second, etc. Example: "foo[0-9]bar",
X first match "foo", then a digit and then "bar".
X
X3. A piece is an atom, possibly followed by:
X 'magic' 'nomagic'
X option option
X * \* matches 0 or more of the preceding atom
X \+ \+ matches 1 or more of the preceding atom {not
X in Vi}
X \= \= matches 0 or 1 of the preceding atom {not in
X Vi}
X Examples:
X .* .\* match anything, also empty string
X .\+ .\+ match any non-empty string
X foo\= foo\= match "fo" and "foo"
X
X
X4. An atom can be:
X - One of these five:
X magic nomagic
X . \. matches any single character
X \< \< matches the beginning of a word
X \> \> matches the end of a word
X ^ ^ at beginning of pattern, matches start of
X line
X $ $ at end of pattern or in front of '\|',
X matches end of line
X - A pattern enclosed by escaped parentheses (e.g. "\(^a\)").
X - A single character, with no special meaning, matches itself
X - A backslash followed by a single character, with no special meaning,
X matches the single character.
X - A range. This is a sequence of characters enclosed in '[]' with the
X 'magic' option, or enclosed in '\[]' with the 'nomagic' option. It
X normally matches any single character from the sequence. If the
X sequence begins with <^>, it matches any single character NOT in the
X sequence. If two characters in the sequence are separated by <->, this
X is shorthand for the full list of ASCII characters between them (e.g.
X '[0-9]' matches any decimal digit). To include a literal <]> in the
X sequence, make it the first character (following a possible <^>). To
X include a literal '\-', make it the first or last character.
X
XIf the 'ignorecase' option is set, the case of letters is ignored.
X
XIt is impossible to have a pattern that contains a line break.
X
XExamples:
X^beep( Probably the start of the C function "beep".
X
X[a-zA-Z]$ Any alphabetic character at the end of a line.
X
X\(^\|[^a-zA-Z0-9_]\)[a-zA-Z_]\+[a-zA-Z0-9_]*
X A C identifier (will stop in front of it).
X
X\(\.$\|\. \) A period followed by end-of-line or a space.
X Note that "\(\. \|\.$\)" does not do the same,
X because '$' is not end-of-line in front of '\)'.
X This was done to remain vi-compatible.
X
X[.!?][])"']*\($\|[ ]\) A search pattern that finds the end of a sentence,
X with almost the same definition as the <)> command.
X
XTechnical detail:
X<NUL> characters in the file are stored as <LF> in memory. In the display
Xthey are shown as "^@". The translation is done when reading and writing
Xfiles. To match a <NUL> with a search pattern you can just enter CTRL-@ or
X"CTRL-V 000". This is probably just what you expect. Internally the
Xcharacter is replaced by a <LF> in the search pattern. What is unusual is
Xthat typing CTRL_V CTRL_J also inserts a <LF>, thus also searches for a
X<NUL> in the file. {vi cannot handle <NUL> characters in the file at all}
X
X
X6.6 Various motions
X
Xm<a-zA-Z> Set mark <a-zA-Z> at cursor position (does not move
X the cursor, this is not a motion command).
X
X:[range]mar[k] <a-zA-Z> Set mark <a-zA-Z> at last line number in [range],
X column 0. Default is cursor line.
X
X:[range]k<a-zA-Z> Same as :mark, but the space before the mark name can
X be omitted.
X
X'<a-z> To the first non-blank character on the line with
X mark <a-z> (linewise).
X
X'<A-Z> To the first non-blank character on the line with
X mark <A-Z> in the correct file (linewise when in
X same file, not a motion command when in other file).
X {not in Vi}
X
X`<a-z> To the mark <a-z> (exclusive).
X
X`<A-Z> To the mark <A-Z> in the correct file (exclusive
X when in same file, not a motion command when in
X other file). {not in Vi}
X
X:marks List the current marks (not a motion command). {not
X in Vi}
X
XA mark is not visible in any way. It is just a position in the file that is
Xremembered. Do not confuse marks with named registers, they are totally
Xunrelated.
X
XLowercase marks are only remembered as long as the file remains loaded. If
Xyou quit editing the file, change a character in a line or delete a line
Xthat contains a mark, that mark is erased. Lowercase marks can be used
Xin combination with operators. For example: "d't" deletes the lines from the
Xcursor position to mark <t>. Hint: Use mark <t> for Top, <b> for Bottom,
Xetc..
X
XMarks are restored when using undo and redo.
X
XMarks are remembered as long as the file remains in the buffer list.
X
XUppercase marks include the file name. {Vi: no uppercase marks} You can use
Xthem to jump from file to file. You can only use an uppercase mark with
Xan operator if the mark is in the current file. The line number of the mark
Xremains correct, even if you insert/delete lines or edit another file for a
Xmoment.
X
X
X'[ To the first non-blank character on the first line
X of the previously operated text or start of the last
X putted text. {not in Vi}
X
X`[ To the first character of the previously operated
X text or start of the last putted text. {not in Vi}
X
X'] To the first non-blank character on the last line of
X the previously operated text or end of the last
X putted text. {not in Vi}
X
X`] To the last character of the previously operated
X text or end of the last putted text. {not in Vi}
X
XAfter executing an operator the Cursor is put at the beginning of the text
Xthat was operated upon. After a put command ("p" or "P") the cursor is
Xsometimes placed at the first inserted line and sometimes on the last
Xinserted character. The four commands above put the cursor at either
Xend. Example: After yanking 10 lines you want to go to the last one of them:
X"10Y']". After inserting several lines with the "p" command you want to jump
Xto the lowest inserted line: "p']".
X
XNote: After deleting text, the start and end positions are the same, except
Xwhen using blockwise Visual mode. These commands do not work when no
Xoperator or put command has been used yet in the current file. The position
Xmay be incorrect after inserting text and ".p.
X
X
X'' To the first non-blank character of the line where
X the cursor was before the latest jump (linewise).
X
X`` To the position before latest jump (exclusive).
X
XA "jump" is one of the following commands: "'", "`", "G", "/", "?", "n",
X"N", "%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and
Xthe commands that start editing a new file. If you make the cursor "jump"
Xwith one of these commands, the position of the cursor before the jump is
Xremembered. You can return to that position with the "''" and "``" command,
Xunless the line containing that position was changed or deleted.
X
XCTRL-O Go to [count] Older cursor position in jump list
X (not a motion command). {not in Vi}
X
XCTRL-I Go to [count] newer cursor position in jump list
X (not a motion command). {not in Vi}
X
X:jumps Print the jump list (not a motion command). {not in
X Vi}
X
XJumps are remembered in a jump list. With the CTRL-O and CTRL-I command you
Xcan go to cursor positions before older jumps, and back again. Thus you can
Xmove up and down the list.
X
XFor example, after three jump commands you have this jump list:
X
X jump line file
X 1 1 -current-
X 2 70 -current-
X 3 1154 -current-
X>
X
XYou are currently in line 1167. If you then use the CTRL-O command, the
Xcursor is put in line 1154. This results in:
X
X jump line file
X 1 1 -current-
X 2 70 -current-
X> 3 1154 -current-
X 4 1167 -current-
X
XThe pointer will be set at the last used jump position. The next CTRL-O
Xcommand will use the entry above it, the next CTRL-I command will use the
Xentry below it. If the pointer is below the last entry, this indicates that
Xyou did not use a CTRL-I or CTRL-O before. In this case the CTRL-O command
Xwill cause the cursor position to be added to the jump list, so you can get
Xback to the position before the CTRL-O. In this case this is line 1167.
X
XWith more CTRL-O commands you will go to lines 70 and 1. If you use CTRL-I
Xyou can go back to 1154 and 1167 again.
X
XIf you use a jump command, the current line number is inserted at the end of
Xthe jump list. If you used CTRL-O or CTRL-I just before that, the same line
Xmay be in the list twice. This may be a bit strange. Just try it and look at
Xthe jump list with the :jumps command. Note that this behaviour is different
Xfrom the tag stack.
X
XAfter the CTRL-O command that got you into line 1154 you could give another
Xjump command (e.g. "G"). The jump list would then become:
X
X jump line file
X 1 1 -current-
X 2 70 -current-
X 3 1154 -current-
X 4 1167 -current-
X 5 1154 -current-
X>
X
XAs long as you stay in the same file, the line numbers will be adjusted for
Xdeleted and inserted lines. If you go to another file the line numbers may
Xbe wrong (keeping them correct would take too much time). If you want to
Xavoid this use a :jumps command before changing files. This will update the
Xline numbers in the current file.
X
X% Find the next item in this line after or under the
X cursor and jump to its match (inclusive). Items can
X be:
X ([{}]) parenthesis or (curly/square) brackets
X /* */ start or end of C-style comment
X #if, #ifdef, #else, #elif, #endif
X C preprocessor conditionals
X Parens and braces preceded with a backslash are
X ignored. Parens and braces inside quotes are ignored,
X unless the number of parens/braces in a line is uneven
X and this line and the previous one does not end in a
X backslash. No count is allowed ({count}% jumps to a
X line {count} percentage down the file).
X Using '%' on #if/#else/#endif makes the movement
X linewise.
X
X[( go to [count] previous unmatched <(>. {not in Vi}
X
X[{ go to [count] previous unmatched <{>. {not in Vi}
X
X]) go to [count] next unmatched <)>. {not in Vi}
X
X]} go to [count] next unmatched <}>. {not in Vi}
X
XThe above four commands can be used to go to the start or end of the current
Xcode block. It is like doing "%" on the <(>, <)>, <{> or <}> at the other
Xend of the code block, but you can do this from anywhere in the code block.
XVery useful for C programs. Example: When standing on "case x:", "[{" will
Xbring you back to the switch statement.
X
XH To line [count] from top (Home) of screen (default:
X first line on the screen) on the first non-blank
X character (linewise).
X
XM To Middle line of screen, on the first non-blank
X character (linewise).
X
XL To line [count] from bottom of screen (default: Last
X line on the screen) on the first non-blank character
X (linewise).
X
X
X 7. Scrolling
X
XMove edit window downwards (this means that more lines downwards in the text
Xbuffer are seen):
X
XCTRL-E Window [count] lines downwards in the buffer
X
XCTRL-D Window Downwards in the buffer. The number of lines
X comes from the 'scroll' option (default: half a
X screen). If [count] given, first set 'scroll' option
X to [count].
X
X<SC_DOWN> or
XCTRL-F Window [count] pages Forwards (downwards) in the
X buffer.
X
XMove edit window upwards (this means that more lines upwards in the text
Xbuffer are seen):
X
XCTRL-Y Window [count] lines upwards in the buffer.
X
XCTRL-U Window Upwards in the buffer. The number of lines
END_OF_FILE
if test 50511 -ne `wc -c <'vim/doc/reference.doc.B'`; then
echo shar: \"'vim/doc/reference.doc.B'\" unpacked with wrong size!
elif test -f 'vim/doc/reference.doc.A' && 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.B'
fi
if test -f 'vim/src/termlib.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vim/src/termlib.c'\"
else
echo shar: Extracting \"'vim/src/termlib.c'\" \(15559 characters\)
sed "s/^X//" >'vim/src/termlib.c' <<'END_OF_FILE'
X/* vi:sw=4:ts=4:
X The following software is (C) 1984 Peter da Silva,
X the Mad Australian, in the public domain. It may
X be re-distributed for any purpose with the inclusion
X of this notice. */
X
X/* modified by Bram Moolenaar for use with VIM - Vi Improved */
X
X/* TERMLIB: Terminal independant database. */
X
X#include "vim.h"
X#include "proto.h"
X#include "proto/termlib.pro"
X
X#ifndef AMIGA
X# include <sgtty.h>
X#endif
X
Xstatic int getent __PARMS((char *, char *, FILE *, int));
Xstatic int nextent __PARMS((char *, FILE *, int));
Xstatic int _match __PARMS((char *, char *));
Xstatic char *_addfmt __PARMS((char *, char *, int));
Xstatic char *_find __PARMS((char *, char *));
X
X/*
X * Global variables for termlib
X */
X
Xchar *tent; /* Pointer to terminal entry, set by tgetent */
Xchar PC = 0; /* Pad character, default NULL */
Xchar *UP = 0, *BC = 0; /* Pointers to UP and BC strings from database */
Xshort ospeed; /* Baud rate (1-16, 1=300, 16=19200), as in stty */
X
X/*
X * Module: tgetent
X *
X * Purpose: Get termcap entry for <term> into buffer at <tbuf>.
X *
X * Calling conventions: char tbuf[TBUFSZ+], term=canonical name for
X * terminal.
X *
X * Returned values: 1 = success, -1 = can't open file,
X * 0 = can't find terminal.
X *
X * Notes
X * Should probably supply static buffer.
X *
X * Uses environment variables "TERM" and
X * "TERMCAP". If TERM = term (that is, if the argument
X * matches the environment) then it looks at TERMCAP.
X * If TERMCAP begins with a slash, then it assumes
X * this is the file to search rather than /etc/termcap.
X * If TERMCAP does not begin with a slash, and it
X * matches TERM, then this is used as the entry.
X *
X * This could be simplified considerably for non-UNIX
X * systems.
X */
X
X#ifdef AMIGA
X# define TERMCAPFILE "s:termcap"
X#else
X# define TERMCAPFILE "/etc/termcap"
X#endif
X
Xtgetent(tbuf, term)
X char *tbuf; /* Buffer to hold termcap entry, TBUFSZ bytes max */
X char *term; /* Name of terminal */
X{
X char tcbuf[32]; /* Temp buffer to handle */
X char *tcptr = tcbuf; /* extended entries */
X char *tcap = TERMCAPFILE; /* Default termcap file */
X char *tmp;
X FILE *termcap;
X int retval = 0;
X int len;
X
X if ((tmp = (char *)vimgetenv("TERMCAP")) != NULL)
X {
X if (*tmp == '/') /* TERMCAP = name of termcap file */
X tcap = tmp ;
X else /* TERMCAP = termcap entry itself */
X {
X int tlen = strlen(term);
X
X while (*tmp && *tmp != ':') /* Check if TERM matches */
X {
X while (*tmp == '|')
X tmp++;
X if (_match(tmp, term) == tlen)
X {
X strcpy(tbuf, tmp);
X tent = tbuf;
X return 1;
X }
X else
X tmp = _find(tmp, ":|");
X }
X }
X }
X if (!(termcap = fopen(tcap, "r")))
X {
X strcpy(tbuf, tcap);
X return -1;
X }
X
X len = 0;
X while (getent(tbuf + len, term, termcap, TBUFSZ - len))
X {
X if ((term = tgetstr("tc", &tcptr))) /* extended entry */
X {
X rewind(termcap);
X len = strlen(tbuf);
X }
X else
X {
X retval = 1;
X tent = tbuf;
X break;
X }
X }
X fclose(termcap);
X return retval;
X}
X
X static int
Xgetent(tbuf, term, termcap, buflen)
X char *tbuf, *term;
X FILE *termcap;
X int buflen;
X{
X char *tptr;
X int tlen = strlen(term);
X
X while (nextent(tbuf, termcap, buflen)) /* For each possible entry */
X {
X tptr = tbuf;
X while (*tptr && *tptr != ':') /* : terminates name field */
X {
X while (*tptr == '|') /* | seperates names */
X tptr++;
X if (_match(tptr, term) == tlen) /* FOUND! */
X {
X tent = tbuf;
X return 1;
X }
X else /* Look for next name */
X tptr = _find(tptr, ":|");
X }
X }
X return 0;
X}
X
X static int
Xnextent(tbuf, termcap, buflen) /* Read 1 entry from TERMCAP file */
X char *tbuf;
X FILE *termcap;
X int buflen;
X{
X char *lbuf = tbuf; /* lbuf=line buffer */
X /* read lines straight into buffer */
X
X while (lbuf < tbuf+buflen && /* There's room and */
X fgets(lbuf, (int)(tbuf+buflen-lbuf), termcap)) /* another line */
X {
X int llen = strlen(lbuf);
X
X if (*lbuf == '#') /* eat comments */
X continue;
X if (lbuf[-1] == ':' && /* and whitespace */
X lbuf[0] == '\t' &&
X lbuf[1] == ':')
X {
X strcpy(lbuf, lbuf+2);
X llen -= 2;
X }
X if (lbuf[llen-2] == '\\') /* and continuations */
X lbuf += llen-2;
X else
X {
X lbuf[llen-1]=0; /* no continuation, return */
X return 1;
X }
X }
X
X return 0; /* ran into end of file */
X}
X
X/*
X * Module: tgetflag
X *
X * Purpose: returns flag true or false as to the existence of a given
X * entry. used with 'bs', 'am', etc...
X *
X * Calling conventions: id is the 2 character capability id.
X *
X * Returned values: 1 for success, 0 for failure.
X */
X
Xtgetflag(id)
X char *id;
X{
X char buf[256], *ptr = buf;
X
X return tgetstr(id, &ptr) ? 1 : 0;
X}
X
X/*
X * Module: tgetnum
X *
X * Purpose: get numeric value such as 'li' or 'co' from termcap.
X *
X * Calling conventions: id = 2 character id.
X *
X * Returned values: -1 for failure, else numerical value.
X */
X
Xtgetnum(id)
Xchar *id;
X{
X char *ptr, buf[256];
X ptr = buf;
X
X if (tgetstr(id, &ptr))
X return atoi(buf);
X else
X return 0;
X}
X
X/*
X * Module: tgetstr
X *
X * Purpose: get terminal capability string from database.
X *
X * Calling conventions: id is the two character capability id.
X * (*buf) points into a hold buffer for the
X * id. the capability is copied into the buffer
X * and (*buf) is advanced to point to the next
X * free byte in the buffer.
X *
X * Returned values: 0 = no such entry, otherwise returns original
X * (*buf) (now a pointer to the string).
X *
X * Notes
X * It also decodes certain escape sequences in the buffer.
X * they should be obvious from the code:
X * \E = escape.
X * \n, \r, \t, \f, \b match the 'c' escapes.
X * ^x matches control-x (^@...^_).
X * \nnn matches nnn octal.
X * \x, where x is anything else, matches x. I differ
X * from the standard library here, in that I allow ^: to match
X * :.
X *
X */
X
Xchar *
Xtgetstr(id, buf)
Xchar *id, **buf;
X{
X int len = strlen(id);
X char *tmp=tent;
X char *hold;
X int i;
X
X do {
X tmp = _find(tmp, ":"); /* For each field */
X while (*tmp == ':') /* skip empty fields */
X tmp++;
X if (!*tmp)
X break;
X
X if (_match(id, tmp) == len) {
X tmp += len; /* find '=' '@' or '#' */
X if (*tmp == '@') /* :xx@: entry for tc */
X return 0; /* deleted entry */
X hold= *buf;
X while (*++tmp && *tmp != ':') {/* not at end of field */
X switch(*tmp) {
X case '\\': /* Expand escapes here */
X switch(*++tmp) {
X case 0: /* ignore backslashes */
X tmp--; /* at end of entry */
X break; /* shouldn't happen */
X case 'e':
X case 'E': /* ESC */
X *(*buf)++ = '\033';
X break;
X case 'n': /* \n */
X *(*buf)++ = '\n';
X break;
X case 'r': /* \r */
X *(*buf)++ = '\r';
X break;
X case 't': /* \t */
X *(*buf)++ = '\t';
X break;
X case 'b': /* \b */
X *(*buf)++ = '\b';
X break;
X case 'f': /* \f */
X *(*buf)++ = '\f';
X break;
X case '0': /* \nnn */
X case '1':
X case '2':
X case '3':
X case '4':
X case '5':
X case '6':
X case '7':
X case '8':
X case '9':
X **buf = 0;
X /* get up to three digits */
X for (i = 0; i < 3 && isdigit(*tmp); ++i)
X **buf = **buf * 8 + *tmp++ - '0';
X (*buf)++;
X tmp--;
X break;
X default: /* \x, for all other x */
X *(*buf)++= *tmp;
X }
X break;
X case '^': /* control characters */
X *(*buf)++ = *++tmp - '@';
X break;
X default:
X *(*buf)++ = *tmp;
X }
X }
X *(*buf)++ = 0;
X return hold;
X }
X } while (*tmp);
X
X return 0;
X}
X
X/*
X * Module: tgoto
X *
X * Purpose: decode cm cursor motion string.
X *
X * Calling conventions: cm is cursor motion string.
X * line, col, are the desired destination.
X *
X * Returned values: a string pointing to the decoded string, or
X * "OOPS" if it cannot be decoded.
X *
X * Notes
X * The accepted escapes are:
X * %d as in printf, 0 origin.
X * %2, %3 like %02d, %03d in printf.
X * %. like %c
X * %+x adds <x> to value, then %.
X * %>xy if value>x, adds y. No output.
X * %i increments line& col, no output.
X * %r reverses order of line&col. No output.
X * %% prints as a single %.
X * %n exclusive or row & col with 0140.
X * %B BCD, no output.
X * %D reverse coding (x-2*(x%16)), no output.
X */
X
Xchar *
Xtgoto(cm, col, line)
Xchar *cm; /* cm string, from termcap */
Xint col, /* column, x position */
X line; /* line, y position */
X{
X char gx, gy, /* x, y */
X *ptr, /* pointer in 'cm' */
X reverse = 0, /* reverse flag */
X *bufp, /* pointer in returned string */
X addup = 0, /* add upline */
X addbak = 0, /* add backup */
X c;
X static char buffer[32];
X
X if (!cm)
X return "OOPS"; /* Kludge, but standard */
X
X bufp = buffer;
X ptr = cm;
X
X while (*ptr) {
X if ((c = *ptr++) != '%') { /* normal char */
X *bufp++ = c;
X } else { /* % escape */
X switch(c = *ptr++) {
X case 'd': /* decimal */
X bufp = _addfmt(bufp, "%d", line);
X line = col;
X break;
X case '2': /* 2 digit decimal */
X bufp = _addfmt(bufp, "%02d", line);
X line = col;
X break;
X case '3': /* 3 digit decimal */
X bufp = _addfmt(bufp, "%03d", line);
X line = col;
X break;
X case '>': /* %>xy: if >x, add y */
X gx = *ptr++;
X gy = *ptr++;
X if (col>gx) col += gy;
X if (line>gx) line += gy;
X break;
X case '+': /* %+c: add c */
X line += *ptr++;
X case '.': /* print x/y */
X if (line == '\t' || /* these are */
X line == '\n' || /* chars that */
X line == '\004' || /* UNIX hates */
X line == '\0') {
X line++; /* so go to next pos */
X if (reverse == (line == col))
X addup=1; /* and mark UP */
X else
X addbak=1; /* or BC */
X }
X *bufp++=line;
X line = col;
X break;
X case 'r': /* r: reverse */
X gx = line;
X line = col;
X col = gx;
X reverse = 1;
X break;
X case 'i': /* increment (1-origin screen) */
X col++;
X line++;
X break;
X case '%': /* %%=% literally */
X *bufp++='%';
X break;
X case 'n': /* magic DM2500 code */
X line ^= 0140;
X col ^= 0140;
X break;
X case 'B': /* bcd encoding */
X line = line/10<<4+line%10;
X col = col/10<<4+col%10;
X break;
X case 'D': /* magic Delta Data code */
X line = line-2*(line&15);
X col = col-2*(col&15);
X break;
X default: /* Unknown escape */
X return "OOPS";
X }
X }
X }
X
X if (addup) /* add upline */
X if (UP) {
X ptr=UP;
X while (isdigit(*ptr) || *ptr == '.')
X ptr++;
X if (*ptr == '*')
X ptr++;
X while (*ptr)
X *bufp++ = *ptr++;
X }
X
X if (addbak) /* add backspace */
X if (BC) {
X ptr=BC;
X while (isdigit(*ptr) || *ptr == '.')
X ptr++;
X if (*ptr == '*')
X ptr++;
X while (*ptr)
X *bufp++ = *ptr++;
X }
X else
X *bufp++='\b';
X
X *bufp = 0;
X
X return(buffer);
X}
X
X/*
X * Module: tinit
X *
X * Purpose: simplified terminal initialisation.
X *
X * Calling conventions: name is name of terminal.
X *
X * Returned values: none.
X *
X * Notes
X * tinit calls tgetent, then sets up the global
X * variables PC, UP, BC, ospeed appropriately.
X *
X */
X
X#if 0 /* already included in term.c */
X
Xchar tbuf[TBUFSZ]; /* Buffer for termcap entry */
Xchar junkbuf[TBUFSZ]; /* Big buffer for junk */
Xchar *junkptr;
X
Xtinit(name)
Xchar *name;
X{
X#ifndef AMIGA
X struct sgttyb sgbuf;
X#endif
X char *ps;
X
X junkptr = junkbuf;
X
X tgetent(tbuf, name);
X
X ps = tgetstr("pc", &junkptr);
X if (ps) PC = *ps;
X UP = tgetstr("up", &junkptr);
X BC = tgetstr("bc", &junkptr);
X
X#ifdef AMIGA
X ospeed=0;
X#else
X gtty(1, &sgbuf);
X ospeed=sgbuf.sg_ospeed;
X#endif
X return 0;
X}
X#endif
X
X/*
X * Module: tputs
X *
X * Purpose: decode padding information
X *
X * Calling conventions: cp = string to be padded, affcnt = # of items
X * affected (lines, characters, whatever),
X * outc = routine to output 1 character.
X *
X * Returned values: none
X *
X * Notes
X * cp has padding information ahead of it, in the form
X * nnnTEXT or nnn*TEXT. nnn is the number of milliseconds to delay,
X * and may be a decimal (nnn.mmm). If the asterisk is given, then
X * the delay is multiplied by afcnt. The delay is produced by outputting
X * a number of nulls (or other padding char) after printing the
X * TEXT.
X *
X */
X
Xlong _bauds[16]={
X 0, 50, 75, 110,
X 134, 150, 200, 300,
X 600, 1200, 1800, 2400,
X 4800, 9600, 19200, 19200 };
X
Xtputs(cp, affcnt, outc)
Xchar *cp; /* string to print */
Xint affcnt; /* Number of lines affected */
Xvoid (*outc) __ARGS((unsigned int)); /* routine to output 1 character */
X{
X long frac, /* 10^(#digits after decimal point) */
X counter, /* digits */
X atol();
X
X if (isdigit(*cp)) {
X counter = 0;
X frac = 1000;
X while (isdigit(*cp))
X counter = counter * 10L + (long)(*cp++ - '0');
X if (*cp == '.')
X while (isdigit(*++cp)) {
X counter = counter * 10L + (long)(*cp++ - '0');
X frac = frac * 10;
X }
X if (*cp!='*') { /* multiply by affected lines */
X if (affcnt>1) affcnt = 1;
X }
X else
X cp++;
X
X /* Calculate number of characters for padding counter/frac ms delay */
X if (ospeed)
X counter = (counter * _bauds[ospeed] * (long)affcnt) / frac;
X
X while (*cp) /* output string */
X (*outc)(*cp++);
X if (ospeed)
X while (counter--) /* followed by pad characters */
X (*outc)(PC);
X }
X else
X while (*cp)
X (*outc)(*cp++);
X return 0;
X}
X
X/*
X * Module: tutil.c
X *
X * Purpose: Utility routines for TERMLIB functions.
X *
X */
X
X static int
X_match(s1, s2) /* returns length of text common to s1 and s2 */
Xchar *s1, *s2;
X{
X int i = 0;
X
X while (s1[i] && s1[i] == s2[i])
X i++;
X
X return i;
X}
X
X static char *
X_find(s, set) /* finds next c in s that's a member of set, returns pointer */
Xchar *s, *set;
X{
X for(; *s; s++) {
X char *ptr = set;
X
X while (*ptr && *s != *ptr)
X ptr++;
X
X if (*ptr)
X return s;
X }
X
X return s;
X}
X
X static char *
X_addfmt(buf, fmt, val) /* add val to buf according to format fmt */
Xchar *buf, *fmt;
Xint val;
X{
X sprintf(buf, fmt, val);
X while (*buf)
X buf++;
X return buf;
X}
END_OF_FILE
if test 15559 -ne `wc -c <'vim/src/termlib.c'`; then
echo shar: \"'vim/src/termlib.c'\" unpacked with wrong size!
fi
# end of 'vim/src/termlib.c'
fi
echo shar: End of archive 4 \(of 26\).
cp /dev/null ark4isdone
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...