change.txt 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. *change.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. This file describes commands that delete or change text. In this context,
  4. changing text means deleting the text and replacing it with other text using
  5. one command. You can undo all of these commands. You can repeat the non-Ex
  6. commands with the "." command.
  7. For inserting text see |insert.txt|.
  8. Type |gO| to see the table of contents.
  9. ==============================================================================
  10. 1. Deleting text *deleting* *E470*
  11. ["x]<Del> or *<Del>* *x* *dl*
  12. ["x]x Delete [count] characters under and after the cursor
  13. [into register x] (not |linewise|). Does the same as
  14. "dl".
  15. The <Del> key does not take a [count]. Instead, it
  16. deletes the last character of the count.
  17. See |'whichwrap'| for deleting a line break (join
  18. lines).
  19. *X* *dh*
  20. ["x]X Delete [count] characters before the cursor [into
  21. register x] (not |linewise|). Does the same as "dh".
  22. Also see |'whichwrap'|.
  23. *d*
  24. ["x]d{motion} Delete text that {motion} moves over [into register
  25. x]. See below for exceptions.
  26. *dd*
  27. ["x]dd Delete [count] lines [into register x] |linewise|.
  28. *D*
  29. ["x]D Delete the characters under the cursor until the end
  30. of the line and [count]-1 more lines [into register
  31. x]; synonym for "d$".
  32. (not |linewise|)
  33. {Visual}["x]x or *v_x* *v_d* *v_<Del>*
  34. {Visual}["x]d or
  35. {Visual}["x]<Del> Delete the highlighted text [into register x] (for
  36. {Visual} see |Visual-mode|).
  37. {Visual}["x]CTRL-H or *v_CTRL-H* *v_<BS>*
  38. {Visual}["x]<BS> When in Select mode: Delete the highlighted text [into
  39. register x].
  40. {Visual}["x]X or *v_X* *v_D* *v_b_D*
  41. {Visual}["x]D Delete the highlighted lines [into register x] (for
  42. {Visual} see |Visual-mode|). In Visual block mode,
  43. "D" deletes the highlighted text plus all text until
  44. the end of the line.
  45. *:d* *:de* *:del* *:delete* *:dl* *:dp*
  46. :[range]d[elete] [x] Delete [range] lines (default: current line) [into
  47. register x].
  48. Note these weird abbreviations:
  49. :dl delete and list
  50. :dell idem
  51. :delel idem
  52. :deletl idem
  53. :deletel idem
  54. :dp delete and print
  55. :dep idem
  56. :delp idem
  57. :delep idem
  58. :deletp idem
  59. :deletep idem
  60. :[range]d[elete] [x] {count}
  61. Delete {count} lines, starting with [range]
  62. (default: current line |cmdline-ranges|) [into
  63. register x].
  64. These commands delete text. You can repeat them with the `.` command
  65. (except `:d`) and undo them. Use Visual mode to delete blocks of text. See
  66. |registers| for an explanation of registers.
  67. An exception for the d{motion} command: If the motion is not linewise, the
  68. start and end of the motion are not in the same line, and there are only
  69. blanks before the start and there are no non-blanks after the end of the
  70. motion, the delete becomes linewise. This means that the delete also removes
  71. the line of blanks that you might expect to remain. Use the |o_v| operator to
  72. force the motion to be charwise.
  73. Trying to delete an empty region of text (e.g., "d0" in the first column)
  74. is an error when 'cpoptions' includes the 'E' flag.
  75. *J*
  76. J Join [count] lines, with a minimum of two lines.
  77. Remove the indent and insert up to two spaces (see
  78. below). Fails when on the last line of the buffer.
  79. If [count] is too big it is reduced to the number of
  80. lines available.
  81. *v_J*
  82. {Visual}J Join the highlighted lines, with a minimum of two
  83. lines. Remove the indent and insert up to two spaces
  84. (see below).
  85. *gJ*
  86. gJ Join [count] lines, with a minimum of two lines.
  87. Don't insert or remove any spaces.
  88. *v_gJ*
  89. {Visual}gJ Join the highlighted lines, with a minimum of two
  90. lines. Don't insert or remove any spaces.
  91. *:j* *:join*
  92. :[range]j[oin][!] [flags]
  93. Join [range] lines. Same as "J", except with [!]
  94. the join does not insert or delete any spaces.
  95. If a [range] has equal start and end values, this
  96. command does nothing. The default behavior is to
  97. join the current line with the line below it.
  98. See |ex-flags| for [flags].
  99. :[range]j[oin][!] {count} [flags]
  100. Join {count} lines, starting with [range] (default:
  101. current line |cmdline-ranges|). Same as "J", except
  102. with [!] the join does not insert or delete any
  103. spaces.
  104. See |ex-flags| for [flags].
  105. These commands delete the <EOL> between lines. This has the effect of joining
  106. multiple lines into one line. You can repeat these commands (except `:j`) and
  107. undo them.
  108. These commands, except "gJ", insert one space in place of the <EOL> unless
  109. there is trailing white space or the next line starts with a ')'. These
  110. commands, except "gJ", delete any leading white space on the next line. If
  111. the 'joinspaces' option is on, these commands insert two spaces after a '.',
  112. '!' or '?'.
  113. The 'B' and 'M' flags in 'formatoptions' change the behavior for inserting
  114. spaces before and after a multibyte character |fo-table|.
  115. The '[ mark is set at the end of the first line that was joined, '] at the end
  116. of the resulting line.
  117. ==============================================================================
  118. 2. Delete and insert *delete-insert* *replacing*
  119. *R*
  120. R Enter Replace mode: Each character you type replaces
  121. an existing character, starting with the character
  122. under the cursor. Repeat the entered text [count]-1
  123. times. See |Replace-mode| for more details.
  124. *gR*
  125. gR Enter Virtual Replace mode: Each character you type
  126. replaces existing characters in screen space. So a
  127. <Tab> may replace several characters at once.
  128. Repeat the entered text [count]-1 times. See
  129. |Virtual-Replace-mode| for more details.
  130. *c*
  131. ["x]c{motion} Delete {motion} text [into register x] and start
  132. insert. When 'cpoptions' includes the 'E' flag and
  133. there is no text to delete (e.g., with "cTx" when the
  134. cursor is just after an 'x'), an error occurs and
  135. insert mode does not start (this is Vi compatible).
  136. When 'cpoptions' does not include the 'E' flag, the
  137. "c" command always starts insert mode, even if there
  138. is no text to delete.
  139. *cc*
  140. ["x]cc Delete [count] lines [into register x] and start
  141. insert |linewise|. If 'autoindent' is on, preserve
  142. the indent of the first line.
  143. *C*
  144. ["x]C Delete from the cursor position to the end of the
  145. line and [count]-1 more lines [into register x], and
  146. start insert. Synonym for c$ (not |linewise|).
  147. *s*
  148. ["x]s Delete [count] characters [into register x] and start
  149. insert (s stands for Substitute). Synonym for "cl"
  150. (not |linewise|).
  151. *S*
  152. ["x]S Delete [count] lines [into register x] and start
  153. insert. Synonym for "cc" |linewise|.
  154. {Visual}["x]c or *v_c* *v_s*
  155. {Visual}["x]s Delete the highlighted text [into register x] and
  156. start insert (for {Visual} see |Visual-mode|).
  157. *v_r*
  158. {Visual}r{char} Replace all selected characters by {char}.
  159. *v_C*
  160. {Visual}["x]C Delete the highlighted lines [into register x] and
  161. start insert. In Visual block mode it works
  162. differently |v_b_C|.
  163. *v_S*
  164. {Visual}["x]S Delete the highlighted lines [into register x] and
  165. start insert (for {Visual} see |Visual-mode|).
  166. *v_R*
  167. {Visual}["x]R Currently just like {Visual}["x]S. In a next version
  168. it might work differently.
  169. Notes:
  170. - You can end Insert and Replace mode with <Esc>.
  171. - See the section "Insert and Replace mode" |mode-ins-repl| for the other
  172. special characters in these modes.
  173. - The effect of [count] takes place after Vim exits Insert or Replace mode.
  174. - When the 'cpoptions' option contains '$' and the change is within one line,
  175. Vim continues to show the text to be deleted and puts a '$' at the last
  176. deleted character.
  177. See |registers| for an explanation of registers.
  178. Replace mode is just like Insert mode, except that every character you enter
  179. deletes one character. If you reach the end of a line, Vim appends any
  180. further characters (just like Insert mode). In Replace mode, the backspace
  181. key restores the original text (if there was any). (See section "Insert and
  182. Replace mode" |mode-ins-repl|).
  183. *cw* *cW*
  184. Special case: When the cursor is in a word, "cw" and "cW" do not include the
  185. white space after a word, they only change up to the end of the word. This is
  186. because Vim interprets "cw" as change-word, and a word does not include the
  187. following white space.
  188. If you prefer "cw" to include the space after a word, use this mapping: >
  189. :map cw dwi
  190. Or use "caw" (see |aw|).
  191. *:c* *:ch* *:change*
  192. :{range}c[hange][!] Replace lines of text with some different text.
  193. Type a line containing only "." to stop replacing.
  194. Without {range}, this command changes only the current
  195. line.
  196. Adding [!] toggles 'autoindent' for the time this
  197. command is executed.
  198. ==============================================================================
  199. 3. Simple changes *simple-change* *changing*
  200. *r*
  201. r{char} Replace the character under the cursor with {char}.
  202. If {char} is a <CR> or <NL>, a line break replaces the
  203. character. To replace with a real <CR>, use CTRL-V
  204. <CR>. CTRL-V <NL> replaces with a <Nul>.
  205. If {char} is CTRL-E or CTRL-Y the character from the
  206. line below or above is used, just like with |i_CTRL-E|
  207. and |i_CTRL-Y|. This also works with a count, thus
  208. `10r<C-E>` copies 10 characters from the line below.
  209. If you give a [count], Vim replaces [count] characters
  210. with [count] {char}s. When {char} is a <CR> or <NL>,
  211. however, Vim inserts only one <CR>: "5r<CR>" replaces
  212. five characters with a single line break.
  213. When {char} is a <CR> or <NL>, Vim performs
  214. autoindenting. This works just like deleting the
  215. characters that are replaced and then doing
  216. "i<CR><Esc>".
  217. {char} can be entered as a digraph |digraph-arg|.
  218. |:lmap| mappings apply to {char}. The CTRL-^ command
  219. in Insert mode can be used to switch this on/off
  220. |i_CTRL-^|. See |utf-8-char-arg| about using
  221. composing characters when 'encoding' is Unicode.
  222. *gr*
  223. gr{char} Replace the virtual characters under the cursor with
  224. {char}. This replaces in screen space, not file
  225. space. See |gR| and |Virtual-Replace-mode| for more
  226. details. As with |r| a count may be given.
  227. {char} can be entered like with |r|.
  228. *digraph-arg*
  229. The argument for Normal mode commands like |r| and |t| is a single character.
  230. When 'cpo' doesn't contain the 'D' flag, this character can also be entered
  231. like |digraphs|. First type CTRL-K and then the two digraph characters.
  232. *case*
  233. The following commands change the case of letters. The currently active
  234. |locale| is used. See |:language|. The LC_CTYPE value matters here.
  235. *~*
  236. ~ 'notildeop' option: Switch case of the character
  237. under the cursor and move the cursor to the right.
  238. If a [count] is given, do that many characters.
  239. ~{motion} 'tildeop' option: switch case of {motion} text.
  240. *g~*
  241. g~{motion} Switch case of {motion} text.
  242. g~g~ *g~g~* *g~~*
  243. g~~ Switch case of current line.
  244. *v_~*
  245. {Visual}~ Switch case of highlighted text (for {Visual} see
  246. |Visual-mode|).
  247. *v_U*
  248. {Visual}U Make highlighted text uppercase (for {Visual} see
  249. |Visual-mode|).
  250. *gU* *uppercase*
  251. gU{motion} Make {motion} text uppercase.
  252. Example: >
  253. :map! <C-F> <Esc>gUiw`]a
  254. < This works in Insert mode: press CTRL-F to make the
  255. word before the cursor uppercase. Handy to type
  256. words in lowercase and then make them uppercase.
  257. gUgU *gUgU* *gUU*
  258. gUU Make current line uppercase.
  259. *v_u*
  260. {Visual}u Make highlighted text lowercase (for {Visual} see
  261. |Visual-mode|).
  262. *gu* *lowercase*
  263. gu{motion} Make {motion} text lowercase.
  264. gugu *gugu* *guu*
  265. guu Make current line lowercase.
  266. *g?* *rot13*
  267. g?{motion} Rot13 encode {motion} text.
  268. *v_g?*
  269. {Visual}g? Rot13 encode the highlighted text (for {Visual} see
  270. |Visual-mode|).
  271. g?g? *g?g?* *g??*
  272. g?? Rot13 encode current line.
  273. To turn one line into title caps, make every first letter of a word
  274. uppercase: >
  275. :s/\v<(.)(\w*)/\u\1\L\2/g
  276. Adding and subtracting ~
  277. *CTRL-A*
  278. CTRL-A Add [count] to the number or alphabetic character at
  279. or after the cursor.
  280. *v_CTRL-A*
  281. {Visual}CTRL-A Add [count] to the number or alphabetic character in
  282. the highlighted text.
  283. *v_g_CTRL-A*
  284. {Visual}g CTRL-A Add [count] to the number or alphabetic character in
  285. the highlighted text. If several lines are
  286. highlighted, each one will be incremented by an
  287. additional [count] (so effectively creating a
  288. [count] incrementing sequence).
  289. For Example, if you have this list of numbers:
  290. 1. ~
  291. 1. ~
  292. 1. ~
  293. 1. ~
  294. Move to the second "1." and Visually select three
  295. lines, pressing g CTRL-A results in:
  296. 1. ~
  297. 2. ~
  298. 3. ~
  299. 4. ~
  300. *CTRL-X*
  301. CTRL-X Subtract [count] from the number or alphabetic
  302. character at or after the cursor.
  303. *v_CTRL-X*
  304. {Visual}CTRL-X Subtract [count] from the number or alphabetic
  305. character in the highlighted text.
  306. *v_g_CTRL-X*
  307. {Visual}g CTRL-X Subtract [count] from the number or alphabetic
  308. character in the highlighted text. If several lines
  309. are highlighted, each value will be decremented by an
  310. additional [count] (so effectively creating a [count]
  311. decrementing sequence).
  312. The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned
  313. binary/octal/hexadecimal numbers and alphabetic characters.
  314. This depends on the 'nrformats' option:
  315. - When 'nrformats' includes "bin", Vim assumes numbers starting with '0b' or
  316. '0B' are binary.
  317. - When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
  318. to be octal, unless the number includes a '8' or '9'. Other numbers are
  319. decimal and may have a preceding minus sign.
  320. If the cursor is on a number, the commands apply to that number; otherwise
  321. Vim uses the number to the right of the cursor.
  322. - When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or
  323. '0X' are hexadecimal. The case of the rightmost letter in the number
  324. determines the case of the resulting hexadecimal number. If there is no
  325. letter in the current number, Vim uses the previously detected case.
  326. - When 'nrformats' includes "alpha", Vim will change the alphabetic character
  327. under or after the cursor. This is useful to make lists with an alphabetic
  328. index.
  329. For decimals a leading negative sign is considered for incrementing or
  330. decrementing, for binary, octal and hex values, it won't be considered. To
  331. ignore the sign Visually select the number before using CTRL-A or CTRL-X.
  332. For numbers with leading zeros (including all octal and hexadecimal numbers),
  333. Vim preserves the number of characters in the number when possible. CTRL-A on
  334. "0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".
  335. There is one exception: When a number that starts with a zero is found not to
  336. be octal (it contains a '8' or '9'), but 'nrformats' does include "octal",
  337. leading zeros are removed to avoid that the result may be recognized as an
  338. octal number.
  339. Note that when 'nrformats' includes "octal", decimal numbers with leading
  340. zeros cause mistakes, because they can be confused with octal numbers.
  341. Note similarly, when 'nrformats' includes "bin", binary numbers with a leading
  342. '0x' or '0X' can be interpreted as hexadecimal rather than binary since '0b'
  343. are valid hexadecimal digits.
  344. The CTRL-A command is very useful in a macro. Example: Use the following
  345. steps to make a numbered list.
  346. 1. Create the first list entry, make sure it starts with a number.
  347. 2. qa - start recording into register 'a'
  348. 3. Y - yank the entry
  349. 4. p - put a copy of the entry below the first one
  350. 5. CTRL-A - increment the number
  351. 6. q - stop recording
  352. 7. <count>@a - repeat the yank, put and increment <count> times
  353. SHIFTING LINES LEFT OR RIGHT *shift-left-right*
  354. *<*
  355. <{motion} Shift {motion} lines one 'shiftwidth' leftwards.
  356. If the 'shiftwidth' option is set to zero, the amount
  357. of indent is calculated at the first non-blank
  358. character in the line.
  359. *<<*
  360. << Shift [count] lines one 'shiftwidth' leftwards.
  361. *v_<*
  362. {Visual}[count]< Shift the highlighted lines [count] 'shiftwidth'
  363. leftwards (for {Visual} see |Visual-mode|).
  364. *>*
  365. >{motion} Shift {motion} lines one 'shiftwidth' rightwards.
  366. If the 'shiftwidth' option is set to zero, the amount
  367. of indent is calculated at the first non-blank
  368. character in the line.
  369. *>>*
  370. >> Shift [count] lines one 'shiftwidth' rightwards.
  371. *v_>*
  372. {Visual}[count]> Shift the highlighted lines [count] 'shiftwidth'
  373. rightwards (for {Visual} see |Visual-mode|).
  374. *:<*
  375. :[range]< Shift [range] lines one 'shiftwidth' left. Repeat '<'
  376. for shifting multiple 'shiftwidth's.
  377. :[range]< {count} Shift {count} lines one 'shiftwidth' left, starting
  378. with [range] (default current line |cmdline-ranges|).
  379. Repeat '<' for shifting multiple 'shiftwidth's.
  380. :[range]le[ft] [indent] left align lines in [range]. Sets the indent in the
  381. lines to [indent] (default 0).
  382. *:>*
  383. :[range]> [flags] Shift {count} [range] lines one 'shiftwidth' right.
  384. Repeat '>' for shifting multiple 'shiftwidth's.
  385. See |ex-flags| for [flags].
  386. :[range]> {count} [flags]
  387. Shift {count} lines one 'shiftwidth' right, starting
  388. with [range] (default current line |cmdline-ranges|).
  389. Repeat '>' for shifting multiple 'shiftwidth's.
  390. See |ex-flags| for [flags].
  391. The ">" and "<" commands are handy for changing the indentation within
  392. programs. Use the 'shiftwidth' option to set the size of the white space
  393. which these commands insert or delete. Normally the 'shiftwidth' option is 8,
  394. but you can set it to, say, 3 to make smaller indents. The shift leftwards
  395. stops when there is no indent. The shift right does not affect empty lines.
  396. If the 'shiftround' option is on, the indent is rounded to a multiple of
  397. 'shiftwidth'.
  398. If the 'smartindent' option is on, or 'cindent' is on and 'cinkeys' contains
  399. '#' with a zero value, shift right does not affect lines starting with '#'
  400. (these are supposed to be C preprocessor lines that must stay in column 1).
  401. This can be changed with the 'cino' option, see |cino-#|.
  402. When the 'expandtab' option is off (this is the default) Vim uses <Tab>s as
  403. much as possible to make the indent. You can use ">><<" to replace an indent
  404. made out of spaces with the same indent made out of <Tab>s (and a few spaces
  405. if necessary). If the 'expandtab' option is on, Vim uses only spaces. Then
  406. you can use ">><<" to replace <Tab>s in the indent by spaces (or use
  407. `:retab!`).
  408. To move a line several 'shiftwidth's, use Visual mode or the `:` commands.
  409. For example: >
  410. Vjj4> move three lines 4 indents to the right
  411. :<<< move current line 3 indents to the left
  412. :>> 5 move 5 lines 2 indents to the right
  413. :5>> move line 5 2 indents to the right
  414. ==============================================================================
  415. 4. Complex changes *complex-change*
  416. 4.1 Filter commands *filter*
  417. A filter is a program that accepts text at standard input, changes it in some
  418. way, and sends it to standard output. You can use the commands below to send
  419. some text through a filter, so that it is replaced by the filter output.
  420. Examples of filters are "sort", which sorts lines alphabetically, and
  421. "indent", which formats C program files (you need a version of indent that
  422. works like a filter; not all versions do). The 'shell' option specifies the
  423. shell Vim uses to execute the filter command. You can repeat filter commands
  424. with ".". Vim does not recognize a comment (starting with '"') after the
  425. `:!` command.
  426. *!*
  427. !{motion}{filter} Filter {motion} text lines through the external
  428. program {filter}.
  429. *!!*
  430. !!{filter} Filter [count] lines through the external program
  431. {filter}.
  432. *v_!*
  433. {Visual}!{filter} Filter the highlighted lines through the external
  434. program {filter} (for {Visual} see |Visual-mode|).
  435. :{range}![!]{filter} [!][arg] *:range!*
  436. Filter {range} lines through the external program
  437. {filter}. Vim replaces the optional bangs with the
  438. latest given command and appends the optional [arg].
  439. Vim saves the output of the filter command in a
  440. temporary file and then reads the file into the buffer
  441. |tempfile|. Vim uses the 'shellredir' option to
  442. redirect the filter output to the temporary file.
  443. However, if the 'shelltemp' option is off then pipes
  444. are used when possible (on Unix).
  445. When the 'R' flag is included in 'cpoptions' marks in
  446. the filtered lines are deleted, unless the
  447. |:keepmarks| command is used. Example: >
  448. :keepmarks '<,'>!sort
  449. < When the number of lines after filtering is less than
  450. before, marks in the missing lines are deleted anyway.
  451. *=*
  452. ={motion} Filter {motion} lines through the external program
  453. given with the 'equalprg' option. When the 'equalprg'
  454. option is empty (this is the default), use the
  455. internal formatting function |C-indenting| and
  456. |'lisp'|. But when 'indentexpr' is not empty, it will
  457. be used instead |indent-expression|.
  458. *==*
  459. == Filter [count] lines like with ={motion}.
  460. *v_=*
  461. {Visual}= Filter the highlighted lines like with ={motion}.
  462. *tempfile* *setuid*
  463. Vim uses temporary files for filtering, generating diffs and also for
  464. tempname(). For Unix, the file will be in a private directory (only
  465. accessible by the current user) to avoid security problems (e.g., a symlink
  466. attack or other people reading your file). When Vim exits the directory and
  467. all files in it are deleted. When Vim has the setuid bit set this may cause
  468. problems, the temp file is owned by the setuid user but the filter command
  469. probably runs as the original user.
  470. Directory for temporary files is created in the first possible directory of:
  471. Unix: $TMPDIR, /tmp, current-dir, $HOME.
  472. Windows: $TMPDIR, $TMP, $TEMP, $USERPROFILE, current-dir.
  473. 4.2 Substitute *:substitute*
  474. *:s* *:su*
  475. :[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
  476. For each line in [range] replace a match of {pattern}
  477. with {string}.
  478. For the {pattern} see |pattern|.
  479. {string} can be a literal string, or something
  480. special; see |sub-replace-special|.
  481. When [range] and [count] are omitted, replace in the
  482. current line only. When [count] is given, replace in
  483. [count] lines, starting with the last line in [range].
  484. When [range] is omitted start in the current line.
  485. *E939*
  486. [count] must be a positive number. Also see
  487. |cmdline-ranges|.
  488. See |:s_flags| for [flags].
  489. The delimiter doesn't need to be /, see
  490. |pattern-delimiter|.
  491. :[range]s[ubstitute] [flags] [count]
  492. :[range]&[&][flags] [count] *:&*
  493. Repeat last :substitute with same search pattern and
  494. substitute string, but without the same flags. You
  495. may add [flags], see |:s_flags|.
  496. Note that after `:substitute` the '&' flag can't be
  497. used, it's recognized as a pattern separator.
  498. The space between `:substitute` and the 'c', 'g',
  499. 'i', 'I' and 'r' flags isn't required, but in scripts
  500. it's a good idea to keep it to avoid confusion.
  501. Also see the two and three letter commands to repeat
  502. :substitute below |:substitute-repeat|.
  503. :[range]~[&][flags] [count] *:~*
  504. Repeat last substitute with same substitute string
  505. but with last used search pattern. This is like
  506. `:&r`. See |:s_flags| for [flags].
  507. *&*
  508. & Synonym for `:s` (repeat last substitute). Note
  509. that the flags are not remembered, thus it might
  510. actually work differently. You can use `:&&` to keep
  511. the flags.
  512. *&-default*
  513. Mapped to ":&&<CR>" by default. |default-mappings|
  514. *g&*
  515. g& Synonym for `:%s//~/&` (repeat last substitute with
  516. last search pattern on all lines with the same flags).
  517. For example, when you first do a substitution with
  518. `:s/pattern/repl/flags` and then `/search` for
  519. something else, `g&` will do `:%s/search/repl/flags`.
  520. Mnemonic: global substitute.
  521. *:snomagic* *:sno*
  522. :[range]sno[magic] ... Same as `:substitute`, but always use 'nomagic'.
  523. *:smagic* *:sm*
  524. :[range]sm[agic] ... Same as `:substitute`, but always use 'magic'.
  525. *:s_flags*
  526. The flags that you can use for the substitute commands:
  527. *:&&*
  528. [&] Must be the first one: Keep the flags from the previous substitute
  529. command. Examples: >
  530. :&&
  531. :s/this/that/&
  532. < Note that `:s` and `:&` don't keep the flags.
  533. [c] Confirm each substitution. Vim highlights the matching string (with
  534. |hl-IncSearch|). You can type: *:s_c*
  535. 'y' to substitute this match
  536. 'l' to substitute this match and then quit ("last")
  537. 'n' to skip this match
  538. <Esc> to quit substituting
  539. 'a' to substitute this and all remaining matches
  540. 'q' to quit substituting
  541. CTRL-E to scroll the screen up
  542. CTRL-Y to scroll the screen down
  543. *:s_e*
  544. [e] When the search pattern fails, do not issue an error message and, in
  545. particular, continue in maps as if no error occurred. This is most
  546. useful to prevent the "No match" error from breaking a mapping. Vim
  547. does not suppress the following error messages, however:
  548. Regular expressions can't be delimited by letters
  549. \ should be followed by /, ? or &
  550. No previous substitute regular expression
  551. Trailing characters
  552. Interrupted
  553. *:s_g*
  554. [g] Replace all occurrences in the line. Without this argument,
  555. replacement occurs only for the first occurrence in each line. If the
  556. 'gdefault' option is on, this flag is on by default and the [g]
  557. argument switches it off.
  558. *:s_i*
  559. [i] Ignore case for the pattern. The 'ignorecase' and 'smartcase' options
  560. are not used.
  561. *:s_I*
  562. [I] Don't ignore case for the pattern. The 'ignorecase' and 'smartcase'
  563. options are not used.
  564. *:s_n*
  565. [n] Report the number of matches, do not actually substitute. The [c]
  566. flag is ignored. The matches are reported as if 'report' is zero.
  567. Useful to |count-items|.
  568. If \= |sub-replace-expression| is used, the expression will be
  569. evaluated in the |sandbox| at every match.
  570. [p] Print the line containing the last substitute. *:s_p*
  571. [#] Like [p] and prepend the line number. *:s_#*
  572. [l] Like [p] but print the text like |:list|. *:s_l*
  573. *:s_r*
  574. [r] Only useful in combination with `:&` or `:s` without arguments. `:&r`
  575. works the same way as `:~`: When the search pattern is empty, use the
  576. previously used search pattern instead of the search pattern from the
  577. last substitute or `:global`. If the last command that did a search
  578. was a substitute or `:global`, there is no effect. If the last
  579. command was a search command such as "/", use the pattern from that
  580. command.
  581. For `:s` with an argument this already happens: >
  582. :s/blue/red/
  583. /green
  584. :s//red/ or :~ or :&r
  585. < The last commands will replace "green" with "red". >
  586. :s/blue/red/
  587. /green
  588. :&
  589. < The last command will replace "blue" with "red".
  590. Note that there is no flag to change the "magicness" of the pattern. A
  591. different command is used instead, or you can use |/\v| and friends. The
  592. reason is that the flags can only be found by skipping the pattern, and in
  593. order to skip the pattern the "magicness" must be known. Catch 22!
  594. If the {pattern} for the substitute command is empty, the command uses the
  595. pattern from the last substitute or `:global` command. If there is none, but
  596. there is a previous search pattern, that one is used. With the [r] flag, the
  597. command uses the pattern from the last substitute, `:global`, or search
  598. command.
  599. If the {string} is omitted the substitute is done as if it's empty. Thus the
  600. matched pattern is deleted. The separator after {pattern} can also be left
  601. out then. Example: >
  602. :%s/TESTING
  603. This deletes "TESTING" from all lines, but only one per line.
  604. For compatibility with Vi these two exceptions are allowed:
  605. "\/{string}/" and "\?{string}?" do the same as "//{string}/r".
  606. "\&{string}&" does the same as "//{string}/".
  607. *pattern-delimiter* *E146*
  608. Instead of the '/' which surrounds the pattern and replacement string, you can
  609. use another single-byte character. This is useful if you want to include a
  610. '/' in the search pattern or replacement string. Example: >
  611. :s+/+//+
  612. You can use most characters, but not an alphanumeric character, '\', '"' or
  613. '|'.
  614. For the definition of a pattern, see |pattern|. In Visual block mode, use
  615. |/\%V| in the pattern to have the substitute work in the block only.
  616. Otherwise it works on whole lines anyway.
  617. *sub-replace-special* *:s\=*
  618. When the {string} starts with "\=" it is evaluated as an expression, see
  619. |sub-replace-expression|. You can use that for complex replacement or special
  620. characters.
  621. The substitution is limited in recursion to 4 levels. *E1290*
  622. Otherwise these characters in {string} have a special meaning:
  623. magic nomagic action ~
  624. & \& replaced with the whole matched pattern *s/\&*
  625. \& & replaced with &
  626. \0 replaced with the whole matched pattern *\0* *s/\0*
  627. \1 replaced with the matched pattern in the first
  628. pair of () *s/\1*
  629. \2 replaced with the matched pattern in the second
  630. pair of () *s/\2*
  631. .. .. *s/\3*
  632. \9 replaced with the matched pattern in the ninth
  633. pair of () *s/\9*
  634. ~ \~ replaced with the {string} of the previous
  635. substitute *s~*
  636. \~ ~ replaced with ~ *s/\~*
  637. \u next character made uppercase *s/\u*
  638. \U following characters made uppercase, until \E *s/\U*
  639. \l next character made lowercase *s/\l*
  640. \L following characters made lowercase, until \E *s/\L*
  641. \e end of \u, \U, \l and \L (NOTE: not <Esc>!) *s/\e*
  642. \E end of \u, \U, \l and \L *s/\E*
  643. <CR> split line in two at this point
  644. (Type the <CR> as CTRL-V <Enter>) *s<CR>*
  645. \r idem *s/\r*
  646. \<CR> insert a carriage-return (CTRL-M)
  647. (Type the <CR> as CTRL-V <Enter>) *s/\<CR>*
  648. \n insert a <NL> (<NUL> in the file)
  649. (does NOT break the line) *s/\n*
  650. \b insert a <BS> *s/\b*
  651. \t insert a <Tab> *s/\t*
  652. \\ insert a single backslash *s/\\*
  653. \x where x is any character not mentioned above:
  654. Reserved for future expansion
  655. The special meaning is also used inside the third argument {sub} of
  656. the |substitute()| function with the following exceptions:
  657. - A % inserts a percent literally without regard to 'cpoptions'.
  658. - magic is always set without regard to 'magic'.
  659. - A ~ inserts a tilde literally.
  660. - <CR> and \r inserts a carriage-return (CTRL-M).
  661. - \<CR> does not have a special meaning. It's just one of \x.
  662. Examples: >
  663. :s/a\|b/xxx\0xxx/g modifies "a b" to "xxxaxxx xxxbxxx"
  664. :s/\([abc]\)\([efg]\)/\2\1/g modifies "af fa bg" to "fa fa gb"
  665. :s/abcde/abc^Mde/ modifies "abcde" to "abc", "de" (two lines)
  666. :s/$/\^M/ modifies "abcde" to "abcde^M"
  667. :s/\w\+/\u\0/g modifies "bla bla" to "Bla Bla"
  668. :s/\w\+/\L\u\0/g modifies "BLA bla" to "Bla Bla"
  669. Note: "\L\u" can be used to capitalize the first letter of a word. This is
  670. not compatible with Vi and older versions of Vim, where the "\u" would cancel
  671. out the "\L". Same for "\U\l".
  672. Note: In previous versions CTRL-V was handled in a special way. Since this is
  673. not Vi compatible, this was removed. Use a backslash instead.
  674. command text result ~
  675. :s/aa/a^Ma/ aa a<line-break>a
  676. :s/aa/a\^Ma/ aa a^Ma
  677. :s/aa/a\\^Ma/ aa a\<line-break>a
  678. (you need to type CTRL-V <CR> to get a ^M here)
  679. The numbering of "\1", "\2" etc. is done based on which "\(" comes first in
  680. the pattern (going left to right). When a parentheses group matches several
  681. times, the last one will be used for "\1", "\2", etc. Example: >
  682. :s/\(\(a[a-d] \)*\)/\2/ modifies "aa ab x" to "ab x"
  683. The "\2" is for "\(a[a-d] \)". At first it matches "aa ", secondly "ab ".
  684. When using parentheses in combination with '|', like in \([ab]\)\|\([cd]\),
  685. either the first or second pattern in parentheses did not match, so either
  686. \1 or \2 is empty. Example: >
  687. :s/\([ab]\)\|\([cd]\)/\1x/g modifies "a b c d" to "ax bx x x"
  688. <
  689. *:sc* *:sce* *:scg* *:sci* *:scI* *:scl* *:scp* *:sg* *:sgc*
  690. *:sge* *:sgi* *:sgI* *:sgl* *:sgn* *:sgp* *:sgr* *:sI* *:si*
  691. *:sic* *:sIc* *:sie* *:sIe* *:sIg* *:sIl* *:sin* *:sIn* *:sIp*
  692. *:sip* *:sIr* *:sir* *:sr* *:src* *:srg* *:sri* *:srI* *:srl*
  693. *:srn* *:srp* *:substitute-repeat*
  694. 2-letter and 3-letter :substitute commands ~
  695. These commands repeat the previous `:substitute` command with the given flags.
  696. The first letter is always "s", followed by one or two of the possible flag
  697. characters. For example `:sce` works like `:s///ce`. The table lists the
  698. possible combinations, not all flags are possible, because the command is
  699. short for another command.
  700. List of :substitute commands
  701. | c e g i I n p l r
  702. | c :sc :sce :scg :sci :scI :scn :scp :scl
  703. | e
  704. | g :sgc :sge :sg :sgi :sgI :sgn :sgp :sgl :sgr
  705. | i :sic :sie :si :siI :sin :sip :sir
  706. | I :sIc :sIe :sIg :sIi :sI :sIn :sIp :sIl :sIr
  707. | n
  708. | p
  709. | l
  710. | r :src :srg :sri :srI :srn :srp :srl :sr
  711. Exceptions:
  712. :scr is `:scriptnames`
  713. :se is `:set`
  714. :sig is `:sign`
  715. :sil is `:silent`
  716. :sn is `:snext`
  717. :sp is `:split`
  718. :sl is `:sleep`
  719. :sre is `:srewind`
  720. Substitute with an expression *sub-replace-expression*
  721. *sub-replace-\=* *s/\=*
  722. When the substitute string starts with "\=" the remainder is interpreted as an
  723. expression.
  724. The special meaning for characters as mentioned at |sub-replace-special| does
  725. not apply except for "<CR>". A <NL> character is used as a line break, you
  726. can get one with a double-quote string: "\n". Prepend a backslash to get a
  727. real <NL> character (which will be a NUL in the file).
  728. The "\=" notation can also be used inside the third argument {sub} of
  729. |substitute()| function. In this case, the special meaning for characters as
  730. mentioned at |sub-replace-special| does not apply at all. Especially, <CR> and
  731. <NL> are interpreted not as a line break but as a carriage-return and a
  732. new-line respectively.
  733. When the result is a |List| then the items are joined with separating line
  734. breaks. Thus each item becomes a line, except that they can contain line
  735. breaks themselves.
  736. The |submatch()| function can be used to obtain matched text. The whole
  737. matched text can be accessed with "submatch(0)". The text matched with the
  738. first pair of () with "submatch(1)". Likewise for further sub-matches in ().
  739. Be careful: The separation character must not appear in the expression!
  740. Consider using a character like "@" or ":". There is no problem if the result
  741. of the expression contains the separation character.
  742. Examples: >
  743. :s@\n@\="\r" .. expand("$HOME") .. "\r"@
  744. This replaces an end-of-line with a new line containing the value of $HOME. >
  745. s/E/\="\<Char-0x20ac>"/g
  746. This replaces each 'E' character with a euro sign. Read more in |<Char->|.
  747. 4.3 Changing tabs *change-tabs*
  748. *:ret* *:retab* *:retab!*
  749. :[range]ret[ab][!] [new_tabstop]
  750. Replace all sequences of white-space containing a
  751. <Tab> with new strings of white-space using the new
  752. tabstop value given. If you do not specify a new
  753. tabstop size or it is zero, Vim uses the current value
  754. of 'tabstop'.
  755. The current value of 'tabstop' is always used to
  756. compute the width of existing tabs.
  757. With !, Vim also replaces strings of only normal
  758. spaces with tabs where appropriate.
  759. With 'expandtab' on, Vim replaces all tabs with the
  760. appropriate number of spaces.
  761. This command sets 'tabstop' to the new value given,
  762. and if performed on the whole file, which is default,
  763. should not make any visible change.
  764. Careful: This command modifies any <Tab> characters
  765. inside of strings in a C program. Use "\t" to avoid
  766. this (that's a good habit anyway).
  767. `:retab!` may also change a sequence of spaces by
  768. <Tab> characters, which can mess up a printf().
  769. A list of tab widths separated by commas may be used
  770. in place of a single tabstop. Each value in the list
  771. represents the width of one tabstop, except the final
  772. value which applies to all following tabstops.
  773. *retab-example*
  774. Example for using autocommands and ":retab" to edit a file which is stored
  775. with tabstops at 8 but edited with tabstops set at 4. Warning: white space
  776. inside of strings can change! Also see 'softtabstop' option. >
  777. :auto BufReadPost *.xx retab! 4
  778. :auto BufWritePre *.xx retab! 8
  779. :auto BufWritePost *.xx retab! 4
  780. :auto BufNewFile *.xx set ts=4
  781. ==============================================================================
  782. 5. Copying and moving text *copy-move*
  783. *quote*
  784. "{register} Use {register} for next delete, yank or put. Use
  785. an uppercase character to append with delete and yank.
  786. Registers ".", "%", "#" and ":" only work with put.
  787. *:reg* *:registers*
  788. :reg[isters] Display the type and contents of all numbered and
  789. named registers. If a register is written to for
  790. |:redir| it will not be listed.
  791. Type can be one of:
  792. "c" for |characterwise| text
  793. "l" for |linewise| text
  794. "b" for |blockwise-visual| text
  795. :reg[isters] {arg} Display the contents of the numbered and named
  796. registers that are mentioned in {arg}. For example: >
  797. :reg 1a
  798. < to display registers '1' and 'a'. Spaces are allowed
  799. in {arg}.
  800. *:di* *:display*
  801. :di[splay] [arg] Same as :registers.
  802. *y* *yank*
  803. ["x]y{motion} Yank {motion} text [into register x]. When no
  804. characters are to be yanked (e.g., "y0" in column 1),
  805. this is an error when 'cpoptions' includes the 'E'
  806. flag.
  807. *yy*
  808. ["x]yy Yank [count] lines [into register x] |linewise|.
  809. *Y*
  810. ["x]Y yank [count] lines [into register x] (synonym for
  811. yy, |linewise|).
  812. *Y-default*
  813. Mapped to "y$" by default. |default-mappings|
  814. *zy*
  815. ["x]zy{motion} Yank {motion} text [into register x]. Only differs
  816. from `y` when selecting a block of text, see |v_zy|.
  817. *v_y*
  818. {Visual}["x]y Yank the highlighted text [into register x] (for
  819. {Visual} see |Visual-mode|).
  820. *v_Y*
  821. {Visual}["x]Y Yank the highlighted lines [into register x] (for
  822. {Visual} see |Visual-mode|).
  823. *v_zy*
  824. {Visual}["x]zy Yank the highlighted text [into register x]. Trailing
  825. whitespace at the end of each line of a selected block
  826. won't be yanked. Especially useful in combination
  827. with `zp`. (for {Visual} see |Visual-mode|)
  828. *:y* *:yank* *E850*
  829. :[range]y[ank] [x] Yank [range] lines [into register x].
  830. :[range]y[ank] [x] {count}
  831. Yank {count} lines, starting with last line number
  832. in [range] (default: current line |cmdline-ranges|),
  833. [into register x].
  834. *p* *put* *E353* *E1240*
  835. ["x]p Put the text [from register x] after the cursor
  836. [count] times.
  837. *P*
  838. ["x]P Put the text [from register x] before the cursor
  839. [count] times.
  840. *<MiddleMouse>*
  841. ["x]<MiddleMouse> Put the text from a register before the cursor [count]
  842. times. Uses the "* register, unless another is
  843. specified.
  844. Leaves the cursor at the end of the new text.
  845. Using the mouse only works when 'mouse' contains 'n'
  846. or 'a'.
  847. If you have a scrollwheel and often accidentally paste
  848. text, you can use these mappings to disable the
  849. pasting with the middle mouse button: >
  850. :map <MiddleMouse> <Nop>
  851. :imap <MiddleMouse> <Nop>
  852. < You might want to disable the multi-click versions
  853. too, see |double-click|.
  854. *gp*
  855. ["x]gp Just like "p", but leave the cursor just after the new
  856. text.
  857. *gP*
  858. ["x]gP Just like "P", but leave the cursor just after the new
  859. text.
  860. *:pu* *:put*
  861. :[line]pu[t] [x] Put the text [from register x] after [line] (default
  862. current line). This always works |linewise|, thus
  863. this command can be used to put a yanked block as new
  864. lines.
  865. If no register is specified, it depends on the 'cb'
  866. option: If 'cb' contains "unnamedplus", paste from the
  867. + register |quoteplus|. Otherwise, if 'cb' contains
  868. "unnamed", paste from the * register |quotestar|.
  869. Otherwise, paste from the unnamed register
  870. |quote_quote|.
  871. The register can also be '=' followed by an optional
  872. expression. The expression continues until the end of
  873. the command. You need to escape the '|' and '"'
  874. characters to prevent them from terminating the
  875. command. Example: >
  876. :put ='path' .. \",/test\"
  877. < If there is no expression after '=', Vim uses the
  878. previous expression. You can see it with ":dis =".
  879. :[line]pu[t]! [x] Put the text [from register x] before [line] (default
  880. current line).
  881. ["x]]p or *]p* *]<MiddleMouse>*
  882. ["x]]<MiddleMouse> Like "p", but adjust the indent to the current line.
  883. Using the mouse only works when 'mouse' contains 'n'
  884. or 'a'.
  885. ["x][P or *[P*
  886. ["x]]P or *]P*
  887. ["x][p or *[p* *[<MiddleMouse>*
  888. ["x][<MiddleMouse> Like "P", but adjust the indent to the current line.
  889. Using the mouse only works when 'mouse' contains 'n'
  890. or 'a'.
  891. ["x]zp or *zp* *zP*
  892. ["x]zP Like "p" and "P", except without adding trailing spaces
  893. when pasting a block. Thus the inserted text will not
  894. always be a rectangle. Especially useful in
  895. combination with |v_zy|.
  896. You can use these commands to copy text from one place to another. Do this
  897. by first getting the text into a register with a yank, delete or change
  898. command, then inserting the register contents with a put command. You can
  899. also use these commands to move text from one file to another, because Vim
  900. preserves all registers when changing buffers (the CTRL-^ command is a quick
  901. way to toggle between two files).
  902. *linewise-register* *charwise-register*
  903. You can repeat the put commands with "." (except for :put) and undo them. If
  904. the command that was used to get the text into the register was |linewise|,
  905. Vim inserts the text below ("p") or above ("P") the line where the cursor is.
  906. Otherwise Vim inserts the text after ("p") or before ("P") the cursor. With
  907. the ":put" command, Vim always inserts the text in the next line. You can
  908. exchange two characters with the command sequence "xp". You can exchange two
  909. lines with the command sequence "ddp". You can exchange two words with the
  910. command sequence "deep" (start with the cursor in the blank space before the
  911. first word). You can use the "']" or "`]" command after the put command to
  912. move the cursor to the end of the inserted text, or use "'[" or "`[" to move
  913. the cursor to the start.
  914. *put-Visual-mode* *v_p* *v_P*
  915. When using a put command like |p| or |P| in Visual mode, Vim will try to
  916. replace the selected text with the contents of the register. Whether this
  917. works well depends on the type of selection and the type of the text in the
  918. register. With blockwise selection it also depends on the size of the block
  919. and whether the corners are on an existing character. (Implementation detail:
  920. it actually works by first putting the register after the selection and then
  921. deleting the selection.)
  922. With |p| the previously selected text is put in the unnamed register (and
  923. possibly the selection and/or clipboard). This is useful if you want to put
  924. that text somewhere else. But you cannot repeat the same change.
  925. With |P| the unnamed register is not changed (and neither the selection or
  926. clipboard), you can repeat the same change. But the deleted text cannot be
  927. used. If you do need it you can use |p| with another register. E.g., yank
  928. the text to copy, Visually select the text to replace and use "0p . You can
  929. repeat this as many times as you like, and the unnamed register will be
  930. changed each time.
  931. *blockwise-put*
  932. When a register contains text from one line (characterwise), using a
  933. blockwise Visual selection, putting that register will paste that text
  934. repeatedly in each of the selected lines, thus replacing the blockwise
  935. selected region by multiple copies of the register text. For example:
  936. - yank the word "TEXT" into a register with `yw`
  937. - select a visual block, marked with "v" in this text:
  938. aaavvaaa
  939. bbbvvbbb
  940. cccvvccc
  941. - press `p`, results in:
  942. aaaTEXTaaa
  943. bbbTEXTbbb
  944. cccTEXTccc
  945. *blockwise-register*
  946. If you use a blockwise Visual mode command to get the text into the register,
  947. the block of text will be inserted before ("P") or after ("p") the cursor
  948. column in the current and next lines. Vim makes the whole block of text start
  949. in the same column. Thus the inserted text looks the same as when it was
  950. yanked or deleted. Vim may replace some <Tab> characters with spaces to make
  951. this happen. However, if the width of the block is not a multiple of a <Tab>
  952. width and the text after the inserted block contains <Tab>s, that text may be
  953. misaligned.
  954. Use |zP|/|zp| to paste a blockwise yanked register without appending trailing
  955. spaces.
  956. Note that after a charwise yank command, Vim leaves the cursor on the first
  957. yanked character that is closest to the start of the buffer. This means that
  958. "yl" doesn't move the cursor, but "yh" moves the cursor one character left.
  959. Rationale: In Vi the "y" command followed by a backwards motion would
  960. sometimes not move the cursor to the first yanked character,
  961. because redisplaying was skipped. In Vim it always moves to
  962. the first character, as specified by Posix.
  963. With a linewise yank command the cursor is put in the first line, but the
  964. column is unmodified, thus it may not be on the first yanked character.
  965. There are ten types of registers: *registers* *{register}* *E354*
  966. 1. The unnamed register ""
  967. 2. 10 numbered registers "0 to "9
  968. 3. The small delete register "-
  969. 4. 26 named registers "a to "z or "A to "Z
  970. 5. Three read-only registers ":, "., "%
  971. 6. Alternate buffer register "#
  972. 7. The expression register "=
  973. 8. The selection registers "* and "+
  974. 9. The black hole register "_
  975. 10. Last search pattern register "/
  976. 1. Unnamed register "" *quote_quote* *quotequote*
  977. Vim fills this register with text deleted with the "d", "c", "s", "x" commands
  978. or copied with the yank "y" command, regardless of whether or not a specific
  979. register was used (e.g. "xdd). This is like the unnamed register is pointing
  980. to the last used register. Thus when appending using an uppercase register
  981. name, the unnamed register contains the same text as the named register.
  982. An exception is the '_' register: "_dd does not store the deleted text in any
  983. register.
  984. Vim uses the contents of the unnamed register for any put command (p or P)
  985. which does not specify a register. Additionally you can access it with the
  986. name '"'. This means you have to type two double quotes. Writing to the ""
  987. register writes to register "0.
  988. 2. Numbered registers "0 to "9 *quote_number* *quote0* *quote1*
  989. *quote2* *quote3* *quote4* *quote9*
  990. Vim fills these registers with text from yank and delete commands.
  991. Numbered register 0 contains the text from the most recent yank command,
  992. unless the command specified another register with ["x].
  993. Numbered register 1 contains the text deleted by the most recent delete or
  994. change command, unless the command specified another register or the text is
  995. less than one line (the small delete register is used then). An exception is
  996. made for the delete operator with these movement commands: |%|, |(|, |)|, |`|,
  997. |/|, |?|, |n|, |N|, |{| and |}|. Register "1 is always used then (this is Vi
  998. compatible). The "- register is used as well if the delete is within a line.
  999. Note that these characters may be mapped. E.g. |%| is mapped by the matchit
  1000. plugin.
  1001. With each successive deletion or change, Vim shifts the previous contents
  1002. of register 1 into register 2, 2 into 3, and so forth, losing the previous
  1003. contents of register 9.
  1004. 3. Small delete register "- *quote_-* *quote-*
  1005. This register contains text from commands that delete less than one line,
  1006. except when the command specifies a register with ["x].
  1007. 4. Named registers "a to "z or "A to "Z *quote_alpha* *quotea*
  1008. Vim fills these registers only when you say so. Specify them as lowercase
  1009. letters to replace their previous contents or as uppercase letters to append
  1010. to their previous contents. When the '>' flag is present in 'cpoptions' then
  1011. a line break is inserted before the appended text.
  1012. 5. Read-only registers ":, ". and "%
  1013. These are '%', ':' and '.'. You can use them only with the "p", "P",
  1014. and ":put" commands and with CTRL-R.
  1015. *quote_.* *quote.* *E29*
  1016. ". Contains the last inserted text (the same as what is inserted
  1017. with the insert mode commands CTRL-A and CTRL-@). Note: this
  1018. doesn't work with CTRL-R on the command-line. It works a bit
  1019. differently, like inserting the text instead of putting it
  1020. ('textwidth' and other options affect what is inserted).
  1021. *quote_%* *quote%*
  1022. "% Contains the name of the current file.
  1023. *quote_:* *quote:* *E30*
  1024. ": Contains the most recent executed command-line. Example: Use
  1025. "@:" to repeat the previous command-line command.
  1026. The command-line is only stored in this register when at least
  1027. one character of it was typed. Thus it remains unchanged if
  1028. the command was completely from a mapping.
  1029. *quote_#* *quote#*
  1030. 6. Alternate file register "#
  1031. Contains the name of the alternate file for the current window. It will
  1032. change how the |CTRL-^| command works.
  1033. This register is writable, mainly to allow for restoring it after a plugin has
  1034. changed it. It accepts buffer number: >
  1035. let altbuf = bufnr(@#)
  1036. ...
  1037. let @# = altbuf
  1038. It will give error |E86| if you pass buffer number and this buffer does not
  1039. exist.
  1040. It can also accept a match with an existing buffer name: >
  1041. let @# = 'buffer_name'
  1042. Error |E93| if there is more than one buffer matching the given name or |E94|
  1043. if none of buffers matches the given name.
  1044. 7. Expression register "= *quote_=* *quote=* *@=*
  1045. This is not really a register that stores text, but is a way to use an
  1046. expression in commands which use a register. The expression register is
  1047. read-write.
  1048. When typing the '=' after " or CTRL-R the cursor moves to the command-line,
  1049. where you can enter any expression (see |expression|). All normal
  1050. command-line editing commands are available, including a special history for
  1051. expressions. When you end the command-line by typing <CR>, Vim computes the
  1052. result of the expression. If you end it with <Esc>, Vim abandons the
  1053. expression. If you do not enter an expression, Vim uses the previous
  1054. expression (like with the "/" command).
  1055. The expression must evaluate to a String. A Number is always automatically
  1056. converted to a String. For the "p" and ":put" command, if the result is a
  1057. Float it's converted into a String. If the result is a List each element is
  1058. turned into a String and used as a line. A Dictionary or FuncRef results in
  1059. an error message (use string() to convert).
  1060. If the "= register is used for the "p" command, the String is split up at <NL>
  1061. characters. If the String ends in a <NL>, it is regarded as a linewise
  1062. register.
  1063. 8. Selection registers "* and "+
  1064. Use these registers for storing and retrieving the selected text for the GUI.
  1065. See |quotestar| and |quoteplus|. When the clipboard is not available or not
  1066. working, the unnamed register is used instead. For Unix systems and Mac OS X,
  1067. see |primary-selection|.
  1068. 9. Black hole register "_ *quote_*
  1069. When writing to this register, nothing happens. This can be used to delete
  1070. text without affecting the normal registers. When reading from this register,
  1071. nothing is returned.
  1072. 10. Last search pattern register "/ *quote_/* *quote/*
  1073. Contains the most recent search-pattern. This is used for "n" and 'hlsearch'.
  1074. It is writable with `:let`, you can change it to have 'hlsearch' highlight
  1075. other matches without actually searching. You can't yank or delete into this
  1076. register. The search direction is available in |v:searchforward|.
  1077. Note that the value is restored when returning from a function
  1078. |function-search-undo|.
  1079. *@/*
  1080. You can write to a register with a `:let` command |:let-@|. Example: >
  1081. :let @/ = "the"
  1082. If you use a put command without specifying a register, Vim uses the register
  1083. that was last filled (this is also the contents of the unnamed register). If
  1084. you are confused, use the `:dis` command to find out what Vim will put (this
  1085. command displays all named and numbered registers; the unnamed register is
  1086. labelled '"').
  1087. The next three commands always work on whole lines.
  1088. :[range]co[py] {address} *:co* *:copy*
  1089. Copy the lines given by [range] to below the line
  1090. given by {address}.
  1091. *:t*
  1092. :t Synonym for copy.
  1093. :[range]m[ove] {address} *:m* *:mo* *:move* *E134*
  1094. Move the lines given by [range] to below the line
  1095. given by {address}.
  1096. ==============================================================================
  1097. 6. Formatting text *formatting*
  1098. :[range]ce[nter] [width] *:ce* *:center*
  1099. Center lines in [range] between [width] columns
  1100. (default 'textwidth' or 80 when 'textwidth' is 0).
  1101. :[range]ri[ght] [width] *:ri* *:right*
  1102. Right-align lines in [range] at [width] columns
  1103. (default 'textwidth' or 80 when 'textwidth' is 0).
  1104. *:le* *:left*
  1105. :[range]le[ft] [indent]
  1106. Left-align lines in [range]. Sets the indent in the
  1107. lines to [indent] (default 0).
  1108. *gq*
  1109. gq{motion} Format the lines that {motion} moves over.
  1110. Formatting is done with one of three methods:
  1111. 1. If 'formatexpr' is not empty the expression is
  1112. evaluated. This can differ for each buffer.
  1113. 2. If 'formatprg' is not empty an external program
  1114. is used.
  1115. 3. Otherwise formatting is done internally.
  1116. In the third case the 'textwidth' option controls the
  1117. length of each formatted line (see below).
  1118. If the 'textwidth' option is 0, the formatted line
  1119. length is the screen width (with a maximum width of
  1120. 79).
  1121. The 'formatoptions' option controls the type of
  1122. formatting |fo-table|.
  1123. The cursor is left on the first non-blank of the last
  1124. formatted line.
  1125. NOTE: The "Q" command formerly performed this
  1126. function. If you still want to use "Q" for
  1127. formatting, use this mapping: >
  1128. :nnoremap Q gq
  1129. gqgq *gqgq* *gqq*
  1130. gqq Format the current line. With a count format that
  1131. many lines.
  1132. *v_gq*
  1133. {Visual}gq Format the highlighted text. (for {Visual} see
  1134. |Visual-mode|).
  1135. *gw*
  1136. gw{motion} Format the lines that {motion} moves over. Similar to
  1137. |gq| but puts the cursor back at the same position in
  1138. the text. However, 'formatprg' and 'formatexpr' are
  1139. not used.
  1140. gwgw *gwgw* *gww*
  1141. gww Format the current line as with "gw".
  1142. *v_gw*
  1143. {Visual}gw Format the highlighted text as with "gw". (for
  1144. {Visual} see |Visual-mode|).
  1145. Example: To format the current paragraph use: *gqap* >
  1146. gqap
  1147. The "gq" command leaves the cursor in the line where the motion command takes
  1148. the cursor. This allows you to repeat formatting repeated with ".". This
  1149. works well with "gqj" (format current and next line) and "gq}" (format until
  1150. end of paragraph). Note: When 'formatprg' is set, "gq" leaves the cursor on
  1151. the first formatted line (as with using a filter command).
  1152. If you want to format the current paragraph and continue where you were, use: >
  1153. gwap
  1154. If you always want to keep paragraphs formatted you may want to add the 'a'
  1155. flag to 'formatoptions'. See |auto-format|.
  1156. If the 'autoindent' option is on, Vim uses the indent of the first line for
  1157. the following lines.
  1158. Formatting does not change empty lines (but it does change lines with only
  1159. white space!).
  1160. The 'joinspaces' option is used when lines are joined together.
  1161. You can set the 'formatexpr' option to an expression or the 'formatprg' option
  1162. to the name of an external program for Vim to use for text formatting. The
  1163. 'textwidth' and other options have no effect on formatting by an external
  1164. program.
  1165. *format-formatexpr*
  1166. The 'formatexpr' option can be set to a Vim script function that performs
  1167. reformatting of the buffer. This should usually happen in an |ftplugin|,
  1168. since formatting is highly dependent on the type of file. It makes
  1169. sense to use an |autoload| script, so the corresponding script is only loaded
  1170. when actually needed and the script should be called <filetype>format.vim.
  1171. For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME
  1172. directory, sets the 'formatexpr' option to: >
  1173. setlocal formatexpr=xmlformat#Format()
  1174. That means, you will find the corresponding script, defining the
  1175. xmlformat#Format() function, in the directory:
  1176. `$VIMRUNTIME/autoload/xmlformat.vim`
  1177. Here is an example script that removes trailing whitespace from the selected
  1178. text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: >
  1179. func! format#Format()
  1180. " only reformat on explicit gq command
  1181. if mode() != 'n'
  1182. " fall back to Vim's internal reformatting
  1183. return 1
  1184. endif
  1185. let lines = getline(v:lnum, v:lnum + v:count - 1)
  1186. call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')})
  1187. call setline('.', lines)
  1188. " do not run internal formatter!
  1189. return 0
  1190. endfunc
  1191. You can then enable the formatting by executing: >
  1192. setlocal formatexpr=format#Format()
  1193. Note: this function explicitly returns non-zero when called from insert mode
  1194. (which basically means, text is inserted beyond the 'textwidth' limit). This
  1195. causes Vim to fall back to reformat the text by using the internal formatter.
  1196. However, if the |gq| command is used to reformat the text, the function
  1197. will receive the selected lines, trim trailing whitespace from those lines and
  1198. put them back in place. If you are going to split single lines into multiple
  1199. lines, be careful not to overwrite anything.
  1200. If you want to allow reformatting of text from insert or replace mode, one has
  1201. to be very careful, because the function might be called recursively. For
  1202. debugging it helps to set the 'debug' option.
  1203. *right-justify*
  1204. There is no command in Vim to right justify text. You can do it with
  1205. an external command, like "par" (e.g.: "!}par" to format until the end of the
  1206. paragraph) or set 'formatprg' to "par".
  1207. *format-comments*
  1208. An overview of comment formatting is in section |30.6| of the user manual.
  1209. Vim can automatically insert and format comments in a special way. Vim
  1210. recognizes a comment by a specific string at the start of the line (ignoring
  1211. white space). Three types of comments can be used:
  1212. - A comment string that repeats at the start of each line. An example is the
  1213. type of comment used in shell scripts, starting with "#".
  1214. - A comment string that occurs only in the first line, not in the following
  1215. lines. An example is this list with dashes.
  1216. - Three-piece comments that have a start string, an end string, and optional
  1217. lines in between. The strings for the start, middle and end are different.
  1218. An example is the C style comment:
  1219. /*
  1220. * this is a C comment
  1221. */
  1222. The 'comments' option is a comma-separated list of parts. Each part defines a
  1223. type of comment string. A part consists of:
  1224. {flags}:{string}
  1225. {string} is the literal text that must appear.
  1226. {flags}:
  1227. n Nested comment. Nesting with mixed parts is allowed. If 'comments'
  1228. is "n:),n:>" a line starting with "> ) >" is a comment.
  1229. b Blank (<Space>, <Tab> or <EOL>) required after {string}.
  1230. f Only the first line has the comment string. Do not repeat comment on
  1231. the next line, but preserve indentation (e.g., a bullet-list).
  1232. s Start of three-piece comment
  1233. m Middle of a three-piece comment
  1234. e End of a three-piece comment
  1235. l Left align. Used together with 's' or 'e', the leftmost character of
  1236. start or end will line up with the leftmost character from the middle.
  1237. This is the default and can be omitted. See below for more details.
  1238. r Right align. Same as above but rightmost instead of leftmost. See
  1239. below for more details.
  1240. O Don't consider this comment for the "O" command.
  1241. x Allows three-piece comments to be ended by just typing the last
  1242. character of the end-comment string as the first action on a new
  1243. line when the middle-comment string has been inserted automatically.
  1244. See below for more details.
  1245. {digits}
  1246. When together with 's' or 'e': add {digit} amount of offset to an
  1247. automatically inserted middle or end comment leader. The offset begins
  1248. from a left alignment. See below for more details.
  1249. -{digits}
  1250. Like {digits} but reduce the indent. This only works when there is
  1251. some indent for the start or end part that can be removed.
  1252. When a string has none of the 'f', 's', 'm' or 'e' flags, Vim assumes the
  1253. comment string repeats at the start of each line. The flags field may be
  1254. empty.
  1255. Any blank space in the text before and after the {string} is part of the
  1256. {string}, so do not include leading or trailing blanks unless the blanks are a
  1257. required part of the comment string.
  1258. When one comment leader is part of another, specify the part after the whole.
  1259. For example, to include both "-" and "->", use >
  1260. :set comments=f:->,f:-
  1261. A three-piece comment must always be given as start,middle,end, with no other
  1262. parts in between. An example of a three-piece comment is >
  1263. sr:/*,mb:*,ex:*/
  1264. for C-comments. To avoid recognizing "*ptr" as a comment, the middle string
  1265. includes the 'b' flag. For three-piece comments, Vim checks the text after
  1266. the start and middle strings for the end string. If Vim finds the end string,
  1267. the comment does not continue on the next line. Three-piece comments must
  1268. have a middle string because otherwise Vim can't recognize the middle lines.
  1269. Notice the use of the "x" flag in the above three-piece comment definition.
  1270. When you hit Return in a C-comment, Vim will insert the middle comment leader
  1271. for the new line: " * ". To close this comment you just have to type "/"
  1272. before typing anything else on the new line. This will replace the
  1273. middle-comment leader with the end-comment leader and apply any specified
  1274. alignment, leaving just " */". There is no need to hit Backspace first.
  1275. When there is a match with a middle part, but there also is a matching end
  1276. part which is longer, the end part is used. This makes a C style comment work
  1277. without requiring the middle part to end with a space.
  1278. Here is an example of alignment flags at work to make a comment stand out
  1279. (kind of looks like a 1 too). Consider comment string: >
  1280. :set comments=sr:/***,m:**,ex-2:******/
  1281. <
  1282. /*** ~
  1283. **<--right aligned from "r" flag ~
  1284. ** ~
  1285. offset 2 spaces for the "-2" flag--->** ~
  1286. ******/ ~
  1287. In this case, the first comment was typed, then return was pressed 4 times,
  1288. then "/" was pressed to end the comment.
  1289. Here are some finer points of three part comments. There are three times when
  1290. alignment and offset flags are taken into consideration: opening a new line
  1291. after a start-comment, opening a new line before an end-comment, and
  1292. automatically ending a three-piece comment. The end alignment flag has a
  1293. backwards perspective; the result is that the same alignment flag used with
  1294. "s" and "e" will result in the same indent for the starting and ending pieces.
  1295. Only one alignment per comment part is meant to be used, but an offset number
  1296. will override the "r" and "l" flag.
  1297. Enabling 'cindent' will override the alignment flags in many cases.
  1298. Reindenting using a different method like |gq| or |=| will not consult
  1299. alignment flags either. The same behaviour can be defined in those other
  1300. formatting options. One consideration is that 'cindent' has additional options
  1301. for context based indenting of comments but cannot replicate many three piece
  1302. indent alignments. However, 'indentexpr' has the ability to work better with
  1303. three piece comments.
  1304. Other examples: >
  1305. "b:*" Includes lines starting with "*", but not if the "*" is
  1306. followed by a non-blank. This avoids a pointer dereference
  1307. like "*str" to be recognized as a comment.
  1308. "n:>" Includes a line starting with ">", ">>", ">>>", etc.
  1309. "fb:-" Format a list that starts with "- ".
  1310. By default, "b:#" is included. This means that a line that starts with
  1311. "#include" is not recognized as a comment line. But a line that starts with
  1312. "# define" is recognized. This is a compromise.
  1313. *fo-table*
  1314. You can use the 'formatoptions' option to influence how Vim formats text.
  1315. 'formatoptions' is a string that can contain any of the letters below. You
  1316. can separate the option letters with commas for readability.
  1317. letter meaning when present in 'formatoptions' ~
  1318. *fo-t*
  1319. t Auto-wrap text using 'textwidth'
  1320. *fo-c*
  1321. c Auto-wrap comments using 'textwidth', inserting the current comment
  1322. leader automatically.
  1323. *fo-r*
  1324. r Automatically insert the current comment leader after hitting
  1325. <Enter> in Insert mode.
  1326. *fo-o*
  1327. o Automatically insert the current comment leader after hitting 'o' or
  1328. 'O' in Normal mode. In case comment is unwanted in a specific place
  1329. use CTRL-U to quickly delete it. |i_CTRL-U|
  1330. *fo-/*
  1331. / When 'o' is included: do not insert the comment leader for a //
  1332. comment after a statement, only when // is at the start of the line.
  1333. *fo-q*
  1334. q Allow formatting of comments with "gq".
  1335. Note that formatting will not change blank lines or lines containing
  1336. only the comment leader. A new paragraph starts after such a line,
  1337. or when the comment leader changes.
  1338. *fo-w*
  1339. w Trailing white space indicates a paragraph continues in the next line.
  1340. A line that ends in a non-white character ends a paragraph.
  1341. *fo-a*
  1342. a Automatic formatting of paragraphs. Every time text is inserted or
  1343. deleted the paragraph will be reformatted. See |auto-format|.
  1344. When the 'c' flag is present this only happens for recognized
  1345. comments.
  1346. *fo-n*
  1347. n When formatting text, recognize numbered lists. This actually uses
  1348. the 'formatlistpat' option, thus any kind of list can be used. The
  1349. indent of the text after the number is used for the next line. The
  1350. default is to find a number, optionally followed by '.', ':', ')',
  1351. ']' or '}'. Note that 'autoindent' must be set too. Doesn't work
  1352. well together with "2".
  1353. Example: >
  1354. 1. the first item
  1355. wraps
  1356. 2. the second item
  1357. < *fo-2*
  1358. 2 When formatting text, use the indent of the second line of a paragraph
  1359. for the rest of the paragraph, instead of the indent of the first
  1360. line. This supports paragraphs in which the first line has a
  1361. different indent than the rest. Note that 'autoindent' must be set
  1362. too. Example: >
  1363. first line of a paragraph
  1364. second line of the same paragraph
  1365. third line.
  1366. < This also works inside comments, ignoring the comment leader.
  1367. *fo-v*
  1368. v Vi-compatible auto-wrapping in insert mode: Only break a line at a
  1369. blank that you have entered during the current insert command. (Note:
  1370. this is not 100% Vi compatible. Vi has some "unexpected features" or
  1371. bugs in this area. It uses the screen column instead of the line
  1372. column.)
  1373. *fo-b*
  1374. b Like 'v', but only auto-wrap if you enter a blank at or before
  1375. the wrap margin. If the line was longer than 'textwidth' when you
  1376. started the insert, or you do not enter a blank in the insert before
  1377. reaching 'textwidth', Vim does not perform auto-wrapping.
  1378. *fo-l*
  1379. l Long lines are not broken in insert mode: When a line was longer than
  1380. 'textwidth' when the insert command started, Vim does not
  1381. automatically format it.
  1382. *fo-m*
  1383. m Also break at a multibyte character above 255. This is useful for
  1384. Asian text where every character is a word on its own.
  1385. *fo-M*
  1386. M When joining lines, don't insert a space before or after a multibyte
  1387. character. Overrules the 'B' flag.
  1388. *fo-B*
  1389. B When joining lines, don't insert a space between two multibyte
  1390. characters. Overruled by the 'M' flag.
  1391. *fo-1*
  1392. 1 Don't break a line after a one-letter word. It's broken before it
  1393. instead (if possible).
  1394. *fo-]*
  1395. ] Respect 'textwidth' rigorously. With this flag set, no line can be
  1396. longer than 'textwidth', unless line-break-prohibition rules make this
  1397. impossible. Mainly for CJK scripts and works only if 'encoding' is
  1398. "utf-8".
  1399. *fo-j*
  1400. j Where it makes sense, remove a comment leader when joining lines. For
  1401. example, joining:
  1402. int i; // the index ~
  1403. // in the list ~
  1404. Becomes:
  1405. int i; // the index in the list ~
  1406. *fo-p*
  1407. p Don't break lines at single spaces that follow periods. This is
  1408. intended to complement 'joinspaces' and |cpo-J|, for prose with
  1409. sentences separated by two spaces. For example, with 'textwidth' set
  1410. to 28: >
  1411. Surely you're joking, Mr. Feynman!
  1412. < Becomes: >
  1413. Surely you're joking,
  1414. Mr. Feynman!
  1415. < Instead of: >
  1416. Surely you're joking, Mr.
  1417. Feynman!
  1418. With 't' and 'c' you can specify when Vim performs auto-wrapping:
  1419. value action ~
  1420. "" no automatic formatting (you can use "gq" for manual formatting)
  1421. "t" automatic formatting of text, but not comments
  1422. "c" automatic formatting for comments, but not text (good for C code)
  1423. "tc" automatic formatting for text and comments
  1424. Note that when 'textwidth' is 0, Vim does no automatic formatting anyway (but
  1425. does insert comment leaders according to the 'comments' option). An exception
  1426. is when the 'a' flag is present. |auto-format|
  1427. Note that when 'paste' is on, Vim does no formatting at all.
  1428. Note that 'textwidth' can be non-zero even if Vim never performs auto-wrapping;
  1429. 'textwidth' is still useful for formatting with "gq".
  1430. If the 'comments' option includes "/*", "*" and/or "*/", then Vim has some
  1431. built in stuff to treat these types of comments a bit more cleverly.
  1432. Opening a new line before or after "/*" or "*/" (with 'r' or 'o' present in
  1433. 'formatoptions') gives the correct start of the line automatically. The same
  1434. happens with formatting and auto-wrapping. Opening a line after a line
  1435. starting with "/*" or "*" and containing "*/", will cause no comment leader to
  1436. be inserted, and the indent of the new line is taken from the line containing
  1437. the start of the comment.
  1438. E.g.:
  1439. /* ~
  1440. * Your typical comment. ~
  1441. */ ~
  1442. The indent on this line is the same as the start of the above
  1443. comment.
  1444. All of this should be really cool, especially in conjunction with the new
  1445. :autocmd command to prepare different settings for different types of file.
  1446. Some examples:
  1447. for C code (only format comments): >
  1448. :set fo=croq
  1449. < for Mail/news (format all, don't start comment with "o" command): >
  1450. :set fo=tcrq
  1451. <
  1452. Automatic formatting *auto-format* *autoformat*
  1453. When the 'a' flag is present in 'formatoptions' text is formatted
  1454. automatically when inserting text or deleting text. This works nicely for
  1455. editing text paragraphs. A few hints on how to use this:
  1456. - You need to properly define paragraphs. The simplest is paragraphs that are
  1457. separated by a blank line. When there is no separating blank line, consider
  1458. using the 'w' flag and adding a space at the end of each line in the
  1459. paragraphs except the last one.
  1460. - You can set the 'formatoptions' based on the type of file |filetype| or
  1461. specifically for one file with a |modeline|.
  1462. - Set 'formatoptions' to "aw2tq" to make text with indents like this:
  1463. bla bla foobar bla
  1464. bla foobar bla foobar bla
  1465. bla bla foobar bla
  1466. bla foobar bla bla foobar
  1467. - Add the 'c' flag to only auto-format comments. Useful in source code.
  1468. - Set 'textwidth' to the desired width. If it is zero then 79 is used, or the
  1469. width of the screen if this is smaller.
  1470. And a few warnings:
  1471. - When part of the text is not properly separated in paragraphs, making
  1472. changes in this text will cause it to be formatted anyway. Consider doing >
  1473. :set fo-=a
  1474. - When using the 'w' flag (trailing space means paragraph continues) and
  1475. deleting the last line of a paragraph with |dd|, the paragraph will be
  1476. joined with the next one.
  1477. - Changed text is saved for undo. Formatting is also a change. Thus each
  1478. format action saves text for undo. This may consume quite a lot of memory.
  1479. - Formatting a long paragraph and/or with complicated indenting may be slow.
  1480. ==============================================================================
  1481. 7. Sorting text *sorting*
  1482. Vim has a sorting function and a sorting command. The sorting function can be
  1483. found here: |sort()|, |uniq()|.
  1484. *:sor* *:sort*
  1485. :[range]sor[t][!] [b][f][i][l][n][o][r][u][x] [/{pattern}/]
  1486. Sort lines in [range]. When no range is given all
  1487. lines are sorted.
  1488. With [!] the order is reversed.
  1489. With [i] case is ignored.
  1490. With [l] sort uses the current collation locale.
  1491. Implementation details: strcoll() is used to compare
  1492. strings. See |:language| to check or set the collation
  1493. locale. Example: >
  1494. :language collate en_US.UTF-8
  1495. :%sort l
  1496. < |v:collate| can also used to check the current locale.
  1497. Sorting using the locale typically ignores case.
  1498. This does not work properly on Mac.
  1499. Options [n][f][x][o][b] are mutually exclusive.
  1500. With [n] sorting is done on the first decimal number
  1501. in the line (after or inside a {pattern} match).
  1502. One leading '-' is included in the number.
  1503. With [f] sorting is done on the Float in the line.
  1504. The value of Float is determined similar to passing
  1505. the text (after or inside a {pattern} match) to
  1506. str2float() function.
  1507. With [x] sorting is done on the first hexadecimal
  1508. number in the line (after or inside a {pattern}
  1509. match). A leading "0x" or "0X" is ignored.
  1510. One leading '-' is included in the number.
  1511. With [o] sorting is done on the first octal number in
  1512. the line (after or inside a {pattern} match).
  1513. With [b] sorting is done on the first binary number in
  1514. the line (after or inside a {pattern} match).
  1515. With [u] (u stands for unique) only keep the first of
  1516. a sequence of identical lines (ignoring case when [i]
  1517. is used). Without this flag, a sequence of identical
  1518. lines will be kept in their original order.
  1519. Note that leading and trailing white space may cause
  1520. lines to be different.
  1521. When /{pattern}/ is specified and there is no [r] flag
  1522. the text matched with {pattern} is skipped, so that
  1523. you sort on what comes after the match.
  1524. 'ignorecase' applies to the pattern, but 'smartcase'
  1525. is not used.
  1526. Instead of the slash any non-letter can be used.
  1527. For example, to sort on the second comma-separated
  1528. field: >
  1529. :sort /[^,]*,/
  1530. < To sort on the text at virtual column 10 (thus
  1531. ignoring the difference between tabs and spaces): >
  1532. :sort /.*\%10v/
  1533. < To sort on the first number in the line, no matter
  1534. what is in front of it: >
  1535. :sort /.\{-}\ze\d/
  1536. < (Explanation: ".\{-}" matches any text, "\ze" sets the
  1537. end of the match and \d matches a digit.)
  1538. With [r] sorting is done on the matching {pattern}
  1539. instead of skipping past it as described above.
  1540. For example, to sort on only the first three letters
  1541. of each line: >
  1542. :sort /\a\a\a/ r
  1543. < If a {pattern} is used, any lines which don't have a
  1544. match for {pattern} are kept in their current order,
  1545. but separate from the lines which do match {pattern}.
  1546. If you sorted in reverse, they will be in reverse
  1547. order after the sorted lines, otherwise they will be
  1548. in their original order, right before the sorted
  1549. lines.
  1550. If {pattern} is empty (e.g. // is specified), the
  1551. last search pattern is used. This allows trying out
  1552. a pattern first.
  1553. Note that using `:sort` with `:global` doesn't sort the matching lines, it's
  1554. quite useless.
  1555. `:sort` does not use the current locale unless the l flag is used.
  1556. Vim does do a "stable" sort.
  1557. The sorting can be interrupted, but if you interrupt it too late in the
  1558. process you may end up with duplicated lines. This also depends on the system
  1559. library function used.
  1560. vim:tw=78:ts=8:noet:ft=help:norl: