change.txt 72 KB

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