home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / vim / part03 < prev    next >
Internet Message Format  |  1994-08-16  |  71KB

  1. From: mool@oce.nl (Bram Moolenaar)
  2. Newsgroups: comp.sources.misc
  3. Subject: v44i022:  vim - Vi IMproved editor, v3.0, Part03/26
  4. Date: 16 Aug 1994 21:17:21 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <32rrvh$kam@sparky.sterling.com>
  9. X-Md4-Signature: 51bfa32793529618e4898ff205afa628
  10.  
  11. Submitted-by: mool@oce.nl (Bram Moolenaar)
  12. Posting-number: Volume 44, Issue 22
  13. Archive-name: vim/part03
  14. Environment: UNIX, AMIGA, MS-DOS, Windows NT
  15. Supersedes: vim: Volume 41, Issue 50-75
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  vim/doc/reference.doc.A vim/src/archie.c vim/src/archie.h
  22. # Wrapped by kent@sparky on Mon Aug 15 21:43:58 1994
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 3 (of 26)."'
  26. if test -f 'vim/doc/reference.doc.A' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'vim/doc/reference.doc.A'\"
  28. else
  29.   echo shar: Extracting \"'vim/doc/reference.doc.A'\" \(52085 characters\)
  30.   sed "s/^X//" >'vim/doc/reference.doc.A' <<'END_OF_FILE'
  31. X
  32. X
  33. X
  34. X                Vim reference manual
  35. X                      
  36. X                 By Bram Moolenaar
  37. X                      
  38. X                version 3.0
  39. X                      
  40. X
  41. XThere is a contents listing at the end of this document.
  42. X
  43. XThe commands and options for multiple windows and buffers are explained in a
  44. Xseparate document: windows.doc
  45. X
  46. X
  47. X
  48. X    1. Introduction
  49. X
  50. XVim stands for Vi IMproved. It used to be Vi IMitation, but that does not
  51. Xreally cover it anymore. Vim is a text editor which includes almost all the
  52. Xcommands from the Unix program "Vi" (and a lot new ones). It is very useful
  53. Xfor editing programs and other ASCII text. All commands are given with the
  54. Xkeyboard. There is no mouse support and there are no menus. This gives the
  55. Xadvantage that you can keep your fingers on the keyboard and your eyes on
  56. Xthe screen.
  57. X
  58. XThroughout this manual the differences between Vi and Vim are mentioned in 
  59. Xcurly braces. Read the file "difference.doc" for a summary of the 
  60. Xdifferences.
  61. X
  62. XThis manual refers to Vim on the Commodore Amiga computer. On other 
  63. Xcomputers and on terminals there may be small differences. For MSDOS this 
  64. Xis documented in msdos.doc. For UNIX this is in unix.doc.
  65. X
  66. XThis manual is a reference for all the Vim commands and options. A basic
  67. Xknowledge of "Vi" is assumed. A summary of this manual can be found in the 
  68. Xfile vim.hlp. It can be accessed from within Vim with the <HELP> key (in 
  69. XMSDOS <F1>) and with the command ":help". The 'helpfile' option can be 
  70. Xset to the name of the help file, so you can put it in any place you like.
  71. X
  72. X
  73. X    2. Notation
  74. X
  75. X[]        Characters in square brackets are optional.
  76. X
  77. X[count]        An optional number that may precede the command to multiply
  78. X        or iterate the command. If no number is given a count of one
  79. X        is used, unless otherwise noted. Note that in this manual
  80. X        the [count] is not mentioned in the description of the
  81. X        command, but only in the explanation. This was done to make
  82. X        the commands easier to lookup. If the "sc" option is on, the
  83. X        (partially) entered count is shown at the bottom of the
  84. X        window. You can use <DEL> to erase the last digit.
  85. X
  86. X["x]        An optional register designation where text can be stored.
  87. X        The x is a single character between <a> and <z> or <A> and
  88. X        <Z> or <">, and in some cases (with the put command) between
  89. X        <0> and <9>, <%>, <:> or <.>. The uppercase and lower case
  90. X        letter designate the same register, but the lower case letter
  91. X        is used to overwrite the previous register contents, while the
  92. X        uppercase letter is used to append to the previous register
  93. X        contents. Without the ""x" or with """" the stored text is
  94. X        put into the unnamed register. See also "Copying and moving
  95. X        text".
  96. X
  97. X{}        Curly braces denote parts of the command which must appear, 
  98. X        but can take a number of different values. The differences 
  99. X        between Vim and Vi are also given in curly braces (this will 
  100. X        be clear from the context).
  101. X
  102. X{motion}    A command that moves the cursor. They are listed in chapter 
  103. X        6. This is used after an "operator" command to move over the 
  104. X        text that is to be operated upon. If the motion includes a 
  105. X        count and the operator also had a count, the two counts are 
  106. X        multiplied. For example: "2d3w" deletes six words.
  107. X
  108. X{visual}    A piece of text that is started with the "v", "V" or CTRL-V
  109. X        command and ended by the cursor position. This is used
  110. X        before an "operator" to highlight the text that is to be
  111. X        operated upon. See the chapter on Visual mode.
  112. X
  113. X<character>    A special character from the table below or a single ASCII
  114. X        character.
  115. X
  116. X<char1-char2>    A single character from the range <char1> to <char2>. For
  117. X        example: <a-z> is a lower case letter. Multiple ranges may be
  118. X        concatenated. For example: <a-zA-Z0-9> is any alphanumeric
  119. X        character.
  120. X
  121. XCTRL-<char>    <char> typed as a control character, that is, typing <char>
  122. X        while holding the CTRL key down. The case of <char> does not
  123. X        matter, thus CTRL-A and CTRL-a are equivalent.
  124. X
  125. X'option'    An option, or parameter, that can be set to a value is
  126. X        enclosed in single quotes. See chapter 19.
  127. X
  128. X"command"    In examples the commands you can type are enclosed in double
  129. X        quotes.
  130. X
  131. X
  132. Xnotation    meaning             equivalent decimal value
  133. X-----------------------------------------------------------------------
  134. X<NUL>        zero            CTRL_@  000 (internally 010)
  135. X<BELL>      bell            CTRL-G    007
  136. X<BS>        backspace        CTRL-H    008
  137. X<TAB>       tab            CTRL-I    009
  138. X<LF>        linefeed        CTRL-J    010
  139. X<FF>        formfeed        CTRL-L    012
  140. X<CR>        carriage return        CTRL-M    013
  141. X<ESC>       escape            CTRL-[    027
  142. X<SPACE>        space                032
  143. X<DEL>       delete                127
  144. X<C_UP>        cursor-up            128 (msdos: 176)
  145. X<C_DOWN>    cursor-down            129 (msdos: 177)
  146. X<C_LEFT>    cursor-left            130 (msdos: 178)
  147. X<C_RIGHT>    cursor-right            131 (msdos: 179)
  148. X<SC_UP>        shift-cursor-up            132 (msdos: 180)
  149. X<SC_DOWN>    shift-cursor-down        133 (msdos: 181)
  150. X<SC_LEFT>    shift-cursor-left        134 (msdos: 182)
  151. X<SC_RIGHT>    shift-cursor-right        135 (msdos: 183)
  152. X<F1> - <F10>    function keys 1 to 10        136 - 145 (msdos: 184 - 193)
  153. X<SF1> - <SF10>    shift-function keys 1 to 10    146 - 155 (msdos: 194 - 203)
  154. XHELP>        help key            156 (msdos: 204)
  155. X<UNDO>        undo key            157 (msdos: 205)
  156. X-----------------------------------------------------------------------
  157. XNote: The shifted cursor keys, the help key and the undo key are only
  158. Xavailable on a few terminals. On some terminals the function keys 11 to 20
  159. Xare used instead of the shifted function keys. On the Amiga shifted function
  160. Xkey 10 produces a code (CSI) that is also used by key sequences. It will be
  161. Xrecognized only after typing another key.
  162. X
  163. X
  164. X    3. Starting Vim
  165. X
  166. X3.1 Command line
  167. X
  168. XMost often Vim is started to edit a single file with the command
  169. X
  170. X    vim file
  171. X
  172. XMore generally Vim is started with:
  173. X
  174. X    vim [options] [filelist]
  175. X
  176. XIf the filelist is missing, the editor will start with an empty buffer.
  177. XOtherwise exactly one out of the following three may be used to choose one
  178. Xor more files to be edited.
  179. X
  180. Xfile ..        A list of file names. The first one will be the current file 
  181. X        and read into the buffer. The cursor will be positioned on 
  182. X        the first line of the buffer.
  183. X
  184. X-t {tag}    A tag. "tag" is looked up in the tags file, the associated 
  185. X        file becomes the current file and the associated command is 
  186. X        executed. Mostly this is used for C programs. In that case 
  187. X        "tag" should be a function name. The effect is that the file 
  188. X        containing that function becomes the current file and the 
  189. X        cursor is positioned on the start of the function (see the 
  190. X        section "tag searches").
  191. X
  192. X-e [errorfile]    QuickFix mode. The file with the name [errorfile] is read
  193. X        and the first error is displayed. If [errorfile] is not
  194. X        given, the 'errorfile' option is used for the file name
  195. X        (default "AztecC.Err" for the Amiga, "errors" for other
  196. X        systems). See section 5.5: "using the QuickFix mode".
  197. X
  198. XThe options, if present, must precede the filelist. The options may be given 
  199. Xin any order.
  200. X
  201. X+[num]        The cursor will be positioned on line "num" for the first
  202. X        file being edited. If "num" is missing, the cursor will be
  203. X        positioned on the last line.
  204. X
  205. X+/{pat}        The cursor will be positioned on the first line containing
  206. X        "pat" in the first file being edited (see the section
  207. X        "pattern searches" for the available search patterns).
  208. X
  209. X+{command}
  210. X-c {command}    "command" will be executed after the first file has been
  211. X        read. "command" is interpreted as an Ex command. If the
  212. X        "command" contains spaces it must be enclosed in double
  213. X        quotes (this depends on the shell that is used). Example:
  214. X        vim "+set si" main.c
  215. X
  216. X-r        Recovery mode. The swap file is read to recover a 
  217. X        crashed editing session. See the chapter "Recovery after a
  218. X        crash".
  219. X
  220. X-v        View mode. The 'readonly' option will be set and no 
  221. X        swap file will be written (see -n below). You can 
  222. X        still edit the buffer, but will be prevented from 
  223. X        accidentally overwriting a file. If you forgot that you are 
  224. X        in View mode and did make some changes, you can overwrite 
  225. X        a file by adding an exclamation mark to the Ex command, as in 
  226. X        ":w!". The 'readonly' option can be reset with ":set noro" 
  227. X        (see the options chapter). Calling the executable "view" 
  228. X        has the same effect as the -v option. If your system does 
  229. X        not support links and you do not want to have the executable 
  230. X        twice you could make an alias: "alias view vim -v".
  231. X
  232. X-b        Binary mode. The 'textauto', 'textmode' and 'expandtab'
  233. X        options will be reset. The 'textwidth' option is set to 0.
  234. X        'modelines' is set to 0. The 'binary' option is set. This is
  235. X        done after reading the .vimrc/.exrc files but before reading
  236. X        a file. See also 5.6: "Editing binary files".
  237. X
  238. X-n        No swap file will be used. Recovery after a crash will be
  239. X        impossible. Handy if you want to view or edit a file on a
  240. X        very slow medium (e.g. floppy). Can also be done with ":set
  241. X        uc=0". You can switch it on again by setting the 'uc' option
  242. X        to some value, e.g. ":set uc=100". Any files already being
  243. X        edited will not be affected by this.
  244. X
  245. X-o[N]        Open N windows. If [N] is not given, one window is opened
  246. X        for every file given as argument. If there is not enough
  247. X        room, only the first few files get a window. If there are
  248. X        more windows than arguments, the last few windows will be
  249. X        editing an empty file.
  250. X
  251. X-T {terminal}    Set the terminal type to "terminal". This influences the 
  252. X        codes that Vim will send to your terminal. This is normally 
  253. X        not needed, because Vim will be able to find out what type 
  254. X        of terminal you are using (See chapter 20).
  255. X
  256. X-d {device}    Amiga only: The "device" is opened to be used for editing.
  257. X        Normally you would use this to set the window position and
  258. X        size: "-d con:x/y/width/height", e.g.
  259. X        "-d con:30/10/600/150". But you can also use it to start
  260. X        editing on another device, e.g. AUX:.
  261. X
  262. X-x        Amiga only: Do not restart Vim to open a new window. This
  263. X        option should be used when Vim is started by a program that
  264. X        will wait for the edit session to finish (e.g. mail or
  265. X        readnews). See section 3.3.
  266. X
  267. X-s {scriptin}    The script file "scriptin" is read. The characters in the 
  268. X        file are interpreted as if you had typed them. The same can 
  269. X        be done with the command ":source! {scriptin}". If the end 
  270. X        of the file is reached before the editor exits, further 
  271. X        characters are read from the keyboard. See also the section 
  272. X        "complex repeats".
  273. X
  274. X-w {scriptout}    All the characters that you type are recorded in the file
  275. X        "scriptout", until you exit Vim. This is useful if you want 
  276. X        to create a script file to be used with "vim -s" or 
  277. X        ":source!". See also the section "complex repeats".
  278. X
  279. XExample for using a script file to change a name in several files:
  280. X    Create a file "subs.vi" containing substitute commands and a :wq
  281. X    command:
  282. X
  283. X        :%s/Jones/Smith/g
  284. X        :%s/Allen/Peter/g
  285. X        :wq
  286. X
  287. X    Execute Vim on all files you want to change:
  288. X
  289. X        foreach i ( *.let ) vim -s subs.vi $i
  290. X
  291. XIf the executable is called "view" Vim will start in Readonly mode. This is 
  292. Xuseful if you can make a hard or symbolic link from "view" to "vim".
  293. XStarting in Readonly mode can also be done with "vim -v". 
  294. X
  295. X
  296. X3.2 Workbench (Amiga only)
  297. X
  298. XVim can be started from the workbench by clicking on its icon twice. It will
  299. Xthen start with an empty buffer.
  300. X
  301. XVim can be started to edit one or more files by using a "Project" icon. The
  302. X"Default Tool" of the icon must be the full pathname of the Vim executable. 
  303. XThe name of the ".info" file must be the same as the name of the text file. 
  304. XBy clicking on this icon twice, Vim will be started with the filename as 
  305. Xcurrent filename, which will be read into the buffer (if it exists). You can 
  306. Xedit multiple files by pressing the shift key while clicking on icons, and 
  307. Xclicking twice on the last one. The "Default Tool" for all these icons must 
  308. Xbe the same.
  309. X
  310. XIt is not possible to give arguments to Vim, other than filenames, from the
  311. Xworkbench.
  312. X
  313. X
  314. X3.3 Vim window (Amiga only)
  315. X
  316. XVim will run in the CLI window where it was started. If Vim was started with 
  317. Xthe "run" or "runback" command, or if Vim was started from the workbench, it 
  318. Xwill open a window of its own.
  319. X
  320. XTechnical detail:
  321. X    To open the new window a little trick is used. As soon as Vim 
  322. X    recognizes that it does not run in a normal CLI window, it will 
  323. X    create a script file in t:. This script file contains the same 
  324. X    command as how Vim was started, and an "endcli" command. This script 
  325. X    file is then executed with a "newcli" command (the "c:run" and 
  326. X    "c:newcli" commands are required for this to work). The script file 
  327. X    will hang around until reboot, or until you delete it. This method 
  328. X    is required to get the ":sh" and ":!" commands to work correctly. 
  329. X    But when Vim was started with the -e option (Quickfix mode) or with 
  330. X    the -x option, this method is not used. The reason for this is that 
  331. X    when a compiler starts Vim with the -e option it will wait for a 
  332. X    return code. With the script trick the compiler cannot get the 
  333. X    return code. The -x option can be used when Vim is started by a mail 
  334. X    program which also waits for the edit session to finish. As a 
  335. X    consequence the ":sh" and ":!" commands are not available when the 
  336. X    -e or -x option is used.
  337. X
  338. XVim will automatically recognize the window size and react to window 
  339. Xresizing. Under Amiga DOS 1.3 it is advised to use the fastfonts program 
  340. X"FF" to speed up display redrawing.
  341. X
  342. X
  343. X3.4 Initialization
  344. X
  345. XWhen Vim starts running it does initializations in the following order. If
  346. Xan environment variable is used, it is executed as a single Ex command line.
  347. XMultiple commands must be separated with <|> or <LF>. If a file is used,
  348. Xeach line is executed as an Ex command line.
  349. X
  350. X1.  Four places are searched for initializations. The first that exists is 
  351. X    used, the others are ignored.
  352. X     1. The environment variable VIMINIT
  353. X     2. The file "s:.vimrc" (for Unix: "$HOME/.vimrc")
  354. X     3. The environment variable EXINIT
  355. X     4. The file "s:.exrc" (for Unix: "$HOME/.exrc")
  356. X
  357. X2.  If the 'exrc' option is set (default is 'noexrc'), the current directory
  358. X    is searched for two files. The first that exists is used, the other is
  359. X    ignored.
  360. X     1. The file ".vimrc"
  361. X     2. The file ".exrc"
  362. X
  363. X3.  The environment variable SHELL, if it exists, is used to set the 
  364. X    'shell' option. With MSDOS the COMPSPEC variable is used if SHELL does
  365. X    not exist. The 'shellpipe' option is set according to the name of the
  366. X    shell.
  367. X
  368. X4.  The environment variable TERM, if it exists, is used to set the 'term'
  369. X    option.
  370. X
  371. XThe first can be used to set your default settings and mappings for all edit 
  372. Xsessions. The second one for sessions in a certain directory (note that the
  373. X'exrc' option is default off). See the section "Saving settings" for how to
  374. Xcreate a file with commands to recreate the current settings.
  375. X
  376. XIf the VIMINIT environment variable or ".vimrc" exist the EXINIT and ".exrc" 
  377. Xare skipped. This can be used to initialize Vim without interfering with 
  378. Xanother version of Vi.
  379. X
  380. XOn the Amiga two types of environment variables exist. The ones set with the
  381. XDOS 1.3 (or later) setenv command are recognized. See the AmigaDos 1.3 
  382. Xmanual. The environment variables set with the old Manx Set command (before 
  383. Xversion 5.0) are not recognized.
  384. X
  385. XOn MS-DOS systems Vim assumes that all the "_vimrc" and "_exrc" files have
  386. X<CR><LF> pairs as line separators. This will give problems if you have a
  387. Xfile with only <LF>s and have a line like ":map xx yy^M". The trailing ^M
  388. Xwill be ignored.
  389. X
  390. XWhile reading the ".vimrc" or the ".exrc" file in the current directory some
  391. Xcommands can be disabled for security reasons by setting the 'secure'
  392. Xoption. Otherwise it would be possible to create a .exrc that contains nasty
  393. Xcommands, which another user may automatically execute when he starts Vim it
  394. Xthat directory. The disabled commands are the ones that start a shell and
  395. Xthe ones that write to a file. The ":map" commands are echoed, so you can
  396. Xsee which keys are being mapped.
  397. X
  398. XYou can reset the 'secure' option in the EXINIT or VIMINIT environment
  399. Xvariable or in the global ".exrc" or ".vimrc" file. This is not possible in
  400. X".vimrc" or ".exrc" in the current directory, for obvious reasons.
  401. X
  402. XOn unix systems this only happens if you are not the owner of the ".vimrc" 
  403. Xor ".exrc" file. Warning: If you unpack an archive that contains a .exrc 
  404. Xfile, it will be owned by you. You won't have the security protection. Check 
  405. Xthe .exrc file before you start Vim in that directory, or reset the 'exrc' 
  406. Xoption. 
  407. X
  408. X
  409. X3.5 Suspending
  410. X
  411. XCTRL-Z                Suspend the editor. Same as ":stop".
  412. X
  413. X:sus[pend][!]        or
  414. X:st[op][!]            Suspend the editor. If the <!> is not given,
  415. X                the buffer was changed, autowrite is set and 
  416. X                a filename is known, the buffer will be 
  417. X                written.
  418. X
  419. XOn many UNIX systems it is possible to suspend Vim with CTRL-Z. This is only 
  420. Xpossible in Command mode (see next chapter). Vim will continue if you make it 
  421. Xthe foreground job again. On other systems CTRL-Z will start a new shell. 
  422. XThis is the same as the ":sh" command. Vim will continue if you exit from the 
  423. Xshell.
  424. X
  425. X
  426. X    4. Modes
  427. X
  428. X4.1 Introduction
  429. X
  430. XVim has four basic modes:
  431. X
  432. XCommand mode        In Command mode you can enter all the editor
  433. X            commands. If you start the editor you are in this 
  434. X            mode (unless you have set the 'insertmode' option, 
  435. X            see below).
  436. X
  437. XInsert mode        In Insert mode the text you type is inserted into the
  438. X            buffer. If the 'showmode' option is set (which is
  439. X            default), the string "-- INSERT --" is shown at the
  440. X            bottom of the window.
  441. X
  442. XReplace mode        Replace mode is a special case of Insert mode. You
  443. X            can do the same things as in Insert mode, but for 
  444. X            each character you enter (except some special 
  445. X            characters) one character of the existing text is 
  446. X            deleted. If the 'showmode' option is set (which is 
  447. X            default), the string "-- REPLACE --" is shown at the 
  448. X            bottom of the window.
  449. X
  450. XCommand_line mode    In Command_line mode you can enter one line of text
  451. X            at the bottom of the window. This is for the Ex
  452. X            commands <:>, the pattern search commands <?></> and
  453. X            the filter command <!>.
  454. X
  455. XMore explanation on the insert, replace and Command_line mode is further on 
  456. Xin this chapter.
  457. X
  458. X
  459. X4.2 Switching from mode to mode
  460. X
  461. XIf for any reason you do not know in which mode you are, you can always get
  462. Xback to Command mode by typing <ESC> twice. You will know you are back in
  463. XCommand mode when you see the screen flash or hear the bell after you type
  464. X<ESC>.
  465. X
  466. X- go from Command mode to Insert mode by giving one of the commands
  467. X  "iIaAoOcCsS".
  468. X- go from Command mode to Replace mode with the "R" command (not the "r"
  469. X  command!).
  470. X- go from Command mode to Command_line mode with the one of the commands
  471. X  ":/?!".
  472. X
  473. X- go from insert or Replace mode to Command mode with <ESC> (twice in some
  474. X  rare cases).
  475. X- go from Command_line mode to Command mode by:
  476. X   - hitting <CR> or <LF>, which causes the entered command to be executed
  477. X   - deleting the complete line (e.g. with CTRL-U) and giving a final <BS>
  478. X   - hitting CTRL-C or <ESC>, which quits the command line without executing
  479. X     the command.
  480. X  In the last case <ESC> may be the character defined with the 'wildchar'
  481. X  option, and start command line completion. You can ignore that and type
  482. X  <ESC> again. {vi: when hitting <ESC> the command line is executed. This is
  483. X  unexpected for most people, therefore it was changed in Vim. But when the
  484. X  <ESC> is part of a mapping the command line is executed. If you want the
  485. X  vi behaviour also when typing <ESC> use ":cmap ^V<ESC> ^V^M"}
  486. X
  487. XIf the 'insertmode' option is set, editing a file will start in Insert mode.
  488. X
  489. X
  490. X4.3 Insert and Replace mode
  491. X
  492. X4.3.1 special keys
  493. X
  494. XIn insert and Replace mode the following characters have a special meaning,
  495. Xother characters are inserted directly. To insert one of these special
  496. Xcharacters into the buffer, precede it with CTRL-V. To insert a <NUL> 
  497. Xcharacter use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems you have to
  498. Xuse "CTRL-V 003" to insert a CTRL-C.
  499. X
  500. Xchar        action
  501. X-----------------------------------------------------------------------
  502. XCTRL-@        Insert previously inserted text and stop insert. {Vi: only
  503. X        when typed as first char, only up to 128 chars}
  504. XCTRL-A        Insert previously inserted text. {not in Vi}
  505. XCTRL-B        Toggle the 'revins' option (B for Backwards). {not in Vi}
  506. XCTRL-C        Quit insert mode, back to command mode. Do not check for
  507. X        abbreviations.
  508. XCTRL-D        Delete one shiftwidth of indent at the start of the current 
  509. X        line. See also 'shiftround' option. When preceded with <^>
  510. X        or <0> delete all indent in the current line. With <^> the
  511. X        indent is restored in the next line. This is useful when
  512. X        inserting a label. {Vi: CTRL-D works only when used after
  513. X        autoindent}
  514. XCTRL-E        Insert the character which is below the cursor. {not in Vi}
  515. XCTRL-H <BS>    Delete the character before the cursor (see below). {Vi: 
  516. X        does not delete autoindents}
  517. XCTRL-I <TAB>    Insert a tab. If the 'expandtab' option is on, the
  518. X        equivalent number of spaces is inserted (use CTRL-V <TAB> to
  519. X        avoid the expansion). See also the 'smarttab' option, section
  520. X        4.3.4.
  521. XCTRL-J <LF>    Begin new line.
  522. XCTRL-K {char1} {char2}
  523. X        Enter digraph (see 4.7). {not in Vi}
  524. XCTRL-M <CR>    Begin new line.
  525. XCTRL-N        Find next keyword (see 4.3.7). {not in Vi}
  526. XCTRL-O        Execute one Command mode command. See below. {not in Vi}
  527. XCTRL-P        Find previous keyword (see 4.3.7). {not in Vi}
  528. XCTRL-R <0-9a-z"%:>
  529. X        Insert the contents of a numbered or named register. The
  530. X        text is inserted as if you typed it, but mappings and
  531. X        abbreviations are not used. If you have options like
  532. X        'textwidht' or 'autoindent' set, this will influence what
  533. X        will be inserted. Use <"> for the unnamed register,
  534. X        containing the text of the last delete or yank. Use <%> for
  535. X        the current file name.  Use <:> for the last command line. See
  536. X        the chapter on copying and moving text about registers. {<%>,
  537. X        <"> and <:> not in Vi}
  538. XCTRL-T        Insert one shiftwidth of indent at the start of the current 
  539. X        line. See also 'shiftround' option. {Vi: only when in 
  540. X        autoindent}
  541. XCTRL-U        Delete all entered characters in the current line (see 
  542. X        below).
  543. XCTRL-V        Insert next non-digit literally. Up to three digits form the 
  544. X        decimal value of a single byte. The non-digit and the three
  545. X        digits are not considered for mapping. {Vi: no decimal byte
  546. X        entry}
  547. XCTRL-W        Delete the word before the cursor (see below). See the 
  548. X        section "word motions" for the definition of a word.
  549. XCTRL-Y        Insert the character which is above the cursor. {not in Vi}
  550. XCTRL-[ or <ESC>    End insert or Replace mode, back to Command mode.
  551. X<DEL>        Same as CTRL-H <BS>
  552. X-----------------------------------------------------------------------
  553. X
  554. XThe effect of the <BS>, <DEL>, CTRL-W and CTRL-U depends on the 'backspace' 
  555. Xoption (unless 'revins' is set):
  556. X
  557. Xbackspace    action
  558. X option
  559. X   0       delete stops in column 1 and start position of insert
  560. X   1       delete stops at start position of insert
  561. X   2       delete always, CTRL-W and CTRL-U stop once at start position of 
  562. X          insert
  563. X
  564. XIf the 'backspace' option is non-zero and the cursor is in column 1 when one 
  565. Xof the three keys is used, the current line is joined with the previous 
  566. Xline. This effectively deletes the newline in front of the cursor. {Vi: does 
  567. Xnot cross lines, does not delete past start position of insert}
  568. X
  569. XWith CTRL-V followed by one, two or three digits you can enter the decimal 
  570. Xvalue of a byte, except 10. Normally CTRL-V is followed by three digits. The 
  571. Xformed byte is inserted as soon as you type the third digit. If you type 
  572. Xonly one or two digits and then a non-digit, the decimal value of those one 
  573. Xor two digits form the byte. After that the non-digit is dealt with in the 
  574. Xnormal way. If you enter a value of 10, it will end up in the file as a 0.
  575. XThe 10 is a <LF>, which is used internally to represent the <NUL> character.
  576. XWhen writing the buffer to a file the <LF> character is translated into
  577. X<NUL>. The <LF> character is written at the end of each line. Thus if you
  578. Xwant to insert a <LF> character in a file you will have to make a line
  579. Xbreak.
  580. X
  581. X
  582. X4.3.2 special special keys
  583. X
  584. XThe following keys are special. They stop the current insert, do something 
  585. Xand then restart insertion. This means you can do something without getting 
  586. Xout of Insert mode. This is very handy if you prefer to use the Insert mode 
  587. Xall the time, just like editors that don't have a separate Command mode. You 
  588. Xmay also want to set the 'backspace' option to 2 and set the 'insertmode' 
  589. Xoption. You can use CTRL-O if you want to map a function key to a command.
  590. X
  591. XThe changes (inserted or deleted characters) before and after these keys can 
  592. Xbe undone separately. Only the last change can be redone and always behaves 
  593. Xlike an "i" command.
  594. X
  595. Xchar        action
  596. X-----------------------------------------------------------------------
  597. X<C_UP>        cursor one line up
  598. X<C_DOWN>    cursor one line down
  599. X<C_LEFT>    cursor one character left
  600. X<C_RIGHT>    cursor one character right
  601. X<SC_UP>        move window one page up
  602. X<SC_DOWN>    move window one page down
  603. X<SC_LEFT>    cursor one word back (like "b" command)
  604. X<SC_RIGHT>    cursor one word forward (like "w" command)
  605. XCTRL-O        execute one command and return to Insert mode
  606. X-----------------------------------------------------------------------
  607. X
  608. XThe CTRL-O command has one side effect: If the cursor was beyond the end of 
  609. Xthe line it will be put on the last character in the line.
  610. XThe shifted cursor keys are not available on all terminals.
  611. X
  612. XWhen the 'whichwrap' option is set appropriately, the <C_LEFT> and <C_RIGHT>
  613. Xkeys on the first/last character in the line make the cursor wrap to the
  614. Xprevious/next line.
  615. X
  616. X
  617. X4.3.3 'textwidth' and 'wrapmargin' option
  618. X
  619. XThe 'textwidth' option can be used to automatically break a line before it 
  620. Xgets too long. Set the 'textwidth' option to the desired maximum line 
  621. Xlength. If you then type more characters (not spaces or tabs), the 
  622. Xlast word will be put on a new line (unless it is the only word on the 
  623. Xline). If you set 'textwidth' to 0, this feature is disabled.
  624. X
  625. XThe 'wrapmargin' option does almost the same. The difference is that
  626. X'textwidth' has a fixed width while 'wrapmargin' depends on the width of the
  627. Xscreen. When using 'wrapmargin' this is equal to using 'textwidth' with a
  628. Xvalue equal to (columns - 'wrapmargin'), where columns is the width of the
  629. Xscreen.
  630. X
  631. XWhen 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used.
  632. X
  633. XThe line is only broken automatically when using insert mode, or when
  634. Xappending to a line. When in replace mode and the line length is not
  635. Xchanged, the line will not be broken.
  636. X
  637. XIf you want to format a block of text you can use the "Q" operator. Type "Q" 
  638. Xand a movement command to move the cursor to the end of the block. In many 
  639. Xcases the command "Q}" will do what you want (format until the end of 
  640. Xparagraph). Or you can use visual mode: hit "v", move to the end of the
  641. Xblock and hit "Q".
  642. X
  643. X
  644. X4.3.4 'expandtab' and 'smarttab' options
  645. X
  646. XIf the 'expandtab' option is set, spaces will be used to fill the amount of
  647. Xwhitespace of the tab. If you want to enter a real <TAB> type CTRL-V first.
  648. XThe 'expandtab' option is default off. Note that in Replace mode a single
  649. Xcharacter is replaced by several spaces. The result of this is that the
  650. Xnumber of characters in the line increases. Backspacing will delete one
  651. Xspace at a time. The original text will be put back in a place where you
  652. Xwould not expect it. {not in Vi}
  653. X
  654. XWhen the 'smarttab' option is set a TAB in front of a line inserts
  655. X'shiftwidth' positions, 'tabstop' in other places. This means that often
  656. Xspaces instead of a TAB character is inserted. When not set a TAB always
  657. Xinserts 'tabstop' positions, 'shiftwidth' is only used for ">>" and the like.
  658. X{not in Vi}
  659. X
  660. X
  661. X4.3.5 typing backwards
  662. X
  663. XIf the 'revins' (reverse insert) option is set, inserting happens backwards.
  664. XThis can be used to type Hebrew. When inserting characters the cursor is not
  665. Xmoved and the text moves rightwards. A <BS> deletes the character under the
  666. Xcursor. CTRL-W and CTRL-U also work in the opposite direction. <BS>, CTRL-W
  667. Xand CTRL-U do not stop at the start of insert or end of line, no matter how
  668. Xthe 'backspace' option is set.
  669. X
  670. XIn Replace mode the cursor is moved leftwards. <BS> will restore the
  671. Xcharacter right of the cursor.
  672. X
  673. XIn insert or Replace mode the 'revins' option can be toggled with CTRL-B.
  674. X
  675. XIf the 'showmode' option is set, "-- REVERSE INSERT --" or
  676. X"-- REVERSE REPLACE --" will be shown in the status line.
  677. X
  678. X
  679. X4.3.6 Replace mode
  680. X
  681. XIn Replace mode one character in the line is deleted for every character you 
  682. Xtype. If there is no character to delete (at the end of the line), the 
  683. Xtyped character is appended (as in Insert mode). Thus the number of 
  684. Xcharacters in a line stays the same until you get to the end of the line.
  685. X
  686. XBe careful with <TAB> characters. If you type a normal printing character in 
  687. Xits place, the number of characters is still the same, but the number of 
  688. Xcolumns will become smaller.
  689. X
  690. XIf you delete characters in Replace mode (with <BS>, <DEL>, CTRL-W or
  691. XCTRL-U), you really delete your changes. The characters that were replaced
  692. Xare restored. If you had typed past the existing text, the characters you
  693. Xadded are deleted.
  694. X    All this only works in the current line. If you have started a new line
  695. X(replaced a character with a <CR>) Vim no longer remembers what happened in
  696. Xthe previous line. If you backspace over the newline (only possible if the
  697. X'backspace' option is non-zero), the two lines will be joined again, but
  698. Xtyping further backspaces will not restore the original text. Only the
  699. Xcursor is moved.
  700. X    If the 'expandtab' option is set, a <TAB> will replace one character
  701. Xwith several spaces. When backspacing over these spaces, the original text
  702. Xwill appear in a position where you would not expect it.
  703. X
  704. X
  705. X4.3.7 Keyword completion
  706. X
  707. XIn insert and replace mode the keys CTRL-N and CTRL-P can be used to
  708. Xcomplete the keyword that is in front of the cursor. This is useful if you
  709. Xare writing a program that has complicated variable names, and you want to
  710. Xcopy a name from the text before of after the cursor.
  711. X
  712. XIf there is an identifier in front of the cursor (a name made out of
  713. Xalphanumeric characters and <_>) it is used as the search pattern, with "\<"
  714. Xprepended (meaning: start of a word). Otherwise "\<[a-zA-Z_]" is used as
  715. Xsearch pattern (start of any identifier).
  716. X
  717. XWith CTRL-N (next) the search goes forward, with CTRL-P (previous) the
  718. Xsearch goes backward. The first time the search starts where the cursor is.
  719. XThe next times the search starts at the last found position. If you type any
  720. Xother character than CTRL-P or CTRL-N the current text is accepted and the
  721. Xsearch pattern is forgotten.
  722. X
  723. XIf the search found a match, it is inserted at the cursor position. Any
  724. Xprevious match is replaced. If no match was found, Vim will beep.
  725. X
  726. XIf there is not a valid identifier character before the cursor, any
  727. Xidentifier is matched.
  728. X    eg. to get:
  729. X        printf("(%g, %g, %g)", vector[0], vector[1], vector[2]);
  730. X    just type:
  731. X        printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]);
  732. X
  733. XMultiple repeats of the same completion are skipped.
  734. X
  735. XIf there is only one completion found, then a second CTRL-P or CTRL-N will
  736. Xgive the message 'No other matches'.
  737. X
  738. XIf the only match in the file is an exact match, where no extra characters
  739. Xwould be typed, then the message 'Exact match only' is given (this is also
  740. Xuseful for checking that you typed the symbol correctly).
  741. X
  742. XThe mode (--INSERT--) is shown, unless there is another more important
  743. Xmessage (eg Pattern not found).  This other message will stay until another
  744. Xkey is hit, and then the mode is shown again.
  745. X
  746. XOnly matches where something extra will be added are used.
  747. X    eg. to get:
  748. X        printf("name = %s\n", name);
  749. X    just type:
  750. X        printf("name = %s\n", n^P);
  751. XThe 'n' in '\n' is skipped.
  752. X
  753. X
  754. X4.4 Command_line mode
  755. X
  756. XCommand_line mode is used to enter Ex commands <:>, search patterns </><?>
  757. Xand filter commands <!>.
  758. X
  759. X
  760. X4.4.1 Command line editing
  761. X
  762. XNormal characters are inserted in front of the cursor position. You can move
  763. Xaround in the command line with the left and right cursor keys. {Vi: can 
  764. Xonly alter the last character in the line}
  765. X
  766. XThe command lines that you enter are remembered in a history table. You can
  767. Xrecall them with the up and down cursor keys. Use the 'history' option to 
  768. Xset the number of lines that are remembered (default 20).
  769. X
  770. XThere is an automatic completion of names on the command line, see 4.4.2.
  771. X
  772. XCTRL-V        Insert next non-digit literally. Up to three digits form the 
  773. X        decimal value of a single byte. The non-digit and the three
  774. X        digits are not considered for mapping. This works the same
  775. X        way as in Insert mode (see above).
  776. X<C_LEFT>    cursor left
  777. X<C_RIGHT>    cursor right
  778. X<SC_LEFT>    cursor one word left
  779. X<SC_RIGHT>    cursor one word right
  780. XCTRL-B        cursor to begin of command line
  781. XCTRL-E        cursor to end of command line
  782. X
  783. X<BS>        delete the character in front of the cursor
  784. X<DEL>        delete the character under the cursor (at end of line:
  785. X        character in front of the cursor)
  786. XCTRL-W        delete the word in front of the cursor
  787. XCTRL-U        remove all characters
  788. X
  789. X        Note: if the command line becomes empty with one of the
  790. X        delete commands, command line mode is quit.
  791. X
  792. X{char1} <BS> {char2}    or
  793. XCTRL-K {char1} {char2}
  794. X        enter digraph (see 4.7). {not in Vi}
  795. X
  796. X<CR> or <LF>    start entered command
  797. X<ESC>        when typed: quit command line without executing
  798. X        in macros: start entered command
  799. XCTRL-C        quit command line without executing
  800. X
  801. X<C_UP>        recall older command line from history
  802. X<C_DOWN>    recall more recent command line from history
  803. X
  804. X<SC_UP>        recall older command line from history, which begin matches 
  805. X        the current command line (see below).
  806. X<SC_DOWN>    recall more recent command line from history, which begin 
  807. X        matches the current command line (see below).
  808. X
  809. XCTRL-D        command line completion (see 4.4.2)
  810. X'wildchar' option
  811. X        command line completion (see 4.4.2)
  812. XCTRL-N        command line completion (see 4.4.2)
  813. XCTRL-P        command line completion (see 4.4.2)
  814. XCTRL-A        command line completion (see 4.4.2)
  815. XCTRL-L        command line completion (see 4.4.2)
  816. X
  817. XThe <SC_UP> and <SC_DOWN> keys take the current command line as search 
  818. Xstring. The beginning of the next/previous command lines are compared against 
  819. Xthis string. The fist line that matches is the new command line. When typing 
  820. Xthese two keys repeatedly, the same string is used again. For example this 
  821. Xcan be used to find the previous substitute command: Type ":s" and then 
  822. X<SC_UP>. The same could be done by typing <C_UP> a number of times until the 
  823. Xdesired command line is shown. (Note: the shifted arrow keys do not work on
  824. Xall terminals) 
  825. X
  826. X
  827. X4.4.2 Command line completion
  828. X
  829. XWhen editing the command line a few commands can be used to complete the
  830. Xword before the cursor. This is available for:
  831. X
  832. X- Command names, at the start of the command line. Works always.
  833. X- tags, only after the ":tag" command.
  834. X- file names, only after a command that accepts a file name or a setting for
  835. X  an option that can be set to a file name. This is called file name
  836. X  completion.
  837. X- options, only after the ":set" command.
  838. X
  839. XThese are the commands that can be used:
  840. X
  841. XCTRL-D        List names that match the pattern in front of the cursor.
  842. X        When showing file names, directories are highlighted (see
  843. X        'highlight' option)
  844. X'wildchar' option
  845. X        A match is done on the pattern in front of the cursor. The
  846. X        match, or if there are several, the first match, is inserted
  847. X        in place of the pattern. (Note: does not work inside a
  848. X        macro, because TAB or ESC is mostly used as 'wildchar', and
  849. X        these have a special meaning in some macros)
  850. X        When typed again, and there were multiple matches, the next
  851. X        match is inserted. After the last match the first is used
  852. X        again (wrap around).
  853. XCTRL-N        After using 'wildchar' which got multiple matches: go to next
  854. X        match. Otherwise: Recall more recent command line from history.
  855. XCTRL-P        After using 'wildchar' which got multiple matches: go to
  856. X        previous match. Otherwise: Recall older command line from
  857. X        history.
  858. XCTRL-A        All names that match the pattern in front of the cursor are
  859. X        inserted.
  860. XCTRL-L        A match is done on the pattern in front of the cursor. If
  861. X        there is one match, it is inserted in place of the pattern.
  862. X        If there are multiple matches the longest common part is
  863. X        inserted in place of the pattern.
  864. X
  865. XThe 'wildchar' option defaults to <TAB> (CTRL-E when compiled with 
  866. XCOMPATIBLE; in a previous version <ESC> was used). In the pattern standard
  867. Xwildcards <*> and <?> are accepted. <*> matches any string, <?> matches
  868. Xexactly one character.
  869. X
  870. XFor filename completion you can use the 'suffixes' option to set a priority 
  871. Xbetween files with almost the same name. If there are multiple matches, 
  872. Xthose files with an extension that is in the 'suffixes' option are ignored.
  873. XThe default is ".bak.o.h.info.swp", which means that files with the
  874. Xextensions ".bak", ".o", ".h", ".info" and ".swp" are sometimes ignored. It
  875. Xis impossible to ignore suffixes with two dots. Examples:
  876. X
  877. Xpattern:    files:                match:
  878. Xtest*        test.c test.h test.o        test.c
  879. Xtest*        test.h test.o            test.h and test.o
  880. Xtest*        test.i test.h test.c        test.i and test.c
  881. X
  882. XIf there is more than one matching file (after ignoring the ones matching
  883. Xthe 'suffixes' option) the first file name is inserted. You can see that
  884. Xthere is only one match when you type 'wildchar' twice and the completed
  885. Xmatch stays the same. You can get to the other matches by entering
  886. X'wildchar', CTRL-N or CTRL-P. All files are included, also the ones with
  887. Xextensions matching the 'suffixes' option.
  888. X
  889. X
  890. X4.4.3 Ex command lines
  891. X
  892. XThe Ex commands have a few specialties:
  893. X
  894. X<"> at the start of a line causes the whole line to be ignored. <"> 
  895. Xafter a command causes the rest of the line to be ignored. This can be used 
  896. Xto add comments. Example:
  897. X    :set ai     "set 'autoindent' option
  898. XIt is not possible to add a comment to a shell command ":!cmd" or to the
  899. X":map" command and friends, because they see the <"> as part of their
  900. Xargument.
  901. X
  902. X<|> can be used to separate commands, so you can give multiple commands in 
  903. Xone line. The commands ":global", "vglobal" and  ":!" see the <|> as their
  904. Xargument, and can therefore not be followed by another command. If you want
  905. X<|> to be included in a command, precede it with <\>. Note that this is
  906. Xconfusing (inherited from vi). If you give a command with ":!" you don't
  907. Xhave to use a backslash, with ":r !" you have to. And with ":g" the <|> is
  908. Xincluded in the command, with ":s" it is not. Examples:
  909. X    :!ls | wc        view the output of two commands
  910. X    :r !ls \| wc        insert the same output in the text
  911. X    :%g/foo/p|>        moves all matching lines one shiftwidth
  912. X    :%s/foo/bar/|>        moves one line one shiftwidth
  913. XYou can also use <LF> to separate commands in the same way as with <|>. But
  914. Xusing <|> is the preferred method.
  915. X
  916. XWhen the character <%> or <#> is used where a filename is expected, they are 
  917. Xexpanded to the current and alternate filename (see the chapter "editing 
  918. Xfiles").
  919. X
  920. XEmbedded spaces in filenames are allowed if one filename is expected as
  921. Xargument. Trailing spaces will be ignored, unless escaped with a backslash
  922. Xor CTRL-V. Note that the ":next" command uses spaces to separate file names.
  923. XEscape the spaces to include them in a file name. Example:
  924. X    :next foo\ bar goes\ to school\ 
  925. Xstarts editing the three files "foo bar", "goes to" and "school ".
  926. X
  927. XWhen you want to use the special characters <"> or  <|> in a command, or want
  928. Xto use <%> or <#> in a filename, precede them with a backslash. The backslash
  929. Xis not required in a range and in the ":substitute" command.
  930. X
  931. X
  932. X4.4.4 Ex command line ranges
  933. X
  934. XSome Ex commands accept a line range in front of them. This is noted as
  935. X[range]. It consists of one or more line specifiers, separated with <,> or 
  936. X<;>. When separated with <;> the cursor position will be set to that line 
  937. Xbefore interpreting the next line specifier. The default line specifier for 
  938. Xmost commands is the cursor position, but the commands ":write" and 
  939. X":global" have the whole file (1,$) as default. If more line specifiers are 
  940. Xgiven than required for the command, the first one(s) will be ignored.
  941. X
  942. XLine numbers may be specified with:
  943. X    {number}    an absolute line number
  944. X    .        the current line
  945. X    $        the last line in the file
  946. X    %        equal to 1,$ (the entire file)
  947. X    't        position of mark t (lower case)
  948. X    /{pattern}[/]    the next line where {pattern} matches
  949. X    ?{pattern}[?]    the previous line where {pattern} matches
  950. X
  951. XEach may be followed (several times) by <+> or <-> and an optional number. 
  952. XThis number is added or subtracted from the preceding line number. If the 
  953. Xnumber is omitted, 1 is used.
  954. X
  955. XThe "/" and "?" may be preceded with another address. The search starts from
  956. Xthere. The "/" and "?" after {pattern} are required to separate the pattern
  957. Xfrom anything that follows.
  958. X
  959. XThe {number} must be between 0 and the number of lines in the file. A 0 is 
  960. Xinterpreted as a 1, except with the commands tag, pop and read.
  961. X
  962. XExamples:
  963. X    .+3        three lines below the cursor
  964. X    /that/+1    the line below the next line containing "that"
  965. X    .,$        from current line until end of file
  966. X    0/that        the first line containing "that"
  967. X
  968. XSome commands allow for a count after the command. This count is used as the
  969. Xnumber of lines to be used, starting with the line given in the last line
  970. Xspecifier (the default is the cursor line). The commands that accept a count
  971. Xare the ones that use a range but do not have a file name argument (because
  972. Xa file name can also be a number).
  973. X
  974. XExamples:
  975. X    :s/x/X/g 5    substitute <x> by <X> in the current line and four
  976. X            following lines
  977. X    :23d 4        delete lines 23, 24, 25 and 26
  978. X
  979. XA range should have the lower line number first. If this is not the case, Vim
  980. Xwill ask you if it should swap the line numbers. This is not done within the
  981. Xglobal command ":g".
  982. X
  983. XWhen giving a count before entering ":", this is translated into:
  984. X        :.,.+(count - 1)
  985. XIn words: The 'count' lines at and after the cursor. Example: To delete
  986. Xthree lines:
  987. X        3:d<CR>        is translated into: .,.+2d<CR>
  988. X
  989. X
  990. X4.5 The window contents
  991. X
  992. XIn command and Insert/Replace mode the screen window will show the current
  993. Xcontents of the buffer: What You See Is What You Get. {Vi: when changing 
  994. Xtext a <$> is placed on the last changed character; The window is not always 
  995. Xupdated on slow terminals} Lines longer than the window width will wrap,
  996. Xunless the 'wrap' option is off (see below). The bottom lines in the window
  997. Xmay start with one of these two characters:
  998. X
  999. X<@>     The next line is too long to fit in the window.
  1000. X<~>    Below the last line in the buffer.
  1001. X
  1002. XIf the bottom line is completely filled with <@>, the line that is at the 
  1003. Xtop of the window is too long to fit in the window. If the cursor is on this 
  1004. Xline you can't see what you are doing, because this part of the line is not 
  1005. Xshown. However, the part of the line before the <@>s can be edited normally. 
  1006. X{Vi: gives an "internal error" on lines that do not fit in the window}
  1007. X
  1008. XIf the 'wrap' option is off, long lines will not wrap. Only the part that
  1009. Xfits on the screen is shown. If the cursor is moved to a part of the line
  1010. Xthat is not shown, the screen is scrolled horizontally. The advantage of
  1011. Xthis method is that columns are shown as they are and lines that cannot fit
  1012. Xon the screen can be edited. The disadvantage is that you cannot see all the
  1013. Xcharacters of a line at once. The 'sidescroll' option can be set to the
  1014. Xminimal number of columns to scroll. {Vi: has no 'wrap' option}
  1015. X
  1016. XAll normal ASCII characters are displayed directly on the screen. The <TAB> 
  1017. Xis replaced by the number of spaces that it represents. Other non-printing 
  1018. Xcharacters are replaced by "^<char>", where <char> is the non-printing 
  1019. Xcharacter with 64 added. Thus character 7 (bell) will be shown as "^G". 
  1020. XCharacters between 127 and 160 are replaced by "~<char>", where <char> is 
  1021. Xthe character with 64 subtracted. These characters occupy more than one 
  1022. Xposition on the screen. The cursor can only be positioned on the first one.
  1023. X
  1024. XIf you set the 'number' option, all lines will be preceded with their 
  1025. Xnumber.
  1026. X
  1027. XIf you set the 'list' option, <TAB> characters will not be shown as several
  1028. Xspaces, but as "^I". A <$> will be placed at the end of the line, so you can
  1029. Xfind trailing blanks.
  1030. X
  1031. XIn Command_line mode only the command line itself is shown correctly. The
  1032. Xdisplay of the buffer contents is updated as soon as you go back to Command
  1033. Xmode.
  1034. X
  1035. XSome commands hand over the window to external commands (e.g. ":shell" and
  1036. X"="). After these commands are finished the window may be clobbered with 
  1037. Xoutput from the external command, so it needs to be redrawn. This is also 
  1038. Xthe case if something is displayed on the status line that is longer than 
  1039. Xthe width of the window. If you are expected to have a look at the screen 
  1040. Xbefore it is redrawn, you get this message:
  1041. X
  1042. X        Press RETURN or enter command to continue
  1043. X
  1044. XAfter you type a key the screen will be redrawn and Vim continues. If you 
  1045. Xtype <CR>, <SP> or <LF> nothing else happens. If you type any other key, it 
  1046. Xwill be interpreted as (the start of) a new command. {Vi: only <:> commands 
  1047. Xare interpreted}
  1048. X
  1049. XThe last line of the window is used for status and other messages. The 
  1050. Xstatus messages will only be used if an option is on:
  1051. X
  1052. Xstatus message            option        default    unix default
  1053. Xcurrent mode             'showmode'    on        on
  1054. Xcommand characters        'showcmd'    on        off
  1055. Xcursor position            'ruler'        off        off
  1056. X
  1057. XThe current mode is "-- INSERT --" or "-- REPLACE --". The command 
  1058. Xcharacters are those that you typed but were not used yet. {Vi: does not
  1059. Xshow the characters you typed or the cursor position}
  1060. X
  1061. XIf you have a slow terminal you can switch off the status messages to speed 
  1062. Xup editing:
  1063. X    :set nosc noru nosm
  1064. X
  1065. XIf there is an error, an error message will be shown for at least one second 
  1066. X(in reverse video). {Vi: error messages may be overwritten with other 
  1067. Xmessages before you have a chance to read them}
  1068. X
  1069. XSome commands show how many lines were affected. Above which threshold this
  1070. Xhappens can be controlled with the 'report' option (default 2).
  1071. X
  1072. XOn the Amiga Vim will run in a CLI window. The name Vim and the full name of
  1073. Xthe current filename will be shown in the title bar. When the window is
  1074. Xresized, Vim will automatically redraw the window. You may make the window as
  1075. Xsmall as you like, but if it gets too small not a single line will fit in it.
  1076. XMake it at least 40 characters wide to be able to read most messages on the
  1077. Xlast line.
  1078. X
  1079. XOn most Unix systems window resize works ok.  {Vi: not ok}
  1080. X
  1081. X
  1082. X4.6 Abbreviations
  1083. X
  1084. XAbbreviations are used in insert mode, Replace mode and Command_line mode.
  1085. XIf you enter a word that is an abbreviation, it is replaced by the word it
  1086. Xstands for. This can be used to save typing for often used long words.
  1087. X
  1088. XThere are two types of abbreviations: The "full-id" type consists entirely
  1089. Xof id characters (letters, digits and <_> characters). This is the most
  1090. Xcommon abbreviation. The "non-id" type ends in an id character, but all the
  1091. Xother characters are not id characters. Examples of a "full-id" type are
  1092. X"foo" and "c_1". Examples of a "non-id" type are "#i" and "$/7". Examples of
  1093. Xstrings that will not be recognized as an abbreviation are "a.b", "a b" and
  1094. X"_$ar".
  1095. X
  1096. XThe "full-id" abbreviation is recognized if:
  1097. X- A character is typed that is not an id character. This can also be
  1098. X  the <ESC> that ends insert mode or the <CR> that ends a command.
  1099. X- The characters in front of the cursor match the abbreviation.
  1100. X- In front of the match is a non-id character, or this is where the line or
  1101. X  insertion starts. Exception: when the abbreviation is only one character,
  1102. X  it is not recognized if there is a non-id character in front of it, other
  1103. X  than a space or a TAB.
  1104. X
  1105. XThe "non-id" abbreviation is recognized if:
  1106. X- A character is typed that is not an id character. This can also be
  1107. X  the <ESC> that ends insert mode or the <CR> that ends a command.
  1108. X- The characters in front of the cursor match the abbreviation.
  1109. X- In front of the match is an id character, or a space or a TAB, or this is
  1110. X  where the line or insertion starts.
  1111. X
  1112. XExample: ":ab foo four old otters". Note that spaces in the <rhs> are
  1113. Xallowed and included in the replacement string. If you now insert the word
  1114. X"foo" with a space before and after it, it will be replaced by "four old
  1115. Xotters". If you would type "foobar" or "barfoo" nothing happens.
  1116. X
  1117. XTo avoid the abbreviation in insert mode type part of the abbreviation, exit
  1118. Xinsert mode with <ESC>, re-enter insert mode with "a" and type the rest. In
  1119. XCommand_line mode you can type CTRL-V twice somewhere in the abbreviation to
  1120. Xavoid it to be replaced. A CTRL-V in front of a normal character is mostly
  1121. Xignored otherwise.
  1122. X
  1123. XThere are no default abbreviations.
  1124. X
  1125. XAbbreviations are never recursive. You can use ":ab f f-o-o" without any
  1126. Xproblem. But abbreviations can be mapped. {some versions of vi support
  1127. Xrecursive abbreviations, for no apparent reason}
  1128. X
  1129. XAbbreviations are disabled if the 'paste' option is set.
  1130. X
  1131. X:ab[breviate]        list all abbreviations. The character in the first
  1132. X            column indicates the mode where the abbreviation is
  1133. X            used: 'i' for insert mode, 'c' for Command_line
  1134. X            mode, '!' for both.
  1135. X
  1136. X:ab[breviate] <lhs>    list the abbreviations that start with <lhs>
  1137. X
  1138. X:ab[breviate] <lhs> <rhs>
  1139. X            add abbreviation for <lhs> to <rhs>. If <lhs> already
  1140. X            existed it is replaced with the new <rhs>. <rhs> may
  1141. X            contain spaces.
  1142. X
  1143. X:una[bbreviate] <lhs>    remove abbreviation for <lhs> from the list
  1144. X
  1145. X:norea[bbrev] [lhs] [rhs]
  1146. X            same as ":ab", but no remapping for this <rhs> {not
  1147. X            in Vi}
  1148. X
  1149. X:ca[bbrev] [lhs] [rhs]    same as ":ab", but for Command_line mode only. {not
  1150. X            in Vi}
  1151. X
  1152. X:cuna[bbrev] <lhs>    same as ":una", but for Command_line mode only. {not
  1153. X            in Vi}
  1154. X
  1155. X:cnorea[bbrev] [lhs] [rhs]
  1156. X            same as ":ab", but for Command_line mode only and no
  1157. X            remapping for this <rhs> {not in Vi}
  1158. X
  1159. X:ia[bbrev] [lhs] [rhs]    same as ":ab", but for insert mode only. {not in Vi}
  1160. X
  1161. X:iuna[bbrev] <lhs>    same as ":una", but for insert mode only. {not in
  1162. X            Vi}
  1163. X
  1164. X:inorea[bbrev] [lhs] [rhs]
  1165. X            same as ":ab", but for insert mode only and no
  1166. X            remapping for this <rhs> {not in Vi}
  1167. X
  1168. X
  1169. X4.7 Digraphs
  1170. X
  1171. X:dig[raphs]        show currently defined digraphs. {not in Vi}
  1172. X
  1173. X:dig[raphs] {char1}{char2} {number} ...
  1174. X            Add digraph {char1}{char2} to the list. {number} is 
  1175. X            the decimal representation of the character.
  1176. X
  1177. XDigraphs are used to enter characters that normally cannot be entered by 
  1178. Xan ordinary keyboard. These are mostly accented characters which have the 
  1179. Xeighth bit set. The digraphs are easier to remember than the decimal number
  1180. Xthat can be entered with CTRL-V (see above).
  1181. X
  1182. XVim must have been compiled with the 'digraphs' option enabled. If not, the 
  1183. X":digraph" command will display an error message.
  1184. X
  1185. XThere are two methods to enter digraphs:
  1186. X    CTRL-K {char1} {char2}        or
  1187. X    {char1} <BS> {char2}
  1188. XThe first is always available. The second only when the 'digraph' option is 
  1189. Xset.
  1190. X
  1191. XOnce you have entered the digraph the character is treated like a normal 
  1192. Xcharacter, taking up only one character in the file and on the screen. 
  1193. XExample:
  1194. X    <|> <BS> <|>    will enter the double <|> character (166)
  1195. X    <a> <BS> <^>    will enter an <a> with a hat (226)
  1196. X    CTRL-K <-> <->    will enter a minus sign (173)
  1197. X
  1198. XThe default digraphs are listed in the file digraph.doc. They are meant for 
  1199. Xthe Amiga character set, which is some international standard. With another 
  1200. Xcharacter set they may be illogical.
  1201. X
  1202. XFor CTRL-K there is one general digraph: CTRL-K <SPACE> {char} will enter
  1203. X{char} with the highest bit set. This can be used to enter meta-characters.
  1204. X
  1205. XThe <ESC> character cannot be part of a digraph. When hitting <ESC> entering
  1206. Xthe digraph is aborted and insert mode too.
  1207. X
  1208. XIf you accidently typed an <a> that should be an <e>, you will type <a> <BS> 
  1209. X<e>. But that is a digraph, so you will not get what you want. To avoid this, 
  1210. Xuse <DEL> instead of <BS>. Or don't set the 'digraph' option and use CTRL-K
  1211. Xto enter digraphs.
  1212. X
  1213. X
  1214. X    5. Editing files
  1215. X
  1216. X5.1 Introduction
  1217. X
  1218. XEditing a file with Vim means:
  1219. X
  1220. X1. reading the file into the internal buffer
  1221. X2. changing the buffer with editor commands
  1222. X3. writing the buffer into a file
  1223. X
  1224. XAs long as you don't write the buffer, the original file remains unchanged. 
  1225. XIf you start editing a file (read a file into the buffer), the file name is 
  1226. Xremembered as the "current filename".
  1227. X
  1228. XIf there already was a current filename, then that one becomes the alternate
  1229. Xfile name. All filenames are remembered in the file list. When you enter a
  1230. Xfilename, for editing (e.g. with ":e filename") or writing (e.g. with (:w
  1231. END_OF_FILE
  1232.   if test 52085 -ne `wc -c <'vim/doc/reference.doc.A'`; then
  1233.     echo shar: \"'vim/doc/reference.doc.A'\" unpacked with wrong size!
  1234.   elif test -f 'vim/doc/reference.doc.B' && test -f 'vim/doc/reference.doc.C' && test -f 'vim/doc/reference.doc.D'; then
  1235.     echo shar: Combining  \"'vim/doc/reference.doc'\" \(210836 characters\)
  1236.     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'
  1237.     if test 210836 -ne `wc -c <'vim/doc/reference.doc'`; then
  1238.       echo shar: \"'vim/doc/reference.doc'\" combined with wrong size!
  1239.     else
  1240.       rm vim/doc/reference.doc.A vim/doc/reference.doc.B vim/doc/reference.doc.C vim/doc/reference.doc.D
  1241.     fi
  1242.   fi
  1243.   # end of 'vim/doc/reference.doc.A'
  1244. fi
  1245. if test -f 'vim/src/archie.c' -a "${1}" != "-c" ; then 
  1246.   echo shar: Will not clobber existing file \"'vim/src/archie.c'\"
  1247. else
  1248.   echo shar: Extracting \"'vim/src/archie.c'\" \(13434 characters\)
  1249.   sed "s/^X//" >'vim/src/archie.c' <<'END_OF_FILE'
  1250. X/* vi:ts=4:sw=4
  1251. X *
  1252. X *
  1253. X * VIM - Vi IMproved
  1254. X *
  1255. X * Code Contributions By:    Bram Moolenaar            mool@oce.nl
  1256. X *                            Tim Thompson            twitch!tjt
  1257. X *                            Tony Andrews            onecom!wldrdg!tony 
  1258. X *                            G. R. (Fred) Walter        watmath!watcgl!grwalter 
  1259. X */
  1260. X/*
  1261. X * archie.c -- RISC OS + UnixLib specific code.
  1262. X *
  1263. X * A lot of this file was written by Juergen Weigert.
  1264. X *
  1265. X * It was then hacked to pieces by Alun Jones to work on the Acorn
  1266. X * Archimedes!
  1267. X */
  1268. X
  1269. X#include "vim.h"
  1270. X#include "globals.h"
  1271. X#include "param.h"
  1272. X#include "proto.h"
  1273. X
  1274. X#include <fcntl.h>
  1275. X#include <time.h>
  1276. X#include <unistd.h>
  1277. X#include <sys/types.h>
  1278. X#include <sys/os.h>
  1279. X#include <signal.h>
  1280. X
  1281. X#include <termio.h>
  1282. X
  1283. Xstatic int    Read __ARGS((char *, long));
  1284. Xstatic int    WaitForChar __ARGS((int));
  1285. Xstatic int    RealWaitForChar __ARGS((int));
  1286. Xstatic void fill_inbuf __ARGS((void));
  1287. X
  1288. Xstatic int do_resize = FALSE;
  1289. X
  1290. X/* I'm sure this should be defined in UnixLib, but it ain't!
  1291. X */
  1292. Xshort ospeed;
  1293. X
  1294. X    void
  1295. Xmch_write(s, len)
  1296. X    char    *s;
  1297. X    int        len;
  1298. X{
  1299. X    int i;
  1300. X    for (i=0; i<len; i++)
  1301. X    {
  1302. X        os_vdu(s[i]);
  1303. X    }
  1304. X}
  1305. X
  1306. X/*
  1307. X * GetChars(): low level input funcion.
  1308. X * Get a characters from the keyboard.
  1309. X * If time == 0 do not wait for characters.
  1310. X * If time == n wait a short time for characters.
  1311. X * If time == -1 wait forever for characters.
  1312. X */
  1313. X    int
  1314. XGetChars(buf, maxlen, time)
  1315. X    char    *buf;
  1316. X    int        maxlen;
  1317. X    int        time;
  1318. X{
  1319. X    if (time >= 0)
  1320. X    {
  1321. X        if (WaitForChar(time) == 0)        /* no character available */
  1322. X            return 0;
  1323. X    }
  1324. X    else        /* time == -1 */
  1325. X    {
  1326. X    /*
  1327. X     * If there is no character available within 2 seconds (default)
  1328. X     * write the autoscript file to disk
  1329. X     */
  1330. X        if (WaitForChar((int)p_ut) == 0)
  1331. X            updatescript(0);
  1332. X    }
  1333. X
  1334. X    WaitForChar(-1);
  1335. X    return Read(buf, (long)maxlen);
  1336. X}
  1337. X
  1338. X    void
  1339. Xvim_delay()
  1340. X{
  1341. X    clock_t    now;
  1342. X
  1343. X    now = clock();
  1344. X    while (clock() < now + CLOCKS_PER_SEC/2);
  1345. X}
  1346. X
  1347. X/*
  1348. X * No job control. Fake it by starting a new shell.
  1349. X */
  1350. X    void
  1351. Xmch_suspend()
  1352. X{
  1353. X    outstr("new shell started\n");
  1354. X    call_shell(NULL, 0, 1);
  1355. X}
  1356. X
  1357. X    void
  1358. Xmch_windinit()
  1359. X{
  1360. X    Columns = 80;
  1361. X    Rows = 24;
  1362. X
  1363. X    flushbuf();
  1364. X
  1365. X    mch_get_winsize();
  1366. X}
  1367. X
  1368. X/*
  1369. X * Check_win checks whether we have an interactive window.
  1370. X */
  1371. X
  1372. X    void
  1373. Xcheck_win(argc, argv)
  1374. X    int argc;
  1375. X    char **argv;
  1376. X{
  1377. X    if (!isatty(0) || !isatty(1))
  1378. X    {
  1379. X        fprintf(stderr, "VIM: no controlling terminal\n");
  1380. X        exit(2);
  1381. X    }
  1382. X}
  1383. X
  1384. X/*
  1385. X * fname_case(): Set the case of the filename, if it already exists.
  1386. X *                 This will cause the filename to remain exactly the same.
  1387. X */
  1388. X    void
  1389. Xfname_case(name)
  1390. X    char *name;
  1391. X{
  1392. X}
  1393. X
  1394. X    void
  1395. Xsettitle(str)
  1396. X    char *str;
  1397. X{
  1398. X}
  1399. X
  1400. X    void
  1401. Xresettitle()
  1402. X{
  1403. X}
  1404. X
  1405. X/*
  1406. X * Get name of current directory into buffer 'buf' of length 'len' bytes.
  1407. X * Return non-zero for success.
  1408. X */
  1409. X    int 
  1410. Xdirname(buf, len)
  1411. X    char *buf;
  1412. X    int len;
  1413. X{
  1414. X    extern int        errno;
  1415. X    extern char        *sys_errlist[];
  1416. X
  1417. X    if (getcwd(buf,len) == NULL)
  1418. X    {
  1419. X        strcpy(buf, sys_errlist[errno]);
  1420. X        return 0;
  1421. X    }
  1422. X    return 1;
  1423. X}
  1424. X
  1425. X/*
  1426. X * get absolute filename into buffer 'buf' of length 'len' bytes
  1427. X */
  1428. X    int 
  1429. XFullName(fname, buf, len)
  1430. X    char *fname, *buf;
  1431. X    int len;
  1432. X{
  1433. X    int        l;
  1434. X    char    olddir[MAXPATHL];
  1435. X    char    *p;
  1436. X    int        c;
  1437. X    int        retval = 1;
  1438. X
  1439. X    if (fname == NULL)    /* always fail */
  1440. X        return 0;
  1441. X
  1442. X    *buf = 0;
  1443. X    if (*fname != '/')
  1444. X    {
  1445. X        /*
  1446. X         * If the file name has a path, change to that directory for a moment,
  1447. X         * and then do the getwd() (and get back to where we were).
  1448. X         * This will get the correct path name with "../" things.
  1449. X         */
  1450. X        if ((p = strrchr(fname, '/')) != NULL)
  1451. X        {
  1452. X            if (getcwd(olddir, MAXPATHL) == NULL)
  1453. X            {
  1454. X                p = NULL;        /* can't get current dir: don't chdir */
  1455. X                retval = 0;
  1456. X            }
  1457. X            else
  1458. X            {
  1459. X                c = *p;
  1460. X                *p = NUL;
  1461. X                chdir("\\");        /* Try to maintain PSD */
  1462. X                if (chdir(fname))
  1463. X                    retval = 0;
  1464. X                else
  1465. X                    fname = p + 1;
  1466. X                *p = c;
  1467. X            }
  1468. X        }
  1469. X        if (getcwd(buf, len) == NULL)
  1470. X        {
  1471. X            retval = 0;
  1472. X            *buf = NUL;
  1473. X        }
  1474. X        l = strlen(buf);
  1475. X        if (l && buf[l - 1] != '/')
  1476. X            strcat(buf, "/");
  1477. X        if (p)
  1478. X        {
  1479. X            chdir("\\");            /* Maintain PSD */
  1480. X            chdir(olddir);
  1481. X        }
  1482. X    }
  1483. X    strcat(buf, fname);
  1484. X    return retval;
  1485. X}
  1486. X
  1487. X/*
  1488. X * get file permissions for 'name'
  1489. X */
  1490. X    long 
  1491. Xgetperm(name)
  1492. X    char *name;
  1493. X{
  1494. X    struct stat statb;
  1495. X
  1496. X    if (stat(name, &statb))
  1497. X        return -1;
  1498. X    return statb.st_mode;
  1499. X}
  1500. X
  1501. X/*
  1502. X * set file permission for 'name' to 'perm'
  1503. X */
  1504. X    int
  1505. Xsetperm(name, perm)
  1506. X    char *name;
  1507. X    int perm;
  1508. X{
  1509. X    return chmod(name, perm);
  1510. X}
  1511. X
  1512. X/*
  1513. X * check if "name" is a directory
  1514. X */
  1515. X    int 
  1516. Xisdir(name)
  1517. X    char *name;
  1518. X{
  1519. X    struct stat statb;
  1520. X
  1521. X    if (stat(name, &statb))
  1522. X        return -1;
  1523. X    return (statb.st_mode & S_IFMT) == S_IFDIR;
  1524. X}
  1525. X
  1526. X    void
  1527. Xmch_windexit(r)
  1528. X    int r;
  1529. X{
  1530. X    settmode(0);
  1531. X    stoptermcap();
  1532. X    flushbuf();
  1533. X    stopscript();                    /* remove autoscript file */
  1534. X    exit(r);
  1535. X}
  1536. X
  1537. X    void
  1538. Xmch_settmode(raw)
  1539. X    int                raw;
  1540. X{
  1541. X    static    int old225, old226, old4;
  1542. X    int        retvals[3];
  1543. X    static struct termio told;
  1544. X           struct termio tnew;
  1545. X
  1546. X    if (raw)
  1547. X    {
  1548. X        /* Make arrow keys act as function keys.
  1549. X         */
  1550. X        os_byte(4, 2, 0, retvals);
  1551. X        old4 = retvals[1];
  1552. X        /* Now make function keys return NULL followed by a character.
  1553. X         * Remember the old value for resetting.
  1554. X         */
  1555. X        os_byte(225, 0xC0, 0, retvals);
  1556. X        old225 = retvals[1];
  1557. X        os_byte(226, 0xD0, 0, retvals);
  1558. X        old226 = retvals[1];
  1559. X
  1560. X        ioctl(0, TCGETA, &told);
  1561. X        tnew = told;
  1562. X        tnew.c_iflag &= ~(ICRNL | IXON);        /* ICRNL enables typing ^V^M */
  1563. X                                                /* IXON enables typing ^S/^Q */
  1564. X        tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE);
  1565. X        tnew.c_cc[VMIN] = 1;            /* return after 1 char */
  1566. X        tnew.c_cc[VTIME] = 0;            /* don't wait */
  1567. X        ioctl(0, TCSETA, &tnew);
  1568. X    }
  1569. X    else
  1570. X    {
  1571. X        os_byte(4, old4, 0, retvals);
  1572. X        os_byte(225, old225, 0, retvals);
  1573. X        os_byte(226, old226, 0, retvals);
  1574. X        ioctl(0, TCSETA, &told);
  1575. X    }
  1576. X}
  1577. X
  1578. X/*
  1579. X * Try to get the current window size:
  1580. X * 1. with an ioctl(), most accurate method
  1581. X * 2. from the environment variables LINES and COLUMNS
  1582. X * 3. from the termcap
  1583. X * 4. keep using the old values
  1584. X */
  1585. X    int
  1586. Xmch_get_winsize()
  1587. X{
  1588. X    int            old_Rows = Rows;
  1589. X    int            old_Columns = Columns;
  1590. X    char        *p;
  1591. X
  1592. X    Columns = 0;
  1593. X    Rows = 0;
  1594. X
  1595. X/*
  1596. X * 1. try using an ioctl. It is the most accurate method.
  1597. X */
  1598. X    {
  1599. X        struct winsize    ws;
  1600. X
  1601. X        if (ioctl(0, TIOCGWINSZ, &ws) == 0)
  1602. X        {
  1603. X            Columns = ws.ws_col;
  1604. X            Rows = ws.ws_row;
  1605. X        }
  1606. X    }
  1607. X
  1608. X/*
  1609. X * 2. get size from environment
  1610. X */
  1611. X    if (Columns == 0 || Rows == 0)
  1612. X    {
  1613. X        if ((p = (char *)getenv("LINES")))
  1614. X            Rows = atoi(p);
  1615. X        if ((p = (char *)getenv("COLUMNS")))
  1616. X            Columns = atoi(p);
  1617. X    }
  1618. X
  1619. X/*
  1620. X * 3. try reading the termcap
  1621. X */
  1622. X    if (Columns == 0 || Rows == 0)
  1623. X    {
  1624. X        extern void getlinecol();
  1625. X
  1626. X        getlinecol();    /* get "co" and "li" entries from termcap */
  1627. X    }
  1628. X
  1629. X/*
  1630. X * 4. If everything fails, use the old values
  1631. X */
  1632. X    if (Columns <= 0 || Rows <= 0)
  1633. X    {
  1634. X        Columns = old_Columns;
  1635. X        Rows = old_Rows;
  1636. X        return 1;
  1637. X    }
  1638. X    debug2("mch_get_winsize: %dx%d\n", (int)Columns, (int)Rows);
  1639. X
  1640. X    Rows_max = Rows;                /* remember physical max height */
  1641. X
  1642. X    check_winsize();
  1643. X    script_winsize();
  1644. X
  1645. X/* if size changed: screenalloc will allocate new screen buffers */
  1646. X    return (0);
  1647. X}
  1648. X
  1649. X    void
  1650. Xmch_set_winsize()
  1651. X{
  1652. X    /* should try to set the window size to Rows and Columns */
  1653. X}
  1654. X
  1655. X    int 
  1656. Xcall_shell(cmd, dummy, cooked)
  1657. X    char    *cmd;
  1658. X    int        dummy;
  1659. X    int        cooked;
  1660. X{
  1661. X    int        x;
  1662. X    char    newcmd[1024];
  1663. X
  1664. X    flushbuf();
  1665. X
  1666. X    if (cooked)
  1667. X        settmode(0);                 /* set to cooked mode */
  1668. X
  1669. X    if (cmd == NULL)
  1670. X        x = system(p_sh);
  1671. X    else
  1672. X    {
  1673. X        sprintf(newcmd, "*%s", cmd);
  1674. X        x = system(newcmd);
  1675. X    }
  1676. X    if (x == 127)
  1677. X    {
  1678. X        emsg("Cannot execute shell sh");
  1679. X        outchar('\n');
  1680. X    }
  1681. X    else if (x)
  1682. X    {
  1683. X        smsg("%d returned", x);
  1684. X        outchar('\n');
  1685. X    }
  1686. X
  1687. X    if (cooked)
  1688. X        settmode(1);                         /* set to raw mode */
  1689. X    return x;
  1690. X
  1691. X}
  1692. X
  1693. X/*
  1694. X * The input characters are buffered to be able to check for a CTRL-C.
  1695. X * This should be done with signals, but I don't know how to do that in
  1696. X * a portable way for a tty in RAW mode.
  1697. X */
  1698. X
  1699. X#define INBUFLEN 50
  1700. Xstatic unsigned char        inbuf[INBUFLEN];    /* internal typeahead buffer */
  1701. Xstatic int                    inbufcount = 0;        /* number of chars in inbuf[] */
  1702. X
  1703. X    static int
  1704. XRead(buf, maxlen)
  1705. X    char    *buf;
  1706. X    long    maxlen;
  1707. X{
  1708. X    if (inbufcount == 0)        /* if the buffer is empty, fill it */
  1709. X        fill_inbuf();
  1710. X    if (maxlen > inbufcount)
  1711. X        maxlen = inbufcount;
  1712. X    memmove(buf, inbuf, maxlen);
  1713. X    inbufcount -= maxlen;
  1714. X    if (inbufcount)
  1715. X        memmove(inbuf, inbuf + maxlen, inbufcount);
  1716. X    return (int)maxlen;
  1717. X}
  1718. X
  1719. X    void
  1720. Xbreakcheck()
  1721. X{
  1722. X/*
  1723. X * check for CTRL-C typed by reading all available characters
  1724. X */
  1725. X    if (RealWaitForChar(0))        /* if characters available */
  1726. X        fill_inbuf();
  1727. X}
  1728. X
  1729. X    static void
  1730. Xfill_inbuf()
  1731. X{
  1732. X    int        len;
  1733. X
  1734. X    if (inbufcount >= INBUFLEN)        /* buffer full */
  1735. X        return;
  1736. X
  1737. X    for (len=0; len < INBUFLEN-inbufcount; len++)
  1738. X    {
  1739. X        int key;
  1740. X
  1741. X        key = os_inkey(0);
  1742. X        if (key==-1)
  1743. X        {
  1744. X            break;
  1745. X        }
  1746. X        inbuf[inbufcount+len] = key;
  1747. X    }
  1748. X
  1749. X    while (len-- > 0)
  1750. X    {
  1751. X        /*
  1752. X         * if a CTRL-C was typed, remove it from the buffer and set got_int
  1753. X         */
  1754. X        if (inbuf[inbufcount] == 3)
  1755. X        {
  1756. X            /* remove everything typed before the CTRL-C */
  1757. X            memmove(inbuf, inbuf + inbufcount, len + 1);
  1758. X            inbufcount = 0;
  1759. X            got_int = TRUE;
  1760. X        }
  1761. X        ++inbufcount;
  1762. X    }
  1763. X}
  1764. X
  1765. X/* 
  1766. X * Wait "ticks" until a character is available from the keyboard or from inbuf[]
  1767. X * ticks = -1 will block forever
  1768. X */
  1769. X
  1770. X    static int
  1771. XWaitForChar(ticks)
  1772. X    int ticks;
  1773. X{
  1774. X    if (inbufcount)        /* something in inbuf[] */
  1775. X        return 1;
  1776. X    return RealWaitForChar(ticks);
  1777. X}
  1778. X
  1779. X/* 
  1780. X * Wait "ticks" until a character is available from the keyboard
  1781. X * ticks = -1 will block forever
  1782. X */
  1783. X    static int
  1784. XRealWaitForChar(ticks)
  1785. X    int ticks;
  1786. X{
  1787. X    int    key;
  1788. X
  1789. X    if (ticks == -1)
  1790. X    {
  1791. X        key = os_get();
  1792. X    }
  1793. X    else
  1794. X    {
  1795. X        key = os_inkey(ticks/10);
  1796. X    }
  1797. Xdebug3("RWFC(%d) got %d (%c)\n", ticks, key, key);
  1798. X    
  1799. X    if (key != -1)
  1800. X    {
  1801. X        /* Unfortunately the key has now been taken from the
  1802. X         * buffer, so we need to put it in outselves. It's a 
  1803. X         * shame, but the other way I can think of involves a
  1804. X         * keyboard scan, and this would return for SHIFT, etc.
  1805. X         */
  1806. X         if (inbufcount < INBUFLEN)
  1807. X         {
  1808. X             inbuf[inbufcount++] = key;
  1809. X        }
  1810. X    }
  1811. X    return (key != -1);
  1812. X}
  1813. X
  1814. X/*
  1815. X * ExpandWildCard() - this code does wild-card pattern matching using the shell
  1816. X *
  1817. X * Mool: return 0 for success, 1 for error (you may loose some memory) and
  1818. X *       put an error message in *file.
  1819. X *
  1820. X * num_pat is number of input patterns
  1821. X * pat is array of pointers to input patterns
  1822. X * num_file is pointer to number of matched file names
  1823. X * file is pointer to array of pointers to matched file names
  1824. X * On Unix we do not check for files only yet
  1825. X * list_notfound is ignored
  1826. X */
  1827. X
  1828. Xextern char *mktemp __ARGS((char *));
  1829. X#ifndef SEEK_SET
  1830. X# define SEEK_SET 0
  1831. X#endif
  1832. X#ifndef SEEK_END
  1833. X# define SEEK_END 2
  1834. X#endif
  1835. X
  1836. X    int
  1837. XExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound)
  1838. X    int             num_pat;
  1839. X    char          **pat;
  1840. X    int            *num_file;
  1841. X    char         ***file;
  1842. X    int                files_only;
  1843. X    int                list_notfound;
  1844. X{
  1845. X    char    tmpname[TMPNAMELEN];
  1846. X    char    *command;
  1847. X    int        i;
  1848. X    int        dir;
  1849. X    size_t    len;
  1850. X    FILE    *fd;
  1851. X    char    *buffer;
  1852. X    char    *p;
  1853. X
  1854. X    *num_file = 0;        /* default: no files found */
  1855. X    *file = (char **)"";
  1856. X
  1857. X    /*
  1858. X     * If there are no wildcards, just copy the names to allocated memory.
  1859. X     * Saves a lot of time, because we don't have to run glob.
  1860. X     */
  1861. X    if (!have_wildcard(num_pat, pat))
  1862. X    {
  1863. X        *file = (char **)alloc(num_pat * sizeof(char *));
  1864. X        if (*file == NULL)
  1865. X        {
  1866. X            *file = (char **)"";
  1867. X            return 1;
  1868. X        }
  1869. X        for (i = 0; i < num_pat; i++)
  1870. X            (*file)[i] = strsave(pat[i]);
  1871. X        *num_file = num_pat;
  1872. X        return 0;
  1873. X    }
  1874. X
  1875. X/*
  1876. X * get a name for the temp file
  1877. X */
  1878. X    strcpy(tmpname, TMPNAME2);
  1879. X    if (*mktemp(tmpname) == NUL)
  1880. X    {
  1881. X        emsg(e_notmp);
  1882. X        return 1;
  1883. X    }
  1884. X
  1885. X    len = TMPNAMELEN + 10;
  1886. X    for (i = 0; i < num_pat; ++i)        /* count the length of the patterns */
  1887. X        len += strlen(pat[i]) + 1;
  1888. X    command = (char *)alloc(len);
  1889. X    if (command == NULL)
  1890. X        return 1;
  1891. X    strcpy(command, "glob >");            /* built the shell command */
  1892. X    strcat(command, tmpname);
  1893. X    for (i = 0; i < num_pat; ++i)
  1894. X    {
  1895. X        strcat(command, " ");
  1896. X        strcat(command, pat[i]);
  1897. X    }
  1898. X    i = call_shell(command, 0, FALSE);        /* execute it */
  1899. X    free(command);
  1900. X    if (i)                                    /* call_shell failed */
  1901. X    {
  1902. X        remove(tmpname);
  1903. X        sleep(1);            /* give the user a chance to read error messages */
  1904. X        must_redraw = CLEAR;                /* probably messed up screen */
  1905. X        return 1;
  1906. X    }
  1907. X
  1908. X/*
  1909. X * read the names from the file into memory
  1910. X */
  1911. X     fd = fopen(tmpname, "r");
  1912. X    if (fd == NULL)
  1913. X    {
  1914. X        emsg(e_notopen);
  1915. X        return 1;
  1916. X    }
  1917. X
  1918. X    fseek(fd, 0L, SEEK_END);
  1919. X    len = ftell(fd);                /* get size of temp file */
  1920. X    fseek(fd, 0L, SEEK_SET);
  1921. X    buffer = (char *)alloc(len + 1);
  1922. X    if (buffer == NULL)
  1923. X    {
  1924. X        remove(tmpname);
  1925. X        fclose(fd);
  1926. X        return 1;
  1927. X    }
  1928. X    i = fread(buffer, 1, len, fd);
  1929. X    fclose(fd);
  1930. X    remove(tmpname);
  1931. X    if (i != len)
  1932. X    {
  1933. X        emsg(e_notread);
  1934. X        free(buffer);
  1935. X        return 1;
  1936. X    }
  1937. X
  1938. X    buffer[len] = NUL;                    /* make sure the buffers ends in NUL */
  1939. X    i = 0;
  1940. X    for (p = buffer; p < buffer + len; ++p)
  1941. X        if (*p == NUL)                    /* count entry */
  1942. X            ++i;
  1943. X    if (len)
  1944. X        ++i;                            /* count last entry */
  1945. X
  1946. X    *num_file = i;
  1947. X    *file = (char **)alloc(sizeof(char *) * i);
  1948. X    if (*file == NULL)
  1949. X    {
  1950. X        free(buffer);
  1951. X        *file = (char **)"";
  1952. X        return 1;
  1953. X    }
  1954. X    p = buffer;
  1955. X
  1956. X    for (i = 0; i < *num_file; ++i)
  1957. X    {
  1958. X        (*file)[i] = p;
  1959. X        while (*p && p < buffer + len)        /* skip entry */
  1960. X            ++p;
  1961. X        ++p;                                /* skip NUL */
  1962. X    }
  1963. X    for (i = 0; i < *num_file; ++i)
  1964. X    {
  1965. X        dir = (isdir((*file)[i]) > 0);
  1966. X        if (dir < 0)            /* if file doesn't exist don't add '.' */
  1967. X            dir = 0;
  1968. X        p = alloc((unsigned)(strlen((*file)[i]) + 1 + dir));
  1969. X        if (p)
  1970. X        {
  1971. X            strcpy(p, (*file)[i]);
  1972. X            if (dir)
  1973. X                strcat(p, ".");
  1974. X        }
  1975. X        (*file)[i] = p;
  1976. X    }
  1977. X    free(buffer);
  1978. X    return 0;
  1979. X}
  1980. X
  1981. X    void
  1982. XFreeWild(num, file)
  1983. X    int        num;
  1984. X    char    **file;
  1985. X{
  1986. X    if (file == NULL || num == 0)
  1987. X        return;
  1988. X    while (num--)
  1989. X        free(file[num]);
  1990. X    free(file);
  1991. X}
  1992. X
  1993. X    int
  1994. Xhas_wildcard(p)
  1995. X    char *p;
  1996. X{
  1997. X    return strpbrk(p, "*#") != NULL;
  1998. X}
  1999. X
  2000. X    int
  2001. Xhave_wildcard(num, file)
  2002. X    int        num;
  2003. X    char    **file;
  2004. X{
  2005. X    register int i;
  2006. X
  2007. X    for (i = 0; i < num; i++)
  2008. X        if (has_wildcard(file[i]))
  2009. X            return 1;
  2010. X    return 0;
  2011. X}
  2012. END_OF_FILE
  2013.   if test 13434 -ne `wc -c <'vim/src/archie.c'`; then
  2014.     echo shar: \"'vim/src/archie.c'\" unpacked with wrong size!
  2015.   fi
  2016.   # end of 'vim/src/archie.c'
  2017. fi
  2018. if test -f 'vim/src/archie.h' -a "${1}" != "-c" ; then 
  2019.   echo shar: Will not clobber existing file \"'vim/src/archie.h'\"
  2020. else
  2021.   echo shar: Extracting \"'vim/src/archie.h'\" \(285 characters\)
  2022.   sed "s/^X//" >'vim/src/archie.h' <<'END_OF_FILE'
  2023. X/* vi:ts=4:sw=4
  2024. X *
  2025. X * VIM - Vi IMproved        by Bram Moolenaar
  2026. X *
  2027. X * Read the file "credits.txt" for a list of people who contributed.
  2028. X * Read the file "uganda.txt" for copying and usage conditions.
  2029. X */
  2030. X
  2031. X/*
  2032. X * Archimedes Machine-dependent things
  2033. X */
  2034. X
  2035. X/*
  2036. X * sorry, this file is missing
  2037. X */
  2038. END_OF_FILE
  2039.   if test 285 -ne `wc -c <'vim/src/archie.h'`; then
  2040.     echo shar: \"'vim/src/archie.h'\" unpacked with wrong size!
  2041.   fi
  2042.   # end of 'vim/src/archie.h'
  2043. fi
  2044. echo shar: End of archive 3 \(of 26\).
  2045. cp /dev/null ark3isdone
  2046. MISSING=""
  2047. 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
  2048.     if test ! -f ark${I}isdone ; then
  2049.     MISSING="${MISSING} ${I}"
  2050.     fi
  2051. done
  2052. if test "${MISSING}" = "" ; then
  2053.     echo You have unpacked all 26 archives.
  2054.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2055. else
  2056.     echo You still must unpack the following archives:
  2057.     echo "        " ${MISSING}
  2058. fi
  2059. exit 0
  2060. exit 0 # Just in case...
  2061.