change.txt 76 KB

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