home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim53os2.zip / vim-5.3 / doc / change.txt < prev    next >
Text File  |  1998-08-30  |  55KB  |  1,349 lines

  1. *change.txt*    For Vim version 5.3.  Last modification: 1998 Aug 22
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. This file describes commands that delete or change text.  In this context,
  8. changing text means deleting the text and replacing it with other text using
  9. one command.  You can undo all of these commands.  You can repeat the non-Ex
  10. commands with the "." command.
  11.  
  12. 1. Deleting text        |deleting|
  13. 2. Delete and insert        |delete-insert|
  14. 3. Simple changes        |simple-change|        *changing*
  15. 4. Complex changes        |complex-change|
  16. 5. Copying and moving text    |copy-move|
  17. 6. Formatting text        |formatting|
  18. 7. Indenting C programs        |C-indenting|
  19.  
  20. For inserting text see |insert.txt|.
  21.  
  22. ==============================================================================
  23. 1. Deleting text                    *deleting*
  24.  
  25. ["x]<Del>    or                    *<Del>* *x* *dl*
  26. ["x]x            Delete [count] characters under and after the cursor
  27.             [into register x] (not linewise).  Does the same as
  28.             "dl".  See |:fixdel| if the <Del> key does not do what
  29.             you want.  See |'whichwrap'| for deleting the <EOL>
  30.             (join lines).  {Vi does not support <Del>}
  31.  
  32.                             *X* *dh*
  33. ["x]X            Delete [count] characters before the cursor [into
  34.             register x] (not linewise).  Does the same as "dh".
  35.             Also see |'whichwrap'|.
  36.  
  37.                             *d*
  38. ["x]d{motion}        Delete text that {motion} moves over [into register
  39.             x].  See below for exceptions.
  40.  
  41.                             *dd*
  42. ["x]dd            Delete [count] lines [into register x] (linewise).
  43.  
  44.                             *D*
  45. ["x]D            Delete the characters under the cursor until the end
  46.             of the line and [count]-1 more lines [into register
  47.             x]; synonym for d$ (not linewise).
  48.  
  49. {Visual}["x]x    or                    *v_x* *v_d*
  50. {Visual}["x]d        Delete the highlighted text [into register x] (see
  51.             the chapter on Visual mode |Visual-mode|).  {not in
  52.             Vi}
  53.  
  54. {Visual}["x]X    or                    *v_X* *v_D*
  55. {Visual}["x]D        Delete the highlighted lines [into register x] (see
  56.             the chapter on Visual mode |Visual-mode|).  In Visual
  57.             block mode, "D" deletes the highlighted text plus all
  58.             text until the end of the line.  {not in Vi}
  59.  
  60.                             *:d* *:delete*
  61. :[range]d[elete] [x]    Delete [range] lines (default: current line) [into
  62.             register x].
  63.  
  64. :[range]d[elete] [x] {count}
  65.             Delete {count} lines, starting with [range]
  66.             (default: current line |cmdline-ranges|) [into
  67.             register x].
  68.  
  69. These commands delete text.  You can repeat them with the "." command
  70. (except ":d") and undo them.  Use Visual mode to delete blocks of text.  See
  71. |registers| for an explanation of registers.
  72.  
  73. An exception for the d{motion} command: If the motion is not linewise, the
  74. start and end of the motion are not in the same line, and there are only
  75. blanks before the start and after the end of the motion, the delete becomes
  76. linewise.  This means that the delete also removes the line of blanks that you
  77. might expect to remain.
  78.  
  79. Trying to delete an empty region of text (e.g., "d0" in the first column)
  80. is an error when 'cpoptions' includes the 'E' flag.
  81.  
  82.                             *J*
  83. J            Join [count] lines, with a minimum of two lines.
  84.             Insert up to two spaces (see below).
  85.  
  86.                             *v_J*
  87. {Visual}J        Join the highlighted lines, with a minimum of two
  88.             lines.  Insert up to two spaces (see below).  {not in
  89.             Vi}
  90.  
  91.                             *gJ*
  92. gJ            Join [count] lines, with a minimum of two lines.
  93.             Don't insert any spaces.  {not in Vi}
  94.  
  95.                             *v_gJ*
  96. {Visual}gJ        Join the highlighted lines, with a minimum of two
  97.             lines.  Don't insert any spaces.  {not in Vi}
  98.  
  99.                             *:j* *:join*
  100. :[range]j[oin][!]    Join [range] lines.  Same as "J", except with [!]
  101.             the join does not insert or delete any spaces.
  102.             If a [range] has equal start and end values, this
  103.             command does nothing.  The default behavior is to
  104.             join the current line with the line below it.
  105.  
  106. :[range]j[oin][!] {count}
  107.             Join {count} lines, starting with [range] (default:
  108.             current line |cmdline-ranges|).  Same as "J", except
  109.             with [!] the join does not insert or delete any
  110.             spaces.
  111.  
  112. These commands delete the <EOL> between lines.  This has the effect of joining
  113. multiple lines into one line.  You can repeat these commands (except ":j") and
  114. undo them.
  115.  
  116. These commands, except "gJ", insert one space in place of the <EOL> unless
  117. there is trailing white space or the next line starts with a ')'.  These
  118. commands delete any leading white space on the next line.  If the 'joinspaces'
  119. option is on, these commands insert two spaces after a '.', '!' or '?' (but if
  120. 'cpoptions' includes the 'j' flag, they insert two spaces only after a '.').
  121.  
  122.  
  123. ==============================================================================
  124. 2. Delete and insert                    *delete-insert*
  125.  
  126.                             *R*
  127. R            Enter Replace mode: Each character you type replaces
  128.             an existing character, starting with the character
  129.             under the cursor.  Repeat the entered text [count]-1
  130.             times.
  131.  
  132.                             *c*
  133. ["x]c{motion}        Delete {motion} text [into register x] and start
  134.             insert.  When  'cpoptions' includes the 'E' flag and
  135.             there is no text to delete (e.g., with "cTx" when the
  136.             cursor is just after an 'x'), an error occurs and
  137.             insert mode does not start (this is Vi compatible).
  138.             When  'cpoptions' does not include the 'E' flag, the
  139.             "c" command always starts insert mode, even if there
  140.             is no text to delete.
  141.  
  142.                             *cc*
  143. ["x]cc            Delete [count] lines [into register x] and start
  144.             insert (linewise).  If 'autoindent' is on, preserve
  145.             the indent of the first line.
  146.  
  147.                             *C*
  148. ["x]C            Delete from the cursor position to the end of the
  149.             line and [count]-1 more lines [into register x], and
  150.             start insert.  Synonym for c$ (not linewise).
  151.  
  152.                             *s*
  153. ["x]s            Delete [count] characters [into register x] and start
  154.             insert (s stands for Substitute).  Synonym for "cl"
  155.             (not linewise).
  156.  
  157.                             *S*
  158. ["x]S            Delete [count] lines [into register x] and start
  159.             insert.  Synonym for "cc" (linewise).
  160.  
  161. {Visual}["x]c    or
  162. {Visual}["x]s    or                    *v_c* *v_r* *v_s*
  163. {Visual}["x]r        Delete the highlighted text [into register x] and
  164.             start insert (see the chapter on Visual mode
  165.             |Visual-mode|).  {not in Vi}
  166.  
  167. {Visual}["x]C    or
  168. {Visual}["x]S    or                    *v_C* *v_R* *v_S*
  169. {Visual}["x]R        Delete the highlighted lines [into register x] and
  170.             start insert (see the chapter on Visual mode
  171.             |Visual-mode|).  {not in Vi}
  172.  
  173. Notes:
  174. - You can end Insert and Replace mode with <Esc>.
  175. - See the section "Insert and Replace mode" |mode-ins-repl| for the other
  176.   special characters in these modes.
  177. - The effect of [count] takes place after Vim exits Insert or Replace mode.
  178. - When the 'cpoptions' option contains '$' and the change is within one line,
  179.   Vim continues to show the the text to be deleted and puts a '$' at the last
  180.   deleted character.
  181.  
  182. See |registers| for an explanation of registers.
  183.  
  184. Replace mode is just like Insert mode, except that every character you enter
  185. deletes one character.  If you reach the end of a line, Vim appends any
  186. further characters (just like Insert mode).  In Replace mode, the backspace
  187. key restores the original text (if there was any).  (See section "Insert and
  188. Replace mode" |mode-ins-repl|).
  189.  
  190.                         *cw* *cW*
  191. Special case: "cw" and "cW" work the same as "ce" and "cE" if the cursor is
  192. on a non-blank.  This is because Vim interprets "cw" as change-word, and a
  193. word does not include the following white space.  {Vi: "cw" when on a blank
  194. followed by other blanks changes only the first blank; this is probably a
  195. bug, because "dw" deletes all the blanks}
  196.  
  197.                             *:c* *:change*
  198. :{range}c[hange]    Replace lines of text with some different text.
  199.             Type a line containing only "." to stop replacing.
  200.             Without {range}, this command changes only the current
  201.             line.
  202.  
  203. ==============================================================================
  204. 3. Simple changes                    *simple-change*
  205.  
  206.                             *r*
  207. r{char}            Replace the character under the cursor with {char}.
  208.             If {char} is a <CR> or <NL>, a line break replaces the
  209.             character.  To replace with a real <CR>, use CTRL-V
  210.             <CR>.  CTRL-V <NL> replaces with a <Nul>.  {Vi: CTRL-V
  211.             <CR> still replaces with a line break, cannot replace
  212.             something with a <CR>} If you give a [count], Vim
  213.             replaces [count] characters with [count] {char}s.
  214.             When {char} is a <CR> or <NL>, however, Vim inserts
  215.             only one <CR>: "5r<CR>" replaces five characters with
  216.             a single line break.  When {char} is a <CR> or <NL>,
  217.             Vim performs autoindenting.  This works just like
  218.             deleting the characters that are replaced and then
  219.             doing "i<CR><Esc>".
  220.  
  221.                             *~*
  222. ~            'notildeop' option: switch case of the character
  223.             under the cursor and move the cursor to the right.
  224.             If a [count] is given, do that many characters {Vi:
  225.             no count}
  226.  
  227. ~{motion}        'tildeop' option: switch case of {motion} text.  {Vi:
  228.             tilde cannot be used as an operator}
  229.  
  230.                             *g~*
  231. g~{motion}        Switch case of {motion} text.  {not in Vi}
  232.  
  233. g~g~                            *g~g~* *g~~*
  234. g~~            Switch case of current line.  {not in Vi}.
  235.  
  236.                             *v_~*
  237. {Visual}~        Switch case of highlighted text (see the chapter on
  238.             Visual mode |Visual-mode|).  {not in Vi}
  239.  
  240.                             *v_U*
  241. {Visual}U        Make highlighted text uppercase (see the chapter on
  242.             Visual mode |Visual-mode|).  {not in Vi}
  243.  
  244.                             *gU*
  245. gU{motion}        Make {motion} text uppercase.  {not in Vi}
  246.  
  247. gUgU                            *gUgU* *gUU*
  248. gUU            Make current line uppercase.  {not in Vi}.
  249.  
  250.                             *v_u*
  251. {Visual}u        Make highlighted text lowercase (see the chapter on
  252.             Visual mode |Visual-mode|).  {not in Vi}
  253.  
  254.                             *gu*
  255. gu{motion}        Make {motion} text lowercase.  {not in Vi}
  256.  
  257. gugu                            *gugu* *guu*
  258. guu            Make current line uppercase.  {not in Vi}.
  259.  
  260.                             *CTRL-A*
  261. CTRL-A            Add [count] to the number at or after the cursor.
  262.             {not in Vi}
  263.  
  264.                             *CTRL-X*
  265. CTRL-X            Subtract [count] from the number at or after the
  266.             cursor.  {not in Vi}
  267.  
  268. The CTRL-A and CTRL-X commands work for (signed) decimal numbers and
  269. unsigned octal and hexadecimal numbers.  This depends on the 'nrformats'
  270. option.
  271. - When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or
  272.   '0X' are hexadecimal.  The case of the rightmost letter in the number
  273.   determines the case of the resulting hexadecimal number.  If there is no
  274.   letter in the current number, Vim uses the previously detected case.
  275. - When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
  276.   to be octal.  Other numbers are decimal and may have a preceding minus sign.
  277.   If the cursor is on a number, the commands apply to that number; otherwise
  278.   Vim uses the number to the right of the cursor.
  279.  
  280. For numbers with leading zeros (including all octal and hexadecimal numbers),
  281. Vim preserves the number of characters in the number when possible.  CTRL-A on
  282. "0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".  Note that
  283. when 'nrformats' includes "octal", decimal numbers with leading zeros are
  284. impossible because they are indistinguishable from octal numbers.
  285.  
  286. The CTRL-A command is very useful in a macro.  Example: Use the following
  287. steps to make a numbered list.
  288.  
  289. 1. Create the first list entry, make sure it starts with a number.
  290. 2. qa         - start recording into buffer 'a'
  291. 3. Y         - yank the entry
  292. 4. p         - put a copy of the entry below the first one
  293. 5. CTRL-A    - increment the number
  294. 6. q         - stop recording
  295. 7. <count>@a - repeat the yank, put and increment <count> times
  296.  
  297.  
  298. SHIFTING LINES LEFT OR RIGHT                *shift-left-right*
  299.  
  300.                             *<*
  301. <{motion}        Shift {motion} lines one 'shiftwidth' leftwards.
  302.  
  303.                             *<<*
  304. <<            Shift [count] lines one 'shiftwidth' leftwards.
  305.  
  306.                             *v_<*
  307. {Visual}[count]<    Shift the highlighted lines [count] 'shiftwidth'
  308.             leftwards (see the chapter on Visual mode
  309.             |Visual-mode|).  {not in Vi}
  310.  
  311.                             *>*
  312.  >{motion}        Shift {motion} lines one 'shiftwidth' rightwards.
  313.  
  314.                             *>>*
  315.  >>            Shift [count] lines one 'shiftwidth' rightwards.
  316.  
  317.                             *v_>*
  318. {Visual}[count]>    Shift the highlighted lines [count] 'shiftwidth'
  319.             rightwards (see the chapter on Visual mode
  320.             |Visual-mode|).  {not in Vi}
  321.  
  322.                             *:<*
  323. :[range]<        Shift [range] lines one 'shiftwidth' left.  Repeat '<'
  324.             for shifting multiple 'shiftwidth's.
  325.  
  326. :[range]< {count}    Shift {count} lines one 'shiftwidth' left, starting
  327.             with [range] (default current line |cmdline-ranges|).
  328.             Repeat '<' for shifting multiple 'shiftwidth's.
  329.  
  330. :[range]le[ft] [indent]    left align lines in [range].  Sets the indent in the
  331.             lines to [indent] (default 0).  {not in Vi}
  332.  
  333.                             *:>*
  334. :[range]>        Shift {count} [range] lines one 'shiftwidth' right.
  335.             Repeat '>' for shifting multiple 'shiftwidth's.
  336.  
  337. :[range]> {count}    Shift {count} lines one 'shiftwidth' right, starting
  338.             with [range] (default current line |cmdline-ranges|).
  339.             Repeat '>' for shifting multiple 'shiftwidth's.
  340.  
  341. The ">" and "<" commands are handy for changing the indentation within
  342. programs.  Use the 'shiftwidth' option to set the size of the white space
  343. which these commands insert or delete.  Normally the 'shiftwidth' option is 8,
  344. but you can set it to, say, 3 to make smaller indents.  The shift leftwards
  345. stops when there is no indent.  The shift right does not affect empty lines.
  346.  
  347. If the 'shiftround' option is on, the indent is rounded to a multiple of
  348. 'shiftwidth'.
  349.  
  350. If the 'smartindent' option is on, or 'cindent' is on and 'cinkeys' contains
  351. '#', shift right does not affect lines starting with '#' (these are supposed
  352. to be C preprocessor lines that must stay in column 1).
  353.  
  354. When the 'expandtab' option is off (this is the default) Vim uses <Tab>s as
  355. much as possible to make the indent.  You can use ">><<" to replace an indent
  356. made out of spaces with the same indent made out of <Tab>s (and a few spaces
  357. if necessary).  If the 'expandtab' option is on, Vim uses only spaces.  Then
  358. you can use ">><<" to replace <Tab>s in the indent by spaces (or use
  359. ":retab!").
  360.  
  361. To move a line several 'shiftwidth's, use Visual mode or the ":" commands.
  362. For example:
  363. >    Vjj4>        move three lines 4 indents to the right
  364. >    :<<<        move current line 3 indents to the left
  365. >    :>> 5        move 5 lines 2 indents to the right
  366. >    :5>>        move line 5 2 indents to the right
  367.  
  368. ==============================================================================
  369. 4. Complex changes                    *complex-change*
  370.  
  371.                             *!* *filter*
  372. !{motion}{filter}    Filter {motion} text through the external program
  373.             {filter}.
  374.  
  375.                             *!!*
  376. !!{filter}        Filter [count] lines through the external program
  377.             {filter}.
  378.  
  379.                             *v_!*
  380. {Visual}!{filter}    Filter the highlighted lines through the external
  381.             program {filter} (see the chapter on Visual mode
  382.             |Visual-mode|).  {not in Vi}
  383.  
  384. :{range}![!]{filter} [!][arg]                *:range!*
  385.             Filter {range} lines through the external program
  386.             {filter}.  Vim replaces the optional bangs with the
  387.             latest given command and appends the optional [arg].
  388.             Vim saves the output of the filter command in a
  389.             temporary file and then reads the file into the
  390.             buffer.  Vim uses the 'shellredir' option to redirect
  391.             the filter output to the temporary file.
  392.  
  393.                             *=*
  394. ={motion}        Filter {motion} lines through the external program
  395.             given with the 'equalprg' option.  When the 'equalprg'
  396.             option is empty (this is the default), use the
  397.             internal formatting function to set the indent of each
  398.             line |C-indenting|.
  399.  
  400.                             *==*
  401. ==            Filter [count] lines through the external program
  402.             given with the 'equalprg' option.  When the 'equalprg'
  403.             option is empty (this is the default), use the
  404.             internal formatting function |C-indenting|.
  405.  
  406.                             *v_=*
  407. {Visual}=        Filter the highlighted lines through the external
  408.             program given with the 'equalprg' option.  When the
  409.             'equalprg' option is empty (this is the default),
  410.             use the internal formatting function |C-indenting|.
  411.             (see the chapter on Visual mode |Visual-mode|).  {not
  412.             in Vi}
  413.  
  414. A filter is a program that accepts text at standard input, changes it in some
  415. way, and sends it to standard output.  You can use the commands above to send
  416. some text through a filter.  Examples of filters are "sort", which sorts lines
  417. alphabetically, and "indent", which formats C program files (you need a
  418. version of indent that works like a filter; not all versions do).  The 'shell'
  419. option specifies the shell Vim uses to execute the filter command (See also
  420. the 'shelltype' option).  You can repeat filter commands with ".".  Vim does
  421. not recognize a comment (starting with '"') after the ":!" command.
  422.  
  423.  
  424.                         *:s* *:substitute*
  425. :[range]s[ubstitute]/{pattern}/{string}/[c][e][g][p][r][i][I] [count]
  426.             For each line in [range] replace a match of {pattern}
  427.             with {string}.  See |:s_flags| for the flags.
  428.  
  429. :[range]s[ubstitute] [c][e][g][r][i][I] [count]
  430. :[range]&[c][e][g][r][i][I] [count]            *:&*
  431.             Repeat last :substitute with same search pattern and
  432.             substitute string, but without the same flags.  You
  433.             may add extra flags (see |:s_flags|).
  434.  
  435. :[range]~[c][e][g][r][i][I] [count]            *:~*
  436.             Repeat last substitute with same substitute string
  437.             but with last used search pattern.  This is like
  438.             "&r".  See |:s_flags| for the flags.
  439.  
  440.                         *&*
  441. &            Synonym for ":s//~/" (repeat last substitute).
  442.  
  443.                         *:snomagic*
  444. :[range]sno[magic] ...    Same as ":substitute", but always use 'nomagic'.
  445.  
  446.                         *:smagic*
  447. :[range]sm[agic] ...    Same as ":substitute", but always use 'magic'.
  448.  
  449.                             *:s_flags*
  450. The arguments that you can use for the substitute commands:
  451. [c]    Confirm each substitution.  Vim positions the cursor on the matching
  452.     string.  You can type:                *:s_c*
  453.         'y'        to substitute this match
  454.         'n'        to skip this match
  455.         <Esc>   to skip this match
  456.         'a'        to substitute this and all remaining matches {not in Vi}
  457.         'q'        to quit substituting {not in Vi}
  458.         CTRL-E  to scroll the screen up {not in Vi}
  459.         CTRL-Y  to scroll the screen down {not in Vi}.
  460.     If the 'edcompatible' option is on, Vim remembers the [c] flag and
  461.     toggles it each time you use it, but resets it when you give a new
  462.     search pattern.
  463. [e]     When the search pattern fails, do not issue an error message and, in
  464.     particular, continue in maps as if no error occurred.  This is most
  465.     useful to prevent the "No match" error from breaking a mapping.  Vim
  466.     does not suppress the following error messages, however:
  467.         Regular expressions can't be delimited by letters
  468.         \ should be followed by /, ? or &
  469.         No previous substitute regular expression
  470.         Trailing characters
  471.         Interrupted
  472. [g]    Replace all occurrences in the line.  Without this argument,
  473.     replacement occurs only for the first occurrence in each line.  If
  474.     the 'edcompatible' option is on, Vim remembers this flag and toggles
  475.     it each time you use it, but resets it when you give a new search
  476.     pattern.  If the 'gdefault' option is on, this flag is on by default
  477.     and the [g] argument switches it off.
  478. [i]    Ignore case for the pattern.  The 'ignorecase' and 'smartcase' options
  479.     are not used.
  480. [I]    Don't ignore case for the pattern.  The 'ignorecase' and 'smartcase'
  481.     options are not used.
  482. [p]    Print the line containing the last substitute.
  483. [r]    Only useful in combination with ":&" or ":s" without arguments.  ":&r"
  484.     works the same way as ":~":  When the search pattern is empty, use the
  485.     previously used search pattern instead of the search pattern from the
  486.     last substitute or ":global".  If the last command that did a search
  487.     was a substitute or ":global", there is no effect.  If the last
  488.     command was a search command such as "/", use the pattern from that
  489.     command.
  490.     For ":s" with an argument this already happens:
  491. >        :s/blue/red/
  492. >        /green
  493. >        :s//red/   or  :~   or  :&r
  494.     The last commands will replace "green" with "red".
  495. >        :s/blue/red/
  496. >        /green
  497. >        :&
  498.     The last command will replace "blue" with "red".
  499.  
  500. Note that there is no flag to change the "magicness" of the pattern.  A
  501. different command is used instead.  The reason is that the flags can only be
  502. found by skipping the pattern, and in order to skip the pattern the
  503. "magicness" must be known.  Catch 22!
  504.  
  505. [count] Search [count] lines, starting with the last line number
  506.     in [range] (default is to search only the current line |cmdline-ranges|).
  507.  
  508. If the {pattern} for the substitute command is empty, the command uses the
  509. pattern from the last substitute or ":global" command.  With the [r] flag, the
  510. command uses the pattern from the last substitute, ":global", or search
  511. command.
  512.  
  513. For compatibility with Vi these two exceptions are allowed:
  514. "\/{string}/" and "\?{string}?" do the same as "//{string}/r".
  515. "\&{string}&" does the same as "//{string}/".
  516.  
  517. Instead of the '/' which surrounds the pattern and replacement string, you
  518. can use any other character, but not an alphanumeric character, '\', '"' or
  519. '|'.  This is useful if you want to include a '/' in the search pattern or
  520. replacement string.  Example:
  521. >    :s+/+//+
  522.  
  523. For the definition of a pattern, see |pattern|.
  524.  
  525. Some characters in {string} have a special meaning:
  526.  
  527. magic    nomagic      action    ~
  528.   &      \&      replaced with the whole matched pattern
  529.  \&       &      replaced with &
  530.       \0      replaced with the whole matched pattern
  531.       \1      replaced with the matched pattern in the first pair of ()
  532.       \2      replaced with the matched pattern in the second pair of ()
  533.       ..      ..
  534.       \9      replaced with the matched pattern in the ninth pair of ()
  535.   ~      \~      replaced with the {string} of the previous substitute
  536.  \~       ~      replaced with ~ 
  537.       \u      next character made uppercase
  538.       \U      following characters made uppercase
  539.       \l      next character made lowercase
  540.       \L      following characters made lowercase
  541.       \e      end of /u, /U, /l and /L (NOTE: not <Esc>!)
  542.       \E      end of /u, /U, /l and /L
  543.       <CR>      split line in two at this point
  544.       \r      idem
  545.   CTRL-V <CR>      insert a carriage-return (CTRL-M)
  546.       \n      <NL> (does NOT break the line)
  547.       \b      <BS>
  548.       \t      <Tab>
  549.  
  550. Examples:
  551. >  :s/a\|b/xxx\0xxx/g         modifies "a b"         in "xxxaxxx xxxbxxx"
  552. >  :s/\([abc]\)\([efg]\)/\2\1/g  modifies "af fa bg" in "fa fa gb"
  553. >  :s/abcde/abc^Mde/         modifies "abcde"    in "abc", "de" (two lines)
  554. >  :s/$/^V^M/             modifies "abcde"    in "abcde^M"
  555.  
  556. Note: To insert a ^M you have to type CTRL-V <CR>.  To insert a ^V you have
  557. to type CTRL-V CTRL-V.  So to insert the ^V^M in the last example you have to
  558. type CTRL-V CTRL-V CTRL-V <CR>.
  559.  
  560. Because CTRL-V <CR> inserts a <CR>, it is impossible to insert a CTRL-V just
  561. in front of a line break.  You will have to perform the substitution in two
  562. steps:
  563. >  :s/foo/^Vxxxx/
  564. >  :s/xxxx/^M/
  565.  
  566. When using parentheses in combination with '|', like in \([ab]\)\|\([cd]\),
  567. either the first or second pattern in parentheses did not match, so either
  568. \1 or \2 is empty.  Example:
  569. >  :s/\([ab]\)\|\([cd]\)/\1x/g   modifies "a b c d"  in "ax bx x x"
  570.  
  571.                         *:promptfind*
  572. :promptf[ind] [string]
  573.             Win32 GUI only: Put up a Search dialog.  When [string]
  574.             is given, it is used as the initial search string.
  575.  
  576.                         *:promptrepl*
  577. :promptr[epl] [string]
  578.             Win32 GUI only: Put up a Search/Replace dialog.  When
  579.             [string] is given, it is used as the initial search
  580.             string.
  581.  
  582.                             *:ret* *:retab*
  583. :[range]ret[ab][!] [new_tabstop]
  584.             Replace all sequences of white-space containing a tab
  585.             with new strings of white-space using the new
  586.             tabstop value given.  If you do not specify a new
  587.             tabstop size, Vim uses the current value of 'tabstop'.
  588.             With !, Vim also replaces strings of normal spaces
  589.             with tabs where appropriate.  With 'expandtab' on, Vim
  590.             replaces all tabs with the appropriate number of
  591.             spaces.  This command sets 'tabstop' to the new
  592.             value given, and if performed on the whole file,
  593.             which is default, should not make any visible
  594.             change.  Careful: This command modifies any <Tab>
  595.             characters inside of strings in a C program.  Use
  596.             "\t" to avoid this (that's a good habit anyway).
  597.             {not in Vi}
  598.             Not available when |+ex_extra| feature was disabled at
  599.             compile time.
  600.  
  601.                             *retab-example*
  602. Example for using autocommands and ":retab" to edit a file which is stored
  603. with tabstops at 8 but edited with tabstops set at 4.  Warning: white space
  604. inside of strings can change!  Also see 'softtabstop' option.
  605.  
  606. >  auto BufReadPost    *.xx    retab! 4
  607. >  auto BufWritePre    *.xx    retab! 8
  608. >  auto BufWritePost    *.xx    retab! 4
  609. >  auto BufNewFile    *.xx    set ts=4
  610.  
  611. ==============================================================================
  612. 5. Copying and moving text                *copy-move*
  613.  
  614.                             *quote*
  615. "<a-zA-Z0-9.%#:-">    Use register <a-zA-Z0-9.%#:-"> for next delete, yank
  616.             or put (use uppercase character to append with
  617.             delete and yank) (<.%#:> only work with put).
  618.  
  619.                             *:reg* *:registers*
  620. :reg[isters]        Display the contents of all numbered and named
  621.             registers.  {not in Vi}
  622.  
  623. :reg[isters] {arg}    Display the contents of the numbered and named
  624.             registers that are mentioned in {arg}.  For example:
  625. >                :dis 1a
  626.             to display registers '1' and 'a'.  Spaces are allowed
  627.             in {arg}.  {not in Vi}
  628.  
  629.                             *:di* *:display*
  630. :di[splay] [arg]    Same as :registers.  {not in Vi}
  631.  
  632.                             *y* *yank*
  633. ["x]y{motion}        Yank {motion} text [into register x].  When no
  634.             characters are to be yanked (e.g., "y0" in column 1),
  635.             this is an error when 'cpoptions' includes the 'E'
  636.             flag.
  637.  
  638.                             *yy*
  639. ["x]yy            Yank [count] lines [into register x] (linewise).
  640.  
  641.                             *Y*
  642. ["x]Y            yank [count] lines [into register x] (synonym for
  643.             yy, linewise).  If you like "Y" to work from the
  644.             cursor to the end of line (which is more logical,
  645.             but not Vi-compatible) use ":map Y y$".
  646.  
  647.                             *v_y*
  648. {Visual}["x]y        Yank the highlighted text [into register x] (see the
  649.             chapter on Visual mode |Visual-mode|).  {not in Vi}
  650.  
  651.                             *v_Y*
  652. {Visual}["x]Y        Yank the highlighted lines [into register x] (see the
  653.             chapter on Visual mode |Visual-mode|).  {not in Vi}
  654.  
  655.                             *:y* *:yank*
  656. :[range]y[ank] [x]    Yank [range] lines [into register x].
  657.  
  658. :[range]y[ank] [x] {count}
  659.             Yank {count} lines, starting with last line number
  660.             in [range] (default: current line |cmdline-ranges|),
  661.             [into register x].
  662.  
  663.                             *p* *put*
  664. ["x]p            Put the text [from register x] after the cursor
  665.             [count] times.  {Vi: no count}
  666.  
  667. ["x]P            or                    *P* *<MiddleMouse>*
  668. ["x]<MiddleMouse>    Put the text [from register x] before the cursor
  669.             [count] times.  Using the mouse only works when
  670.             'mouse' contains 'n' or 'a'.  {Vi: no count}
  671.  
  672.                             *gp*
  673. ["x]gp            Just like "p", but leave the cursor just after the new
  674.             text.  {not in Vi}
  675.  
  676.                             *gP*
  677. ["x]gP            Just like "P", but leave the cursor just after the new
  678.             text.  {not in Vi}
  679.  
  680.                             *:pu* *:put*
  681. :[line]pu[t] [x]    Put the text [from register x] after [line] (default
  682.             current line).  The register can also be '=' followed
  683.             by an optional expression.  The expression continues
  684.             until the end of the command.  You need to escape the
  685.             '|' and '"' characters to prevent them from
  686.             terminating the command.  Example:
  687. >  :put ='path' . \",/test\"
  688.             If there is no expression after '=', Vim uses the
  689.             previous expression.  You can see it with ":dis =".
  690.  
  691. :[line]pu[t]! [x]    Put the text [from register x] before [line] (default
  692.             current line).
  693.  
  694. ["x]]p            or                    *]p* *]<MiddleMouse>*
  695. ["x]]<MiddleMouse>    Like "p", but adjust the indent to the current line.
  696.             Using the mouse only works when 'mouse' contains 'n'
  697.             or 'a'.  {not in Vi}
  698.  
  699. ["x][P            or                    *[P*
  700. ["x]]P            or                    *]P*
  701. ["x][p            or                    *[p* *[<MiddleMouse>*
  702. ["x][<MiddleMouse>    Like "P", but adjust the indent to the current line.
  703.             Using the mouse only works when 'mouse' contains 'n'
  704.             or 'a'.  {not in Vi}
  705.  
  706. You can use these commands to copy text from one place to another.  Do this
  707. by first getting the text into a register with a yank, delete or change
  708. command, then inserting the register contents with a put command.  You can
  709. also use these commands to move text from one file to another, because Vim
  710. preserves all registers when changing buffers (the CTRL-^ command is a quick
  711. way to toggle between two files).
  712.  
  713.                 *linewise-register* *characterwise-register*
  714. You can repeat the put commands with "." (except for :put) and undo them.  If
  715. the command that was used to get the text into the register was linewise, Vim
  716. inserts the text below ("p") or above ("P") the line where the cursor is.
  717. Otherwise Vim inserts the text after ("p") or before ("P") the cursor.  With
  718. the ":put" command, Vim always inserts the text in the next line.  You can
  719. exchange two characters with the command sequence "xp".  You can exchange two
  720. lines with the command sequence "ddp".  You can exchange two words with the
  721. command sequence "deep" (start with the cursor in the blank space before the
  722. first word).  You can use the "']" or "`]" command after the put command to
  723. move the cursor to the end of the inserted text, or use "'[" or "`[" to move
  724. the cursor to the start.
  725.  
  726.                             *blockwise-register*
  727. If you use a blockwise Visual mode command to get the text into the register,
  728. the block of text will be inserted before ("P") or after ("p") the cursor
  729. column in the current and next lines.  Vim makes the whole block of text start
  730. in the same column.  Thus the inserted text looks the same as when it was
  731. yanked or deleted.  Vim may replace some <Tab> characters with spaces to make
  732. this happen.  However, if the width of the block is not a multiple of a <Tab>
  733. width and the text after the inserted block contains <Tab>s, that text may be
  734. misaligned.
  735.  
  736. Note that after a yank command, Vim leaves the cursor on the first yanked
  737. character that is closest to the start of the buffer.  This means that "yl"
  738. doesn't move the cursor, but "yh" moves the cursor one character left.
  739. Rationale:    In Vi the "y" command followed by a backwards motion would
  740.         sometimes not move the cursor to the first yanked character,
  741.         because redisplaying was skipped.  In Vim it always moves to
  742.         the first character, as specified by Posix.
  743.  
  744. There are eight types of registers:            *registers*
  745. 1. The unnamed register ""            *quote_quote* *quotequote*
  746. 2. 10 numbered registers "0 to "9        *quote_number* *quote0*
  747. 3. The small delete register "-            *quote_-* *quote-*
  748. 4. 26 named registers "a to "z or "A to "Z    *quote_alpha* *quotea*
  749. 5. four read-only registers ":, "., "% and "#
  750. 6. the expression register "=            *quote_=* *quote=*
  751. 7. The selection register "*
  752. 8. The black hole register "_
  753.  
  754. 1. Unnamed register
  755. Vim fills this register with text deleted with the "d", "c", "s", "x" commands
  756. or copied with the yank "y" command, regardless of whether or not a specific
  757. register was used (e.g.  "xdd).  An exception is the '_' register: "_dd does
  758. not store the deleted text in any register.  Vim uses the contents of this
  759. register for any put command (p or P) which does not specify a register.
  760. Additionally you can access it with the name '"'.  This means you have to type
  761. two double quotes.  {Vi: register contents are lost when changing files, no
  762. '"'}
  763.  
  764. 2. Numbered registers                *quote1* *quote2* *quote9*
  765. Vim fills these registers with text from yank and delete commands.  Numbered
  766. register 0 contains the text from the most recent yank command, unless the
  767. command specified another register with ["x].  Numbered register 1 contains
  768. the text deleted by the most recent delete or change command, unless the
  769. command specified another register or the text is less than one line (Vim puts
  770. text deleted with "x" or "dw" in the small delete register).  With each
  771. successive deletion or change, Vim shifts the previous contents of register 1
  772. into register 2, 2 into 3, and so forth, losing the previous contents of
  773. register 9.  {Vi: numbered register contents are lost when changing files;
  774. register 0 does not exist}
  775.  
  776. 3. Small delete register
  777. This register contains text from commands that delete less than one line,
  778. except when the command specifies a register with ["x].
  779.  
  780. 4. Named registers
  781. Vim fills these registers only when you say so.  Specify them as lowercase
  782. letters to replace their previous contents or as uppercase letters to append
  783. to their previous contents.
  784.  
  785. 5. Read-only registers
  786. These are '%', '#', ':' and '.'.  You can use them only with the "p", "P",
  787. and ":put" commands and with CTRL-R.
  788.                             *quote_.* *quote.*
  789.     ".    Contains the last inserted text (the same as what is inserted
  790.         with the insert mode commands CTRL-A and CTRL-@).  Note: this
  791.         doesn't work with CTRL-R on the command-line.  It works a bit
  792.         differently, like inserting the text instead of putting it
  793.         ('textwidth' and other options affect what is inserted).
  794.                             *quote_%* *quote%*
  795.     "%    Contains the name of the current file.
  796.                             *quote_#* *quote#*
  797.     "#    Contains the name of the alternate file.
  798.                             *quote_:* *quote:*
  799.     ":    Contains the most recent command-line.  Example: Use "@:"
  800.         to repeat the most recent command-line.
  801.  
  802. 6. Expression register
  803. This is not really a register that stores text, but is a way to use an
  804. expression in commands which use a register.  The expression register is
  805. read-only; you cannot put text into it.  After the '=', the cursor moves to
  806. the command-line, where you can enter any expression (see |expression|).  All
  807. normal command-line editing commands are available, including a special
  808. history for expressions.  When you end the command-line by typing <CR>, Vim
  809. computes the result of the expression.  If you end it with <Esc>, Vim abandons
  810. the expression.  If you do not enter an expression, Vim uses the previous
  811. expression (like with the "/" command).  If the "= register is used for the
  812. "p" command, the string is split up at <NL> characters.  If the string ends in
  813. a <NL>, it is regarded as a linewise register.
  814.  
  815. 7. Selection register
  816. Use this register for storing and retrieving the selected text for the GUI.
  817. See |quotestar|.
  818.  
  819. 8. Black hole register
  820. When writing to this register, nothing happens.  This can be used to delete
  821. text without affecting the normal registers.  When reading from this register,
  822. nothing is returned.
  823.  
  824. If you use a put command without specifying a register, Vim uses the register
  825. that was last filled (this is also the contents of the unnamed register).  If
  826. you are confused, use the ":dis" command to find out what Vim will put (this
  827. command displays all named and numbered registers; the unnamed register is
  828. labelled '"').
  829.  
  830. The next three commands always work on whole lines.
  831.  
  832. :[range]co[py] {address}                *:co* *:copy*
  833.             Copy the lines given by [range] to below the line
  834.             given by {address}.
  835.  
  836.                             *:t*
  837. :t            Synonym for copy.
  838.  
  839. :[range]m[ove] {address}                *:m* *:move*
  840.             Move the lines given by [range] to below the line
  841.             given by {address}.
  842.  
  843. ==============================================================================
  844. 6. Formatting text                    *formatting*
  845.  
  846. :[range]ce[nter] [width]                *:ce* *:center*
  847.             Center lines in [range] between [width] columns
  848.             (default 'textwidth' or 80 when 'textwidth' is 0).
  849.             {not in Vi}
  850.             Not available when |+ex_extra| feature was disabled at
  851.             compile time.
  852.  
  853. :[range]ri[ght] [width]                    *:ri* *:right*
  854.             Right-align lines in [range] at [width] columns
  855.             (default 'textwidth' or 80 when 'textwidth' is 0).
  856.             {not in Vi}
  857.             Not available when |+ex_extra| feature was disabled at
  858.             compile time.
  859.  
  860.                             *:le* *:left*
  861. :[range]le[ft] [indent]    Left-align lines in [range].  Sets the indent in the
  862.             lines to [indent] (default 0).  {not in Vi}
  863.             Not available when |+ex_extra| feature was disabled at
  864.             compile time.
  865.  
  866.                             *gq*
  867. gq{motion}        Format the lines that {motion} moves over.  The
  868.             'textwidth' option controls the length of each
  869.             formatted line (see below).  If the 'textwidth' option
  870.             is 0, the formatted line length is the screen width
  871.             (with a maximum width of 79).  {not in Vi} NOTE: The
  872.             "Q" command formerly performed this function.  If you
  873.             still want to use "Q" for formatting, use this
  874.             mapping:
  875. >                :nnoremap Q gq
  876.  
  877. gqgq                            *gqgq* *gqq*
  878. gqq            Format the current line.  {not in Vi}
  879.  
  880.                             *v_gq*
  881. {Visual}gq        Format the highlighted text.  (see the chapter on
  882.             Visual mode |Visual-mode|).  {not in Vi}
  883.             NOTE: The "Q" command was formerly used for this.
  884.             If you still want to use "Q" for formatting the
  885.             highlighted text, use this mapping: ":vnoremap Q gq"
  886.  
  887. Example: To format the current paragraph use
  888. >    gqap
  889.  
  890. The "gq" command leaves the cursor in the line where the motion command takes
  891. the cursor.  This allows you to repeat formatting repeated with ".".  This
  892. works well with "gqj" (format current and next line) and "gq}" (format until
  893. end of paragraph).  Note: When 'formatprg' is set, "gq" leaves the cursor on
  894. the first formatted line (as with using a filter command).
  895.  
  896. If the 'autoindent' option is on, Vim uses the indent of the first line for
  897. the following lines.
  898.  
  899. Formatting does not change empty lines (but it does change lines with only
  900. white space!).
  901.  
  902. The 'joinspaces' option is used when lines are joined together.
  903.  
  904. You can set the 'formatprg' option to the name of an external program for Vim
  905. to use for text formatting.  The 'textwidth' and other options have no effect
  906. on formatting by an external program.
  907.  
  908.                             *right-justify*
  909. There is no command in Vim to right justify text.  You can do it with
  910. an external command, like "par" (e.g.: "!}par" to format until the end of the
  911. paragraph) or set 'formatprg' to "par".
  912.  
  913.                             *format-comments*
  914. Vim can format comments in a special way.  Vim recognizes a comment by a
  915. specific string at the start of the line (ignoring white space).  Three types
  916. of comments can be used:
  917.  
  918. - A comment string that repeats at the start of each line.  An example is the
  919.   type of comment used in shell scripts, starting with "#".
  920. - A comment string that occurs only in the first line, not in the following
  921.   lines.  An example is this list with dashes.
  922. - Three-piece comments that have a start string, an end string, and optional
  923.   lines in between.  The strings for the start, middle and end are different.
  924.   An example is the C-style comment:
  925.     /*
  926.      *  this is a C comment
  927.      */
  928.  
  929. The 'comments' option is a comma-separated list of parts.  Each part defines a
  930. type of comment string.  A part consists of:
  931.     {flags}:{string}
  932.  
  933. {string} is the literal text that must appear.
  934.  
  935. {flags}:
  936.   n    Nested comment.  Nesting with mixed parts is allowed.  If 'comments'
  937.     is "n:),n:>" a line starting with "> ) >" is a comment.
  938.  
  939.   b    Blank (<Space>, <Tab> or <EOL>) required after {string}.
  940.  
  941.   f    Only the first line has the comment string.  Do not repeat comment on
  942.     the next line, but preserve indentation (e.g., a bullet-list).
  943.  
  944.   s    Start of three-piece comment
  945.  
  946.   m    Middle of a three-piece comment
  947.  
  948.   e    End of a three-piece comment
  949.  
  950.   l    Left adjust middle with start or end (default).  Only recognized when
  951.     used together with 's' or 'e'.
  952.  
  953.   r    Right adjust middle with start or end.  Only recognized when used
  954.     together with 's' or 'e'.
  955.  
  956. When a string has none of the 'f', 's', 'm' or 'e' flags, Vim assumes the
  957. comment string repeats at the start of each line.  The flags field may be
  958. empty.
  959.  
  960. Any blank space in the text before and after the {string} is part of the
  961. {string}, so do not include leading or trailing blanks unless the blanks are a
  962. required part of the comment string.
  963.  
  964. When one comment leader is part of another, specify the part after the whole.
  965. For example, to include both "-" and "->", use
  966. >    :set comments=f:->,f:-
  967.  
  968. A three-piece comment must always be given as start,middle,end, with no other
  969. parts in between.  An example of a three-piece comment is
  970. >    sr:/*,mb:*,el:*/
  971. for C-comments.  To avoid recognizing "*ptr" as a comment, the middle string
  972. includes the 'b' flag.  For three-piece comments, Vim checks the text after
  973. the start and middle strings for the end string.  If Vim finds the end string,
  974. the comment does not continue on the next line.  Three-piece comments must
  975. have a middle string because otherwise Vim can't recognize the middle lines.
  976.  
  977. Examples:
  978. >  "b:*"    Includes lines starting with "*", but not if the "*" is
  979. >        followed by a non-blank.  This avoids a pointer dereference
  980. >        like "*str" to be recognized as a comment.
  981. >  "n:>"    Includes a line starting with ">", ">>", ">>>", etc.
  982. >  "fb:-"    Format a list that starts with "- ".
  983.  
  984. By default, "b:#" is included.  This means that a line that starts with
  985. "#include" is not recognized as a comment line.  But a line that starts with
  986. "# define" is recognized.  In C code this is good, because somewhere after this
  987. a "#endif" is needed.
  988.  
  989.                             *fo-table*
  990. You can use the 'formatoptions' option  to influence how Vim formats comments.
  991. 'formatoptions' is a string that can contain any of the letters below.  The
  992. default setting is "tcq".  You can separate the option letters with commas for
  993. readability.
  994.  
  995. letter     meaning when present in 'formatoptions'    ~
  996.  
  997. t    Auto-wrap text using textwidth
  998. c    Auto-wrap comments using textwidth, inserting the current comment
  999.     leader automatically.
  1000. r    Automatically insert the current comment leader after hitting
  1001.     <return> in insert mode.
  1002. o    Automatically insert the current comment leader after hitting 'o' or
  1003.     'O' in Normal mode.
  1004. q    Allow formatting of comments with "gq".
  1005.     Note that formatting will not change blank lines or lines containing
  1006.     only the comment leader.  A new paragraph starts after such a line,
  1007.     or when the comment leader changes.
  1008. 2    When formatting text, use the indent of the second line of a paragraph
  1009.     for the rest of the paragraph.  This supports paragraphs in which the
  1010.     first line has a different indent than the rest.
  1011. v    Vi-compatible auto-wrapping in insert mode: Only break a line at a
  1012.     blank that you have entered during the current insert command.  (Note:
  1013.     this is not 100% Vi compatible.  Vi has some "unexpected features" or
  1014.     bugs in this area.  It uses the screen column instead of the line
  1015.     column.)
  1016. b    Like 'v', but only auto-wrap if you enter a blank at or before
  1017.     the wrap margin.  If the line was longer than 'textwidth' when you
  1018.     started the insert, or you do not enter a blank in the insert before
  1019.     reaching 'textwidth', Vim does not perform auto-wrapping.
  1020. l    Long lines are not broken in insert mode: When a line was longer than
  1021.     'textwidth' when the insert command started, Vim does not
  1022.     automatically format it.
  1023.  
  1024. With 't' and 'c' you can specify when Vim performs auto-wrapping:
  1025. value    action    ~
  1026. ""    no automatic formatting (you can use "gq" for manual formatting)
  1027. "t"    automatic formatting of text, but not comments
  1028. "c"    automatic formatting for comments, but not text (good for C code)
  1029. "tc"    automatic formatting for text and comments
  1030.  
  1031. Note that when 'textwidth' is 0, Vim does no formatting anyway (but does
  1032. insert comment leaders according to the 'comments' option).
  1033.  
  1034. Note that when 'paste' is on, Vim does no formatting at all.
  1035.  
  1036. Note that 'textwidth' can be non-zero even if Vim never performs auto-wrapping;
  1037. 'textwidth' is still useful for formatting with "gq".
  1038.  
  1039. If the 'comments' option includes "/*", "*" and/or "*/", then Vim has some
  1040. built in stuff to treat these types of comments a bit more cleverly.
  1041. Opening a new line before or after "/*" or "*/" (with 'r' or 'o' present in
  1042. 'formatoptions') gives the correct start of the line automatically.  The same
  1043. happens with formatting and auto-wrapping. Opening a line after a line
  1044. starting with "/*" or "*" and containing "*/", will cause no comment leader to
  1045. be inserted, and the indent of the new line is taken from the line containing
  1046. the start of the comment.
  1047. E.g.:
  1048.     /*
  1049.      * Your typical comment.
  1050.      */
  1051.     The indent on this line is the same as the start of the above
  1052.     comment.
  1053.  
  1054. All of this should be really cool, especially in conjunction with the new
  1055. :autocmd command to prepare different settings for different types of file.
  1056.  
  1057. Some examples:
  1058.   for C code (only format comments):
  1059. >    fo=croq
  1060.   for Mail/news    (format all, don't start comment with "o" command):
  1061. >    fo=tcrq
  1062.  
  1063. ==============================================================================
  1064. 7. Indenting C programs                    *C-indenting*
  1065.  
  1066. Vim has options for automatically indenting C program files.  These options
  1067. affect only the indent and do not perform other formatting.  For comment
  1068. formatting, see |format-comments|.
  1069.  
  1070. Note that you can disable the |+smartindent| and |+cindent| features at
  1071. compile time.
  1072.  
  1073. There are in fact three methods available for indentation:
  1074. 'autoindent'    uses the indent from the previous line.
  1075. 'smartindent'    is like 'autoindent' but also recognizes some C syntax to
  1076.         increase/reduce the indent where appropriate.
  1077. 'cindent'    Works more cleverly than the other two and is configurable to
  1078.         different indenting styles.
  1079. The rest of this section describes the 'cindent' option.
  1080.  
  1081. Note that 'cindent' indenting does not work for every code scenario.  Vim
  1082. is not a C compiler: it does not recognize all syntax.
  1083.  
  1084. These four options control C program indenting:
  1085. 'cindent'    Enables Vim to perform C program indenting automatically.
  1086. 'cinkeys'    Specifies which keys trigger reindenting in insert mode.
  1087. 'cinoptions'    Sets your preferred indent style.
  1088. 'cinwords'    Defines keywords that start an extra indent in the next line.
  1089.  
  1090. If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
  1091. Vim's built-in algorithm rather than calling an external program.
  1092.  
  1093. See |autocommand| for how to set the 'cindent' option automatically for C code
  1094. files and reset it for others.
  1095.  
  1096.                             *'cinkeys'* *'cink'*
  1097. The 'cinkeys' option is a string that controls Vim's indenting in response to
  1098. typing certain characters or commands in certain contexts.  The default is
  1099. "0{,0},:,0#,!^F,o,O,e" which specifies that indenting occurs as follows:
  1100.  
  1101.     "0{"    if you type '{' as the first character in a line
  1102.     "0}"    if you type '}' as the first character in a line
  1103.     ":"    if you type ':' anywhere
  1104.     "0#"    if you type '#' as the first character in a line
  1105.     "!^F"    if you type CTRL-F (which is not inserted)
  1106.     "o"    if you type a <CR> anywhere or use the "o" command (not in
  1107.         insert mode!)
  1108.     "O"    if you use the "O" command (not in insert mode!)
  1109.     "e"    if you type the second 'e' for an "else" at the start of a
  1110.         line
  1111.  
  1112. Characters that can precede each key:
  1113. '!'    When a '!' precedes the key, Vim will not insert the key but will
  1114.     instead reindent the current line.  This allows you to define a
  1115.     command key for reindenting the current line.  CTRL-F is the default
  1116.     key for this.  Be careful if you define CTRL-I for this because CTRL-I
  1117.     is the ASCII code for <Tab>.
  1118. '*'    When a '*' precedes the key, Vim will reindent the line before
  1119.     inserting the key.  If 'cinkeys' contains "*<Return>", Vim reindents
  1120.     the current line before opening a new line.
  1121. '0'    When a zero precedes the key (but appears after '!' or '*') Vim will
  1122.     reindent the line only if the key is the first character you type in
  1123.     the line.
  1124.  
  1125. When neither '!' nor '*' precedes the key, Vim reindents the line after you
  1126. type the key.  So ';' sets the indentation of a line which includes the ';'.
  1127.  
  1128. Special key names:
  1129. <>    Angle brackets mean spelled-out names of keys.  For example: "<Up>",
  1130.     "<Ins>" (see |key-notation|).
  1131. '^'    Letters preceded by a caret (^) are control characters.  For example:
  1132.     "^F" is CTRL-F.
  1133. 'o'    Reindent a line when you use the the "o" command or when Vim opens a
  1134.     new line below the current one (e.g., when you type <Return> in insert
  1135.     mode).
  1136. 'O'    Reindent a line when you use the "O" command.
  1137. 'e'    Reindent a line that starts with "else" when you type the second 'e'.
  1138.  
  1139. If you really want to reindent when you type 'o', 'O', 'e', '0', '<', '>', '*'
  1140. or '!', use "<o>", "<O>", "<e>", "<0>", "<<>", "<>>", "<*>" or "<!>",
  1141. respectively, for those keys.
  1142.  
  1143. For an emacs-style indent mode where lines aren't indented every time you
  1144. press Return but only if you press Tab, I suggest:
  1145.     :set cinkeys=0{,0},:,0#,!<Tab>,!^F
  1146.  
  1147. Note: If you change the current line's indentation manually, Vim ignores the
  1148. cindent settings for that line.  This prevents vim from reindenting after you
  1149. have changed the indent by typing <BS>, <Tab>, or <Space> in the indent or
  1150. used CTRL-T or CTRL-D.
  1151.  
  1152.                         *cinoptions-values*
  1153. The 'cinoptions' option sets how Vim performs indentation.  In the list below,
  1154. "N" represents a number of your choice (the number can be negative).  When
  1155. there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
  1156. "1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc.  You can use a
  1157. decimal point, too: "-0.5s" is minus half a 'shiftwidth'.  The examples below
  1158. assume a 'shiftwidth' of 4.
  1159.  
  1160.     >N    Amount added for "normal" indent.  Used after a line that should
  1161.           increase the indent (lines starting with "if", an opening brace,
  1162.           etc.).  (default 'shiftwidth').
  1163.  
  1164.         cino=            cino=>2        cino=>2s
  1165.           if (cond)          if (cond)          if (cond)
  1166.           {              {              {
  1167.               foo;        foo;              foo;
  1168.           }              }              }
  1169.  
  1170.     eN    Add N to the prevailing indent inside a set of braces if the
  1171.           opening brace at the End of the line (more precise: is not the
  1172.           first character in a line).  This is useful if you want a
  1173.           different indent when the '{' is at the start of the line from
  1174.           when '{' is at the end of the line.  (default 0).
  1175.  
  1176.         cino=            cino=e2        cino=e-2
  1177.           if (cond) {          if (cond) {      if (cond) {
  1178.               foo;            foo;        foo;
  1179.           }              }              }
  1180.           else              else          else
  1181.           {              {              {
  1182.               bar;          bar;              bar;
  1183.           }              }              }
  1184.  
  1185.     nN    Add N to the prevailing indent for a statement after an "if",
  1186.           "while", etc., if it is Not inside a set of braces.  This is
  1187.           useful if you want a different indent when there is no '{'
  1188.           before the statement from when there is a '{' before it.
  1189.           (default 0).
  1190.  
  1191.         cino=            cino=n2        cino=n-2
  1192.           if (cond)          if (cond)          if (cond)
  1193.               foo;            foo;        foo;
  1194.           else              else          else
  1195.           {              {              {
  1196.               bar;          bar;              bar;
  1197.           }              }              }
  1198.  
  1199.     fN    Place the first opening brace of a function or other block in
  1200.           column N.  This applies only for an opening brace that is not
  1201.           inside other braces and is at the start of the line.  What comes
  1202.           after the brace is put relative to this brace.  (default 0).
  1203.  
  1204.         cino=            cino=f.5s        cino=f1s
  1205.           func()          func()          func()
  1206.           {            {              {
  1207.               int foo;            int foo;          int foo;
  1208.  
  1209.     {N    Place opening braces N characters from the prevailing indent.
  1210.           This applies only for opening braces that are inside other
  1211.           braces.  (default 0).
  1212.  
  1213.         cino=            cino={.5s        cino={1s
  1214.           if (cond)          if (cond)          if (cond)
  1215.           {            {              {
  1216.               foo;          foo;              foo;
  1217.  
  1218.     }N    Place closing braces N characters from the matching opening
  1219.           brace.  (default 0).
  1220.  
  1221.         cino=            cino={2,}-0.5s    cino=}2
  1222.           if (cond)          if (cond)          if (cond)
  1223.           {            {          {
  1224.               foo;          foo;              foo;
  1225.           }              }                }
  1226.  
  1227.     ^N    Add N to the prevailing indent inside a set of braces if the
  1228.           opening brace is in column 0.  This can specify a different
  1229.           indent for whole of a function (some may like to set it to a
  1230.           negative number).  (default 0).
  1231.  
  1232.         cino=            cino=^-2        cino=^-s
  1233.           func()          func()          func()
  1234.           {              {              {
  1235.               if (cond)        if (cond)      if (cond)
  1236.               {            {          {
  1237.               a = b;        a = b;          a = b;
  1238.               }            }          }
  1239.           }              }              }
  1240.  
  1241.     :N    Place case labels N characters from the indent of the switch().
  1242.           (default 'shiftwidth').
  1243.  
  1244.         cino=            cino=:0
  1245.           switch (x)          switch(x)
  1246.           {              {
  1247.               case 1:          case 1:
  1248.               a = b;      a = b;
  1249.               default:          default:
  1250.           }              }
  1251.  
  1252.     =N    Place statements occurring after a case label N characters from
  1253.           the indent of the label.  (default 'shiftwidth').
  1254.  
  1255.         cino=            cino==10
  1256.            case 11:        case 11:  a = a + 1;
  1257.                a = a + 1;          b = b + 1;
  1258.  
  1259.     gN    Place C++ scope declarations N characters from the indent of the
  1260.           block they are in.  (default 'shiftwidth').  A scope declaration
  1261.           can be "public:", "protected:" or "private:".
  1262.  
  1263.         cino=            cino=g0
  1264.           {              {
  1265.               public:          public:
  1266.               a = b;      a = b;
  1267.               private:          private:
  1268.           }              }
  1269.  
  1270.     hN    Place statements occurring after a C++ scope declaration N
  1271.           characters from the indent of the label.  (default
  1272.           'shiftwidth').
  1273.  
  1274.         cino=            cino=h10
  1275.            public:        public:   a = a + 1;
  1276.                a = a + 1;          b = b + 1;
  1277.  
  1278.     pN    Parameter declarations for K&R-style function declarations will
  1279.           be indented N characters from the margin.  (default
  1280.           'shiftwidth').
  1281.  
  1282.         cino=            cino=p0        cino=p2s
  1283.           func(a, b)          func(a, b)      func(a, b)
  1284.               int a;          int a;              int a;
  1285.               char b;          char b;              char b;
  1286.  
  1287.     tN    Indent a function return type declaration N characters from the
  1288.           margin.  (default 'shiftwidth').
  1289.  
  1290.         cino=            cino=t0        cino=t7
  1291.               int          int             int
  1292.           func()          func()          func()
  1293.  
  1294.     +N    Indent a continuation line (a line that spills onto the next) N
  1295.           additional characters.  (default 'shiftwidth').
  1296.  
  1297.         cino=              cino=+10
  1298.           a = b + 9 *            a = b + 9 *
  1299.               c;                  c;
  1300.  
  1301.     cN    Indent comment lines after the comment opener, when there is no
  1302.           other text with which to align, N characters from the comment
  1303.           opener.  (default 3).  See also |format-comments|.
  1304.  
  1305.         cino=              cino=c5
  1306.           /*                /*
  1307.              text.             text.
  1308.            */                 */
  1309.  
  1310.     (N    When in unclosed parentheses, indent N characters from the line
  1311.           with the unclosed parentheses.  When N is 0 or the line starts
  1312.           with '(', line up with the unclosed parentheses.  (default
  1313.           'shiftwidth' * 2).
  1314.  
  1315.         cino=              cino=(0
  1316.           if (c1 && (c2 ||        if (c1 && (c2 ||
  1317.                   c3)               c3))
  1318.               foo;            foo;
  1319.           if (c1 &&            if (c1 &&
  1320.               (c2 || c3)        (c2 || c3)
  1321.              }                   }
  1322.  
  1323.     uN    Same as (N, but for one level deeper.  (default 'shiftwidth').
  1324.  
  1325.         cino=              cino=u2
  1326.           if (c123456789        if (c123456789
  1327.               && (c22345            && (c22345
  1328.                   || c3))              || c3))
  1329.  
  1330.     )N    Vim searches for unclosed parentheses at most N lines away.
  1331.           This limits the time needed to search for parentheses.  (default
  1332.           20 lines).
  1333.  
  1334.     *N    Vim searches for unclosed comments at most N lines away.  This
  1335.           limits the time needed to search for the start of a comment.
  1336.           (default 30 lines).
  1337.  
  1338. The defaults, spelled out in full, are:
  1339.     cinoptions=>s,e0,n0,f0,{0,}0,^0,:s,=s,ps,ts,+s,(2s,)20,*30
  1340.  
  1341. Vim puts a line in column 1 if:
  1342. - It starts with '#' (preprocessor directives), if 'cinkeys' contains '#'.
  1343. - It starts with a label (a keyword followed by ':', other than "case" and
  1344.   "default").
  1345. - Any combination of indentations causes the line to have less than 0
  1346.   indentation.
  1347.  
  1348.  vim:tw=78:ts=8:sw=8:
  1349.