editing.txt 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840
  1. *editing.txt* For Vim version 9.0. Last change: 2022 Nov 02
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Editing files *edit-files*
  4. 1. Introduction |edit-intro|
  5. 2. Editing a file |edit-a-file|
  6. 3. The argument list |argument-list|
  7. 4. Writing |writing|
  8. 5. Writing and quitting |write-quit|
  9. 6. Dialogs |edit-dialogs|
  10. 7. The current directory |current-directory|
  11. 8. Editing binary files |edit-binary|
  12. 9. Encryption |encryption|
  13. 10. Timestamps |timestamps|
  14. 11. File Searching |file-searching|
  15. ==============================================================================
  16. 1. Introduction *edit-intro*
  17. Editing a file with Vim means:
  18. 1. reading the file into a buffer
  19. 2. changing the buffer with editor commands
  20. 3. writing the buffer into a file
  21. *current-file*
  22. As long as you don't write the buffer, the original file remains unchanged.
  23. If you start editing a file (read a file into the buffer), the file name is
  24. remembered as the "current file name". This is also known as the name of the
  25. current buffer. It can be used with "%" on the command line |:_%|.
  26. *alternate-file*
  27. If there already was a current file name, then that one becomes the alternate
  28. file name. It can be used with "#" on the command line |:_#| and you can use
  29. the |CTRL-^| command to toggle between the current and the alternate file.
  30. However, the alternate file name is not changed when |:keepalt| is used.
  31. An alternate file name is remembered for each window.
  32. *:keepalt* *:keepa*
  33. :keepalt {cmd} Execute {cmd} while keeping the current alternate file
  34. name. Note that commands invoked indirectly (e.g.,
  35. with a function) may still set the alternate file
  36. name.
  37. All file names are remembered in the buffer list. When you enter a file name,
  38. for editing (e.g., with ":e filename") or writing (e.g., with ":w filename"),
  39. the file name is added to the list. You can use the buffer list to remember
  40. which files you edited and to quickly switch from one file to another (e.g.,
  41. to copy text) with the |CTRL-^| command. First type the number of the file
  42. and then hit CTRL-^.
  43. CTRL-G or *CTRL-G* *:f* *:fi* *:file*
  44. :f[ile] Prints the current file name (as typed, unless ":cd"
  45. was used), the cursor position (unless the 'ruler'
  46. option is set), and the file status (readonly,
  47. modified, read errors, new file). See the 'shortmess'
  48. option about how to make this message shorter.
  49. :f[ile]! like |:file|, but don't truncate the name even when
  50. 'shortmess' indicates this.
  51. {count}CTRL-G Like CTRL-G, but prints the current file name with
  52. full path. If the count is higher than 1 the current
  53. buffer number is also given.
  54. *g_CTRL-G* *word-count* *byte-count*
  55. g CTRL-G Prints the current position of the cursor in five
  56. ways: Column, Line, Word, Character and Byte. If the
  57. number of Characters and Bytes is the same then the
  58. Character position is omitted.
  59. If there are characters in the line that take more
  60. than one position on the screen (<Tab> or special
  61. character), or characters using more than one byte per
  62. column (characters above 0x7F when 'encoding' is
  63. utf-8), both the byte column and the screen column are
  64. shown, separated by a dash.
  65. Also see the 'ruler' option and the |wordcount()|
  66. function.
  67. *v_g_CTRL-G*
  68. {Visual}g CTRL-G Similar to "g CTRL-G", but Word, Character, Line, and
  69. Byte counts for the visually selected region are
  70. displayed.
  71. In Blockwise mode, Column count is also shown. (For
  72. {Visual} see |Visual-mode|.)
  73. *:file_f*
  74. :f[ile][!] {name} Sets the current file name to {name}. The optional !
  75. avoids truncating the message, as with |:file|.
  76. If the buffer did have a name, that name becomes the
  77. |alternate-file| name. An unlisted buffer is created
  78. to hold the old name.
  79. *:0file*
  80. :0f[ile][!] Remove the name of the current buffer. The optional !
  81. avoids truncating the message, as with |:file|.
  82. :buffers
  83. :files
  84. :ls List all the currently known file names. See
  85. |windows.txt| |:files| |:buffers| |:ls|.
  86. Vim will remember the full path name of a file name that you enter. In most
  87. cases when the file name is displayed only the name you typed is shown, but
  88. the full path name is being used if you used the ":cd" command |:cd|.
  89. *home-replace*
  90. If the environment variable $HOME is set, and the file name starts with that
  91. string, it is often displayed with HOME replaced with "~". This was done to
  92. keep file names short. When reading or writing files the full name is still
  93. used, the "~" is only used when displaying file names. When replacing the
  94. file name would result in just "~", "~/" is used instead (to avoid confusion
  95. between options set to $HOME with 'backupext' set to "~").
  96. When writing the buffer, the default is to use the current file name. Thus
  97. when you give the "ZZ" or ":wq" command, the original file will be
  98. overwritten. If you do not want this, the buffer can be written into another
  99. file by giving a file name argument to the ":write" command. For example: >
  100. vim testfile
  101. [change the buffer with editor commands]
  102. :w newfile
  103. :q
  104. This will create a file "newfile", that is a modified copy of "testfile".
  105. The file "testfile" will remain unchanged. Anyway, if the 'backup' option is
  106. set, Vim renames or copies the original file before it will be overwritten.
  107. You can use this file if you discover that you need the original file. See
  108. also the 'patchmode' option. The name of the backup file is normally the same
  109. as the original file with 'backupext' appended. The default "~" is a bit
  110. strange to avoid accidentally overwriting existing files. If you prefer ".bak"
  111. change the 'backupext' option. Extra dots are replaced with '_' on MS-Windows
  112. machines, when Vim has detected that an MS-DOS-like filesystem is being used
  113. (e.g., messydos or crossdos) or when the 'shortname' option is on. The
  114. backup file can be placed in another directory by setting 'backupdir'.
  115. *auto-shortname*
  116. Technical: On the Amiga you can use 30 characters for a file name. But on an
  117. MS-DOS-compatible filesystem only 8 plus 3 characters are
  118. available. Vim tries to detect the type of filesystem when it is
  119. creating the .swp file. If an MS-DOS-like filesystem is suspected,
  120. a flag is set that has the same effect as setting the 'shortname'
  121. option. This flag will be reset as soon as you start editing a
  122. new file. The flag will be used when making the file name for the
  123. ".swp" and ".~" files for the current file. But when you are
  124. editing a file in a normal filesystem and write to an MS-DOS-like
  125. filesystem the flag will not have been set. In that case the
  126. creation of the ".~" file may fail and you will get an error
  127. message. Use the 'shortname' option in this case.
  128. When you started editing without giving a file name, "No File" is displayed in
  129. messages. If the ":write" command is used with a file name argument, the file
  130. name for the current file is set to that file name. This only happens when
  131. the 'F' flag is included in 'cpoptions' (by default it is included) |cpo-F|.
  132. This is useful when entering text in an empty buffer and then writing it to a
  133. file. If 'cpoptions' contains the 'f' flag (by default it is NOT included)
  134. |cpo-f| the file name is set for the ":read file" command. This is useful
  135. when starting Vim without an argument and then doing ":read file" to start
  136. editing a file.
  137. When the file name was set and 'filetype' is empty the filetype detection
  138. autocommands will be triggered.
  139. *not-edited*
  140. Because the file name was set without really starting to edit that file, you
  141. are protected from overwriting that file. This is done by setting the
  142. "notedited" flag. You can see if this flag is set with the CTRL-G or ":file"
  143. command. It will include "[Not edited]" when the "notedited" flag is set.
  144. When writing the buffer to the current file name (with ":w!"), the "notedited"
  145. flag is reset.
  146. *abandon*
  147. Vim remembers whether you have changed the buffer. You are protected from
  148. losing the changes you made. If you try to quit without writing, or want to
  149. start editing another file, Vim will refuse this. In order to overrule this
  150. protection, add a '!' to the command. The changes will then be lost. For
  151. example: ":q" will not work if the buffer was changed, but ":q!" will. To see
  152. whether the buffer was changed use the "CTRL-G" command. The message includes
  153. the string "[Modified]" if the buffer has been changed, or "+" if the 'm' flag
  154. is in 'shortmess'.
  155. If you want to automatically save the changes without asking, switch on the
  156. 'autowriteall' option. 'autowrite' is the associated Vi-compatible option
  157. that does not work for all commands.
  158. If you want to keep the changed buffer without saving it, switch on the
  159. 'hidden' option. See |hidden-buffer|. Some commands work like this even when
  160. 'hidden' is not set, check the help for the command.
  161. ==============================================================================
  162. 2. Editing a file *edit-a-file*
  163. *:e* *:edit* *reload*
  164. :e[dit] [++opt] [+cmd] Edit the current file. This is useful to re-edit the
  165. current file, when it has been changed outside of Vim.
  166. This fails when changes have been made to the current
  167. buffer and 'autowriteall' isn't set or the file can't
  168. be written.
  169. Also see |++opt| and |+cmd|.
  170. *:edit!* *discard*
  171. :e[dit]! [++opt] [+cmd]
  172. Edit the current file always. Discard any changes to
  173. the current buffer. This is useful if you want to
  174. start all over again.
  175. Also see |++opt| and |+cmd|.
  176. *:edit_f*
  177. :e[dit] [++opt] [+cmd] {file}
  178. Edit {file}.
  179. This fails when changes have been made to the current
  180. buffer, unless 'hidden' is set or 'autowriteall' is
  181. set and the file can be written.
  182. Also see |++opt| and |+cmd|.
  183. *:edit!_f*
  184. :e[dit]! [++opt] [+cmd] {file}
  185. Edit {file} always. Discard any changes to the
  186. current buffer.
  187. Also see |++opt| and |+cmd|.
  188. *:edit_#* *:e#*
  189. :e[dit] [++opt] [+cmd] #[count]
  190. Edit the [count]th buffer (as shown by |:files|).
  191. This command does the same as [count] CTRL-^. But ":e
  192. #" doesn't work if the alternate buffer doesn't have a
  193. file name, while CTRL-^ still works then.
  194. Also see |++opt| and |+cmd|.
  195. *:ene* *:enew*
  196. :ene[w] Edit a new, unnamed buffer. This fails when changes
  197. have been made to the current buffer, unless 'hidden'
  198. is set or 'autowriteall' is set and the file can be
  199. written.
  200. If 'fileformats' is not empty, the first format given
  201. will be used for the new buffer. If 'fileformats' is
  202. empty, the 'fileformat' of the current buffer is used.
  203. *:ene!* *:enew!*
  204. :ene[w]! Edit a new, unnamed buffer. Discard any changes to
  205. the current buffer.
  206. Set 'fileformat' like |:enew|.
  207. *:fin* *:find*
  208. :fin[d][!] [++opt] [+cmd] {file}
  209. Find {file} in 'path' and then |:edit| it.
  210. :{count}fin[d][!] [++opt] [+cmd] {file}
  211. Just like ":find", but use the {count} match in
  212. 'path'. Thus ":2find file" will find the second
  213. "file" found in 'path'. When there are fewer matches
  214. for the file in 'path' than asked for, you get an
  215. error message.
  216. *:ex*
  217. :ex [++opt] [+cmd] [file]
  218. Same as |:edit|.
  219. *:vi* *:visual*
  220. :vi[sual][!] [++opt] [+cmd] [file]
  221. When used in Ex mode: Leave |Ex-mode|, go back to
  222. Normal mode. Otherwise same as |:edit|.
  223. *:vie* *:view*
  224. :vie[w][!] [++opt] [+cmd] file
  225. When used in Ex mode: Leave |Ex-mode|, go back to
  226. Normal mode. Otherwise same as |:edit|, but set
  227. 'readonly' option for this buffer.
  228. *CTRL-^* *CTRL-6*
  229. CTRL-^ Edit the alternate file. Mostly the alternate file is
  230. the previously edited file. This is a quick way to
  231. toggle between two files. It is equivalent to ":e #",
  232. except that it also works when there is no file name.
  233. If the 'autowrite' or 'autowriteall' option is on and
  234. the buffer was changed, write it.
  235. Mostly the ^ character is positioned on the 6 key,
  236. pressing CTRL and 6 then gets you what we call CTRL-^.
  237. But on some non-US keyboards CTRL-^ is produced in
  238. another way.
  239. {count}CTRL-^ Edit [count]th file in the buffer list (equivalent to
  240. ":e #[count]"). This is a quick way to switch between
  241. files.
  242. See |CTRL-^| above for further details.
  243. [count]]f *]f* *[f*
  244. [count][f Same as "gf". Deprecated.
  245. *gf* *E446* *E447*
  246. [count]gf Edit the file whose name is under or after the cursor.
  247. Mnemonic: "goto file".
  248. Uses the 'isfname' option to find out which characters
  249. are supposed to be in a file name. Trailing
  250. punctuation characters ".,:;!" are ignored. Escaped
  251. spaces "\ " are reduced to a single space.
  252. Uses the 'path' option as a list of directory names to
  253. look for the file. See the 'path' option for details
  254. about relative directories and wildcards.
  255. Uses the 'suffixesadd' option to check for file names
  256. with a suffix added.
  257. If the file can't be found, 'includeexpr' is used to
  258. modify the name and another attempt is done.
  259. If a [count] is given, the count'th file that is found
  260. in the 'path' is edited.
  261. This command fails if Vim refuses to |abandon| the
  262. current file.
  263. If you want to edit the file in a new window use
  264. |CTRL-W_CTRL-F|.
  265. If you do want to edit a new file, use: >
  266. :e <cfile>
  267. < To make gf always work like that: >
  268. :map gf :e <cfile><CR>
  269. < If the name is a hypertext link, that looks like
  270. "type://machine/path", you need the |netrw| plugin.
  271. For Unix the '~' character is expanded, like in
  272. "~user/file". Environment variables are expanded too
  273. |expand-env|.
  274. *v_gf*
  275. {Visual}[count]gf Same as "gf", but the highlighted text is used as the
  276. name of the file to edit. 'isfname' is ignored.
  277. Leading blanks are skipped, otherwise all blanks and
  278. special characters are included in the file name.
  279. (For {Visual} see |Visual-mode|.)
  280. *gF*
  281. [count]gF Same as "gf", except if a number follows the file
  282. name, then the cursor is positioned on that line in
  283. the file.
  284. The file name and the number must be separated by a
  285. non-filename (see 'isfname') and non-numeric
  286. character. " line " is also recognized, like it is
  287. used in the output of `:verbose command UserCmd`
  288. White space between the filename, the separator and
  289. the number are ignored.
  290. Examples:
  291. eval.c:10 ~
  292. eval.c @ 20 ~
  293. eval.c (30) ~
  294. eval.c 40 ~
  295. *v_gF*
  296. {Visual}[count]gF Same as "v_gf".
  297. These commands are used to start editing a single file. This means that the
  298. file is read into the buffer and the current file name is set. The file that
  299. is opened depends on the current directory, see |:cd|.
  300. See |read-messages| for an explanation of the message that is given after the
  301. file has been read.
  302. You can use the ":e!" command if you messed up the buffer and want to start
  303. all over again. The ":e" command is only useful if you have changed the
  304. current file name.
  305. *:filename* *{file}*
  306. Besides the things mentioned here, more special items for where a filename is
  307. expected are mentioned at |cmdline-special|.
  308. Note for systems other than Unix: When using a command that accepts a single
  309. file name (like ":edit file") spaces in the file name are allowed, but
  310. trailing spaces are ignored. This is useful on systems that regularly embed
  311. spaces in file names (like MS-Windows and the Amiga). Example: The command
  312. ":e Long File Name " will edit the file "Long File Name". When using a
  313. command that accepts more than one file name (like ":next file1 file2")
  314. embedded spaces must be escaped with a backslash.
  315. *wildcard* *wildcards*
  316. Wildcards in {file} are expanded, but as with file completion, 'wildignore'
  317. and 'suffixes' apply. Which wildcards are supported depends on the system.
  318. These are the common ones:
  319. ? matches one character
  320. * matches anything, including nothing
  321. ** matches anything, including nothing, recurses into directories
  322. [abc] match 'a', 'b' or 'c'
  323. To avoid the special meaning of the wildcards prepend a backslash. However,
  324. on MS-Windows the backslash is a path separator and "path\[abc]" is still seen
  325. as a wildcard when "[" is in the 'isfname' option. A simple way to avoid this
  326. is to use "path\[[]abc]", this matches the file "path\[abc]".
  327. *starstar-wildcard*
  328. Expanding "**" is possible on Unix, Win32, macOS and a few other systems.
  329. This allows searching a directory tree. This goes up to 100 directories deep.
  330. Note there are some commands where this works slightly differently, see
  331. |file-searching|.
  332. Example: >
  333. :n **/*.txt
  334. Finds files:
  335. aaa.txt ~
  336. subdir/bbb.txt ~
  337. a/b/c/d/ccc.txt ~
  338. When non-wildcard characters are used right before or after "**" these are
  339. only matched in the top directory. They are not used for directories further
  340. down in the tree. For example: >
  341. :n /usr/inc**/types.h
  342. Finds files:
  343. /usr/include/types.h ~
  344. /usr/include/sys/types.h ~
  345. /usr/inc/old/types.h ~
  346. Note that the path with "/sys" is included because it does not need to match
  347. "/inc". Thus it's like matching "/usr/inc*/*/*...", not
  348. "/usr/inc*/inc*/inc*".
  349. *backtick-expansion* *`-expansion*
  350. On Unix and a few other systems you can also use backticks for the file name
  351. argument, for example: >
  352. :next `find . -name ver\\*.c -print`
  353. :view `ls -t *.patch \| head -n1`
  354. Vim will run the command in backticks using the 'shell' and use the standard
  355. output as argument for the given Vim command (error messages from the shell
  356. command will be discarded).
  357. To see what shell command Vim is running, set the 'verbose' option to 4. When
  358. the shell command returns a non-zero exit code, an error message will be
  359. displayed and the Vim command will be aborted. To avoid this make the shell
  360. always return zero like so: >
  361. :next `find . -name ver\\*.c -print \|\| true`
  362. The backslashes before the star are required to prevent the shell from
  363. expanding "ver*.c" prior to execution of the find program. The backslash
  364. before the shell pipe symbol "|" prevents Vim from parsing it as command
  365. termination.
  366. This also works for most other systems, with the restriction that the
  367. backticks must be around the whole item. It is not possible to have text
  368. directly before the first or just after the last backtick.
  369. *`=* *E1083*
  370. You can have the backticks expanded as a Vim expression, instead of as an
  371. external command, by putting an equal sign right after the first backtick,
  372. e.g.: >
  373. :e `=tempname()`
  374. The expression can contain just about anything, thus this can also be used to
  375. avoid the special meaning of '"', '|', '%' and '#'. However, 'wildignore'
  376. does apply like to other wildcards.
  377. Environment variables in the expression are expanded when evaluating the
  378. expression, thus this works: >
  379. :e `=$HOME .. '/.vimrc'`
  380. This uses $HOME inside a string and it will be used literally, most likely not
  381. what you intended: >
  382. :e `='$HOME' .. '/.vimrc'`
  383. If the expression returns a string then names are to be separated with line
  384. breaks. When the result is a |List| then each item is used as a name. Line
  385. breaks also separate names.
  386. Note that such expressions are only supported in places where a filename is
  387. expected as an argument to an Ex-command.
  388. *++opt* *[++opt]*
  389. The [++opt] argument can be used to force the value of 'fileformat',
  390. 'fileencoding' or 'binary' to a value for one command, and to specify the
  391. behavior for bad characters. The form is: >
  392. ++{optname}
  393. Or: >
  394. ++{optname}={value}
  395. Where {optname} is one of: *++ff* *++enc* *++bin* *++nobin* *++edit*
  396. ff or fileformat overrides 'fileformat'
  397. enc or encoding overrides 'fileencoding'
  398. bin or binary sets 'binary'
  399. nobin or nobinary resets 'binary'
  400. bad specifies behavior for bad characters
  401. edit for |:read| only: keep option values as if editing
  402. a file
  403. {value} cannot contain white space. It can be any valid value for these
  404. options. Examples: >
  405. :e ++ff=unix
  406. This edits the same file again with 'fileformat' set to "unix". >
  407. :w ++enc=latin1 newfile
  408. This writes the current buffer to "newfile" in latin1 format.
  409. The message given when writing a file will show "[converted]" when
  410. 'fileencoding' or the value specified with ++enc differs from 'encoding'.
  411. There may be several ++opt arguments, separated by white space. They must all
  412. appear before any |+cmd| argument.
  413. *++bad*
  414. The argument of "++bad=" specifies what happens with characters that can't be
  415. converted and illegal bytes. It can be one of three things:
  416. ++bad=X A single-byte character that replaces each bad character.
  417. ++bad=keep Keep bad characters without conversion. Note that this may
  418. result in illegal bytes in your text!
  419. ++bad=drop Remove the bad characters.
  420. The default is like "++bad=?": Replace each bad character with a question
  421. mark. In some places an inverted question mark is used (0xBF).
  422. Note that not all commands use the ++bad argument, even though they do not
  423. give an error when you add it. E.g. |:write|.
  424. Note that when reading, the 'fileformat' and 'fileencoding' options will be
  425. set to the used format. When writing this doesn't happen, thus a next write
  426. will use the old value of the option. Same for the 'binary' option.
  427. *+cmd* *[+cmd]*
  428. The [+cmd] argument can be used to position the cursor in the newly opened
  429. file, or execute any other command:
  430. + Start at the last line.
  431. +{num} Start at line {num}.
  432. +/{pat} Start at first line containing {pat}.
  433. +{command} Execute {command} after opening the new file.
  434. {command} is any Ex command.
  435. To include a white space in the {pat} or {command}, precede it with a
  436. backslash. Double the number of backslashes. >
  437. :edit +/The\ book file
  438. :edit +/dir\ dirname\\ file
  439. :edit +set\ dir=c:\\\\temp file
  440. Note that in the last example the number of backslashes is halved twice: Once
  441. for the "+cmd" argument and once for the ":set" command.
  442. *file-formats*
  443. The 'fileformat' option sets the <EOL> style for a file:
  444. 'fileformat' characters name ~
  445. "dos" <CR><NL> or <NL> DOS format *DOS-format*
  446. "unix" <NL> Unix format *Unix-format*
  447. "mac" <CR> Mac format *Mac-format*
  448. Previously 'textmode' was used. It is obsolete now.
  449. When reading a file, the mentioned characters are interpreted as the <EOL>.
  450. In DOS format (default for Win32), <CR><NL> and <NL> are both interpreted as
  451. the <EOL>. Note that when writing the file in DOS format, <CR> characters
  452. will be added for each single <NL>. Also see |file-read|.
  453. When writing a file, the mentioned characters are used for <EOL>. For DOS
  454. format <CR><NL> is used. Also see |DOS-format-write|.
  455. You can read a file in DOS format and write it in Unix format. This will
  456. replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): >
  457. :e file
  458. :set fileformat=unix
  459. :w
  460. If you read a file in Unix format and write with DOS format, all <NL>
  461. characters will be replaced with <CR><NL> (assuming 'fileformats' includes
  462. "unix"): >
  463. :e file
  464. :set fileformat=dos
  465. :w
  466. If you start editing a new file and the 'fileformats' option is not empty
  467. (which is the default), Vim will try to detect whether the lines in the file
  468. are separated by the specified formats. When set to "unix,dos", Vim will
  469. check for lines with a single <NL> (as used on Unix and Amiga) or by a <CR>
  470. <NL> pair (MS-Windows). Only when ALL lines end in <CR><NL>, 'fileformat' is
  471. set to "dos", otherwise it is set to "unix". When 'fileformats' includes
  472. "mac", and no <NL> characters are found in the file, 'fileformat' is set to
  473. "mac".
  474. If the 'fileformat' option is set to "dos" on non-MS-Windows systems the
  475. message "[dos format]" is shown to remind you that something unusual is
  476. happening. On MS-Windows systems you get the message "[unix format]" if
  477. 'fileformat' is set to "unix". On all systems but the Macintosh you get the
  478. message "[mac format]" if 'fileformat' is set to "mac".
  479. If the 'fileformats' option is empty and DOS format is used, but while reading
  480. a file some lines did not end in <CR><NL>, "[CR missing]" will be included in
  481. the file message.
  482. If the 'fileformats' option is empty and Mac format is used, but while reading
  483. a file a <NL> was found, "[NL missing]" will be included in the file message.
  484. If the new file does not exist, the 'fileformat' of the current buffer is used
  485. when 'fileformats' is empty. Otherwise the first format from 'fileformats' is
  486. used for the new file.
  487. Before editing binary, executable or Vim script files you should set the
  488. 'binary' option. A simple way to do this is by starting Vim with the "-b"
  489. option. This will avoid the use of 'fileformat'. Without this you risk that
  490. single <NL> characters are unexpectedly replaced with <CR><NL>.
  491. You can encrypt files that are written by setting the 'key' option. This
  492. provides some security against others reading your files. |encryption|
  493. END OF LINE AND END OF FILE *eol-and-eof*
  494. Vim has several options to control the file format:
  495. 'fileformat' the <EOL> style: Unix, DOS, Mac
  496. 'endofline' whether the last line ends with a <EOL>
  497. 'endoffile' whether the file ends with a CTRL-Z
  498. 'fixendofline' whether to fix eol and eof
  499. The first three values are normally detected automatically when reading the
  500. file and are used when writing the text to a file. While editing the buffer
  501. it looks like every line has a line ending and the CTRL-Z isn't there (an
  502. exception is when 'binary' is set, it works differently then).
  503. The 'fixendofline' option can be used to choose what to write. You can also
  504. change the option values to write the file differently than how it was read.
  505. Here are some examples how to use them.
  506. If you want files in Unix format (every line NL terminated): >
  507. setl ff=unix fixeol
  508. You should probably do this on any Unix-like system. Also modern MS-Windows
  509. systems tend to work well with this. It is recommended to always use this
  510. format for Vim scripts.
  511. If you want to use an old MS-DOS file in a modern environment, fixing line
  512. endings and dropping CTRL-Z, but keeping the <CR><NL> style <EOL>: >
  513. setl ff=dos fixeol
  514. This is useful for many MS-Windows programs, they regularly expect the
  515. <CR><NL> line endings.
  516. If you want to drop the final <EOL> and add a final CTRL-Z (e.g. for an old
  517. system like CP/M): >
  518. setl ff=dos nofixeol noeol eof
  519. If you want to preserve the fileformat exactly as-is, including any final
  520. <EOL> and final CTRL-Z: >
  521. setl nofixeol
  522. ==============================================================================
  523. 3. The argument list *argument-list* *arglist*
  524. If you give more than one file name when starting Vim, this list is remembered
  525. as the argument list. You can jump to each file in this list.
  526. Do not confuse this with the buffer list, which you can see with the
  527. |:buffers| command. The argument list was already present in Vi, the buffer
  528. list is new in Vim. Every file name in the argument list will also be present
  529. in the buffer list (unless it was deleted with |:bdel| or |:bwipe|). But it's
  530. common that names in the buffer list are not in the argument list.
  531. This subject is introduced in section |07.2| of the user manual.
  532. There is one global argument list, which is used for all windows by default.
  533. It is possible to create a new argument list local to a window, see
  534. |:arglocal|.
  535. You can use the argument list with the following commands, and with the
  536. expression functions |argc()| and |argv()|. These all work on the argument
  537. list of the current window.
  538. *:ar* *:arg* *:args*
  539. :ar[gs] Print the argument list, with the current file in
  540. square brackets.
  541. :ar[gs] [++opt] [+cmd] {arglist} *:args_f*
  542. Define {arglist} as the new argument list and edit
  543. the first one. This fails when changes have been made
  544. and Vim does not want to |abandon| the current buffer.
  545. Also see |++opt| and |+cmd|.
  546. :ar[gs]! [++opt] [+cmd] {arglist} *:args_f!*
  547. Define {arglist} as the new argument list and edit
  548. the first one. Discard any changes to the current
  549. buffer.
  550. Also see |++opt| and |+cmd|.
  551. :[count]arge[dit][!] [++opt] [+cmd] {name} .. *:arge* *:argedit*
  552. Add {name}s to the argument list and edit it.
  553. When {name} already exists in the argument list, this
  554. entry is edited.
  555. This is like using |:argadd| and then |:edit|.
  556. Spaces in filenames have to be escaped with "\".
  557. [count] is used like with |:argadd|.
  558. If the current file cannot be |abandon|ed {name}s will
  559. still be added to the argument list, but won't be
  560. edited. No check for duplicates is done.
  561. Also see |++opt| and |+cmd|.
  562. :[count]arga[dd] {name} .. *:arga* *:argadd* *E479*
  563. :[count]arga[dd] *E1156*
  564. Add the {name}s to the argument list. When {name} is
  565. omitted add the current buffer name to the argument
  566. list.
  567. If [count] is omitted, the {name}s are added just
  568. after the current entry in the argument list.
  569. Otherwise they are added after the [count]'th file.
  570. If the argument list is "a b c", and "b" is the
  571. current argument, then these commands result in:
  572. command new argument list ~
  573. :argadd x a b x c
  574. :0argadd x x a b c
  575. :1argadd x a x b c
  576. :$argadd x a b c x
  577. And after the last one:
  578. :+2argadd y a b c x y
  579. There is no check for duplicates, it is possible to
  580. add a file to the argument list twice. You can use
  581. |:argdedupe| to fix it afterwards: >
  582. :argadd *.txt | argdedupe
  583. < The currently edited file is not changed.
  584. Note: you can also use this method: >
  585. :args ## x
  586. < This will add the "x" item and sort the new list.
  587. :argded[upe] *:argded* *:argdedupe*
  588. Remove duplicate filenames from the argument list.
  589. If your current file is a duplicate, your current file
  590. will change to the original file index.
  591. :argd[elete] {pattern} .. *:argd* *:argdelete* *E480* *E610*
  592. Delete files from the argument list that match the
  593. {pattern}s. {pattern} is used like a file pattern,
  594. see |file-pattern|. "%" can be used to delete the
  595. current entry.
  596. This command keeps the currently edited file, also
  597. when it's deleted from the argument list.
  598. Example: >
  599. :argdel *.obj
  600. :[range]argd[elete] Delete the [range] files from the argument list.
  601. Example: >
  602. :10,$argdel
  603. < Deletes arguments 10 and further, keeping 1-9. >
  604. :$argd
  605. < Deletes just the last one. >
  606. :argd
  607. :.argd
  608. < Deletes the current argument. >
  609. :%argd
  610. < Removes all the files from the arglist.
  611. When the last number in the range is too high, up to
  612. the last argument is deleted.
  613. *:argu* *:argument*
  614. :[count]argu[ment] [count] [++opt] [+cmd]
  615. Edit file [count] in the argument list. When [count]
  616. is omitted the current entry is used. This fails
  617. when changes have been made and Vim does not want to
  618. |abandon| the current buffer.
  619. Also see |++opt| and |+cmd|.
  620. :[count]argu[ment]! [count] [++opt] [+cmd]
  621. Edit file [count] in the argument list, discard any
  622. changes to the current buffer. When [count] is
  623. omitted the current entry is used.
  624. Also see |++opt| and |+cmd|.
  625. :[count]n[ext] [++opt] [+cmd] *:n* *:ne* *:next* *E165* *E163*
  626. Edit [count] next file. This fails when changes have
  627. been made and Vim does not want to |abandon| the
  628. current buffer. Also see |++opt| and |+cmd|.
  629. :[count]n[ext]! [++opt] [+cmd]
  630. Edit [count] next file, discard any changes to the
  631. buffer. Also see |++opt| and |+cmd|.
  632. :n[ext] [++opt] [+cmd] {arglist} *:next_f*
  633. Same as |:args_f|.
  634. :n[ext]! [++opt] [+cmd] {arglist}
  635. Same as |:args_f!|.
  636. :[count]N[ext] [count] [++opt] [+cmd] *:Next* *:N* *E164*
  637. Edit [count] previous file in argument list. This
  638. fails when changes have been made and Vim does not
  639. want to |abandon| the current buffer.
  640. Also see |++opt| and |+cmd|.
  641. :[count]N[ext]! [count] [++opt] [+cmd]
  642. Edit [count] previous file in argument list. Discard
  643. any changes to the buffer. Also see |++opt| and
  644. |+cmd|.
  645. :[count]prev[ious] [count] [++opt] [+cmd] *:prev* *:previous*
  646. Same as :Next. Also see |++opt| and |+cmd|.
  647. *:rew* *:rewind*
  648. :rew[ind] [++opt] [+cmd]
  649. Start editing the first file in the argument list.
  650. This fails when changes have been made and Vim does
  651. not want to |abandon| the current buffer.
  652. Also see |++opt| and |+cmd|.
  653. :rew[ind]! [++opt] [+cmd]
  654. Start editing the first file in the argument list.
  655. Discard any changes to the buffer. Also see |++opt|
  656. and |+cmd|.
  657. *:fir* *:first*
  658. :fir[st][!] [++opt] [+cmd]
  659. Other name for ":rewind".
  660. *:la* *:last*
  661. :la[st] [++opt] [+cmd]
  662. Start editing the last file in the argument list.
  663. This fails when changes have been made and Vim does
  664. not want to |abandon| the current buffer.
  665. Also see |++opt| and |+cmd|.
  666. :la[st]! [++opt] [+cmd]
  667. Start editing the last file in the argument list.
  668. Discard any changes to the buffer. Also see |++opt|
  669. and |+cmd|.
  670. *:wn* *:wnext*
  671. :[count]wn[ext] [++opt]
  672. Write current file and start editing the [count]
  673. next file. Also see |++opt| and |+cmd|.
  674. :[count]wn[ext] [++opt] {file}
  675. Write current file to {file} and start editing the
  676. [count] next file, unless {file} already exists and
  677. the 'writeany' option is off. Also see |++opt| and
  678. |+cmd|.
  679. :[count]wn[ext]! [++opt] {file}
  680. Write current file to {file} and start editing the
  681. [count] next file. Also see |++opt| and |+cmd|.
  682. :[count]wN[ext][!] [++opt] [file] *:wN* *:wNext*
  683. :[count]wp[revious][!] [++opt] [file] *:wp* *:wprevious*
  684. Same as :wnext, but go to previous file instead of
  685. next.
  686. The [count] in the commands above defaults to one. For some commands it is
  687. possible to use two counts. The last one (rightmost one) is used.
  688. If no [+cmd] argument is present, the cursor is positioned at the last known
  689. cursor position for the file. If 'startofline' is set, the cursor will be
  690. positioned at the first non-blank in the line, otherwise the last know column
  691. is used. If there is no last known cursor position the cursor will be in the
  692. first line (the last line in Ex mode).
  693. *{arglist}*
  694. The wildcards in the argument list are expanded and the file names are sorted.
  695. Thus you can use the command "vim *.c" to edit all the C files. From within
  696. Vim the command ":n *.c" does the same.
  697. White space is used to separate file names. Put a backslash before a space or
  698. tab to include it in a file name. E.g., to edit the single file "foo bar": >
  699. :next foo\ bar
  700. On Unix and a few other systems you can also use backticks, for example: >
  701. :next `find . -name \\*.c -print`
  702. The backslashes before the star are required to prevent "*.c" to be expanded
  703. by the shell before executing the find program.
  704. *arglist-position*
  705. When there is an argument list you can see which file you are editing in the
  706. title of the window (if there is one and 'title' is on) and with the file
  707. message you get with the "CTRL-G" command. You will see something like
  708. (file 4 of 11)
  709. If 'shortmess' contains 'f' it will be
  710. (4 of 11)
  711. If you are not really editing the file at the current position in the argument
  712. list it will be
  713. (file (4) of 11)
  714. This means that you are position 4 in the argument list, but not editing the
  715. fourth file in the argument list. This happens when you do ":e file".
  716. LOCAL ARGUMENT LIST
  717. *:arglocal*
  718. :argl[ocal] Make a local copy of the global argument list.
  719. Doesn't start editing another file.
  720. :argl[ocal][!] [++opt] [+cmd] {arglist}
  721. Define a new argument list, which is local to the
  722. current window. Works like |:args_f| otherwise.
  723. *:argglobal*
  724. :argg[lobal] Use the global argument list for the current window.
  725. Doesn't start editing another file.
  726. :argg[lobal][!] [++opt] [+cmd] {arglist}
  727. Use the global argument list for the current window.
  728. Define a new global argument list like |:args_f|.
  729. All windows using the global argument list will see
  730. this new list.
  731. There can be several argument lists. They can be shared between windows.
  732. When they are shared, changing the argument list in one window will also
  733. change it in the other window.
  734. When a window is split the new window inherits the argument list from the
  735. current window. The two windows then share this list, until one of them uses
  736. |:arglocal| or |:argglobal| to use another argument list.
  737. USING THE ARGUMENT LIST
  738. *:argdo*
  739. :[range]argdo[!] {cmd} Execute {cmd} for each file in the argument list or
  740. if [range] is specified only for arguments in that
  741. range. It works like doing this: >
  742. :rewind
  743. :{cmd}
  744. :next
  745. :{cmd}
  746. etc.
  747. < When the current file can't be |abandon|ed and the [!]
  748. is not present, the command fails.
  749. When an error is detected on one file, further files
  750. in the argument list will not be visited.
  751. The last file in the argument list (or where an error
  752. occurred) becomes the current file.
  753. {cmd} can contain '|' to concatenate several commands.
  754. {cmd} must not change the argument list.
  755. Note: While this command is executing, the Syntax
  756. autocommand event is disabled by adding it to
  757. 'eventignore'. This considerably speeds up editing
  758. each file.
  759. Also see |:windo|, |:tabdo|, |:bufdo|, |:cdo|, |:ldo|,
  760. |:cfdo| and |:lfdo|
  761. Example: >
  762. :args *.c
  763. :argdo set ff=unix | update
  764. This sets the 'fileformat' option to "unix" and writes the file if it is now
  765. changed. This is done for all *.c files.
  766. Example: >
  767. :args *.[ch]
  768. :argdo %s/\<my_foo\>/My_Foo/ge | update
  769. This changes the word "my_foo" to "My_Foo" in all *.c and *.h files. The "e"
  770. flag is used for the ":substitute" command to avoid an error for files where
  771. "my_foo" isn't used. ":update" writes the file only if changes were made.
  772. ==============================================================================
  773. 4. Writing *writing* *save-file*
  774. Note: When the 'write' option is off, you are not able to write any file.
  775. *:w* *:write*
  776. *E502* *E503* *E504* *E505*
  777. *E512* *E514* *E667* *E949*
  778. :w[rite] [++opt] Write the whole buffer to the current file. This is
  779. the normal way to save changes to a file. It fails
  780. when the 'readonly' option is set or when there is
  781. another reason why the file can't be written.
  782. For ++opt see |++opt|, but only ++bin, ++nobin, ++ff
  783. and ++enc are effective.
  784. :w[rite]! [++opt] Like ":write", but forcefully write when 'readonly' is
  785. set or there is another reason why writing was
  786. refused.
  787. Note: This may change the permission and ownership of
  788. the file and break (symbolic) links. Add the 'W' flag
  789. to 'cpoptions' to avoid this.
  790. :[range]w[rite][!] [++opt]
  791. Write the specified lines to the current file. This
  792. is unusual, because the file will not contain all
  793. lines in the buffer.
  794. *:w_f* *:write_f*
  795. :[range]w[rite] [++opt] {file}
  796. Write the specified lines to {file}, unless it
  797. already exists and the 'writeany' option is off.
  798. *:w!*
  799. :[range]w[rite]! [++opt] {file}
  800. Write the specified lines to {file}. Overwrite an
  801. existing file.
  802. *:w_a* *:write_a* *E494*
  803. :[range]w[rite][!] [++opt] >>
  804. Append the specified lines to the current file.
  805. :[range]w[rite][!] [++opt] >> {file}
  806. Append the specified lines to {file}. '!' forces the
  807. write even if file does not exist.
  808. *:w_c* *:write_c*
  809. :[range]w[rite] [++opt] !{cmd}
  810. Execute {cmd} with [range] lines as standard input
  811. (note the space in front of the '!'). {cmd} is
  812. executed like with ":!{cmd}", any '!' is replaced with
  813. the previous command |:!|.
  814. The default [range] for the ":w" command is the whole buffer (1,$). If you
  815. write the whole buffer, it is no longer considered changed. When you
  816. write it to a different file with ":w somefile" it depends on the "+" flag in
  817. 'cpoptions'. When included, the write command will reset the 'modified' flag,
  818. even though the buffer itself may still be different from its file.
  819. If a file name is given with ":w" it becomes the alternate file. This can be
  820. used, for example, when the write fails and you want to try again later with
  821. ":w #". This can be switched off by removing the 'A' flag from the
  822. 'cpoptions' option.
  823. Note that the 'fsync' option matters here. If it's set it may make writes
  824. slower (but safer).
  825. *:sav* *:saveas*
  826. :sav[eas][!] [++opt] {file}
  827. Save the current buffer under the name {file} and set
  828. the filename of the current buffer to {file}. The
  829. previous name is used for the alternate file name.
  830. The [!] is needed to overwrite an existing file.
  831. When 'filetype' is empty filetype detection is done
  832. with the new name, before the file is written.
  833. When the write was successful 'readonly' is reset.
  834. *:up* *:update*
  835. :[range]up[date][!] [++opt] [>>] [file]
  836. Like ":write", but only write when the buffer has been
  837. modified.
  838. WRITING WITH MULTIPLE BUFFERS *buffer-write*
  839. *:wa* *:wall*
  840. :wa[ll] Write all changed buffers. Buffers without a file
  841. name cause an error message. Buffers which are
  842. readonly are not written.
  843. :wa[ll]! Write all changed buffers, even the ones that are
  844. readonly. Buffers without a file name are not
  845. written and cause an error message.
  846. Vim will warn you if you try to overwrite a file that has been changed
  847. elsewhere. See |timestamp|.
  848. *backup* *E207* *E506* *E507* *E508* *E509* *E510*
  849. If you write to an existing file (but do not append) while the 'backup',
  850. 'writebackup' or 'patchmode' option is on, a backup of the original file is
  851. made. The file is either copied or renamed (see 'backupcopy'). After the
  852. file has been successfully written and when the 'writebackup' option is on and
  853. the 'backup' option is off, the backup file is deleted. When the 'patchmode'
  854. option is on the backup file may be renamed.
  855. *backup-table*
  856. 'backup' 'writebackup' action ~
  857. off off no backup made
  858. off on backup current file, deleted afterwards (default)
  859. on off delete old backup, backup current file
  860. on on delete old backup, backup current file
  861. When the 'backupskip' pattern matches with the name of the file which is
  862. written, no backup file is made. The values of 'backup' and 'writebackup' are
  863. ignored then.
  864. When the 'backup' option is on, an old backup file (with the same name as the
  865. new backup file) will be deleted. If 'backup' is not set, but 'writebackup'
  866. is set, an existing backup file will not be deleted. The backup file that is
  867. made while the file is being written will have a different name.
  868. On some filesystems it's possible that in a crash you lose both the backup and
  869. the newly written file (it might be there but contain bogus data). In that
  870. case try recovery, because the swap file is synced to disk and might still be
  871. there. |:recover|
  872. The directories given with the 'backupdir' option are used to put the backup
  873. file in. (default: same directory as the written file).
  874. Whether the backup is a new file, which is a copy of the original file, or the
  875. original file renamed depends on the 'backupcopy' option. See there for an
  876. explanation of when the copy is made and when the file is renamed.
  877. If the creation of a backup file fails, the write is not done. If you want
  878. to write anyway add a '!' to the command.
  879. *write-permissions*
  880. When writing a new file the permissions are read-write. For unix the mask is
  881. 0o666 with additionally umask applied. When writing a file that was read Vim
  882. will preserve the permissions, but clear the s-bit.
  883. *write-readonly*
  884. When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
  885. readonly file. When 'W' is not present, ":w!" will overwrite a readonly file,
  886. if the system allows it (the directory must be writable).
  887. *write-fail*
  888. If the writing of the new file fails, you have to be careful not to lose
  889. your changes AND the original file. If there is no backup file and writing
  890. the new file failed, you have already lost the original file! DON'T EXIT VIM
  891. UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place
  892. of the original file (if possible). If you exit Vim, and lose the changes
  893. you made, the original file will mostly still be there. If putting back the
  894. original file fails, there will be an error message telling you that you
  895. lost the original file.
  896. *DOS-format-write*
  897. If the 'fileformat' is "dos", <CR><NL> is used for <EOL>. This is default
  898. for Win32. On other systems the message "[dos format]" is shown to remind you
  899. that an unusual <EOL> was used.
  900. *Unix-format-write*
  901. If the 'fileformat' is "unix", <NL> is used for <EOL>. On Win32 the message
  902. "[unix format]" is shown.
  903. *Mac-format-write*
  904. If the 'fileformat' is "mac", <CR> is used for <EOL>. On non-Mac systems the
  905. message "[mac format]" is shown.
  906. See also |file-formats| and the 'fileformat' and 'fileformats' options.
  907. *ACL*
  908. ACL stands for Access Control List. It is an advanced way to control access
  909. rights for a file. It is used on new MS-Windows and Unix systems, but only
  910. when the filesystem supports it.
  911. Vim attempts to preserve the ACL info when writing a file. The backup file
  912. will get the ACL info of the original file.
  913. The ACL info is also used to check if a file is read-only (when opening the
  914. file).
  915. *read-only-share*
  916. When MS-Windows shares a drive on the network it can be marked as read-only.
  917. This means that even if the file read-only attribute is absent, and the ACL
  918. settings on NT network shared drives allow writing to the file, you can still
  919. not write to the file. Vim on Win32 platforms will detect read-only network
  920. drives and will mark the file as read-only. You will not be able to override
  921. it with |:write|.
  922. *write-device*
  923. When the file name is actually a device name, Vim will not make a backup (that
  924. would be impossible). You need to use "!", since the device already exists.
  925. Example for Unix: >
  926. :w! /dev/lpt0
  927. and for MS-Windows: >
  928. :w! lpt0
  929. For Unix a device is detected when the name doesn't refer to a normal file or
  930. a directory. A fifo or named pipe also looks like a device to Vim.
  931. For MS-Windows the device is detected by its name:
  932. AUX
  933. CON
  934. CLOCK$
  935. NUL
  936. PRN
  937. COMn n=1,2,3... etc
  938. LPTn n=1,2,3... etc
  939. The names can be in upper- or lowercase.
  940. ==============================================================================
  941. 5. Writing and quitting *write-quit*
  942. *:q* *:quit*
  943. :q[uit] Quit the current window. Quit Vim if this is the last
  944. |edit-window|. This fails when changes have been made
  945. and Vim refuses to |abandon| the current buffer, and
  946. when the last file in the argument list has not been
  947. edited.
  948. If there are other tab pages and quitting the last
  949. window in the current tab page the current tab page is
  950. closed |tab-page|.
  951. Triggers the |QuitPre| autocommand event.
  952. See |CTRL-W_q| for quitting another window.
  953. :conf[irm] q[uit] Quit, but give prompt when changes have been made, or
  954. the last file in the argument list has not been
  955. edited. See |:confirm| and 'confirm'.
  956. :q[uit]! Quit without writing, also when the current buffer has
  957. changes. The buffer is unloaded, also when it has
  958. 'hidden' set.
  959. If this is the last window and there is a modified
  960. hidden buffer, the current buffer is abandoned and the
  961. first changed hidden buffer becomes the current
  962. buffer.
  963. Use ":qall!" to exit always.
  964. :cq[uit] Quit always, without writing, and return an error
  965. code. See |:cq|. Used for Manx's QuickFix mode (see
  966. |quickfix|).
  967. *:wq*
  968. :wq [++opt] Write the current file and close the window. If this
  969. was the last |edit-window| Vim quits.
  970. Writing fails when the file is read-only or the buffer
  971. does not have a name. Quitting fails when the last
  972. file in the argument list has not been edited.
  973. :wq! [++opt] Write the current file and close the window. If this
  974. was the last |edit-window| Vim quits. Writing fails
  975. when the current buffer does not have a name.
  976. :wq [++opt] {file} Write to {file} and close the window. If this was the
  977. last |edit-window| Vim quits. Quitting fails when the
  978. last file in the argument list has not been edited.
  979. :wq! [++opt] {file} Write to {file} and close the current window. Quit
  980. Vim if this was the last |edit-window|.
  981. :[range]wq[!] [++opt] [file]
  982. Same as above, but only write the lines in [range].
  983. *:x* *:xit*
  984. :[range]x[it][!] [++opt] [file]
  985. Like ":wq", but write only when changes have been
  986. made.
  987. When 'hidden' is set and there are more windows, the
  988. current buffer becomes hidden, after writing the file.
  989. This command is not supported in |Vim9| script,
  990. because it is too easily confused with a variable
  991. name.
  992. *:exi* *:exit*
  993. :[range]exi[t][!] [++opt] [file]
  994. Same as :xit.
  995. *ZZ*
  996. ZZ Write current file, if modified, and close the current
  997. window (same as ":x").
  998. If there are several windows for the current file,
  999. only the current window is closed.
  1000. *ZQ*
  1001. ZQ Quit without checking for changes (same as ":q!").
  1002. MULTIPLE WINDOWS AND BUFFERS *window-exit*
  1003. *:qa* *:qall*
  1004. :qa[ll] Exit Vim, unless there are some buffers which have been
  1005. changed. (Use ":bmod" to go to the next modified buffer).
  1006. When 'autowriteall' is set all changed buffers will be
  1007. written, like |:wqall|.
  1008. :conf[irm] qa[ll]
  1009. Exit Vim. Bring up a prompt when some buffers have been
  1010. changed. See |:confirm|.
  1011. :qa[ll]! Exit Vim. Any changes to buffers are lost.
  1012. Also see |:cquit|, it does the same but exits with a non-zero
  1013. value.
  1014. *:quita* *:quitall*
  1015. :quita[ll][!] Same as ":qall".
  1016. :wqa[ll] [++opt] *:wqa* *:wqall* *:xa* *:xall*
  1017. :xa[ll] Write all changed buffers and exit Vim. If there are buffers
  1018. without a file name, which are readonly or which cannot be
  1019. written for another reason, Vim will not quit.
  1020. :conf[irm] wqa[ll] [++opt]
  1021. :conf[irm] xa[ll]
  1022. Write all changed buffers and exit Vim. Bring up a prompt
  1023. when some buffers are readonly or cannot be written for
  1024. another reason. See |:confirm|.
  1025. :wqa[ll]! [++opt]
  1026. :xa[ll]! Write all changed buffers, even the ones that are readonly,
  1027. and exit Vim. If there are buffers without a file name or
  1028. which cannot be written for another reason, or there is a
  1029. terminal with a running job, Vim will not quit.
  1030. ==============================================================================
  1031. 6. Dialogs *edit-dialogs*
  1032. *:confirm* *:conf*
  1033. :conf[irm] {command} Execute {command}, and use a dialog when an
  1034. operation has to be confirmed. Can be used on the
  1035. |:q|, |:qa| and |:w| commands (the latter to override
  1036. a read-only setting), and any other command that can
  1037. fail in such a way, such as |:only|, |:buffer|,
  1038. |:bdelete|, etc.
  1039. Examples: >
  1040. :confirm w foo
  1041. < Will ask for confirmation when "foo" already exists. >
  1042. :confirm q
  1043. < Will ask for confirmation when there are changes. >
  1044. :confirm qa
  1045. < If any modified, unsaved buffers exist, you will be prompted to save
  1046. or abandon each one. There are also choices to "save all" or "abandon
  1047. all".
  1048. If you want to always use ":confirm", set the 'confirm' option.
  1049. *:browse* *:bro* *E338*
  1050. :bro[wse] {command} Open a file selection dialog for an argument to
  1051. {command}. At present this works for |:e|, |:w|,
  1052. |:wall|, |:wq|, |:wqall|, |:x|, |:xall|, |:exit|,
  1053. |:view|, |:sview|, |:r|, |:saveas|, |:sp|, |:mkexrc|,
  1054. |:mkvimrc|, |:mksession|, |:mkview|, |:split|,
  1055. |:vsplit|, |:tabe|, |:tabnew|, |:cfile|, |:cgetfile|,
  1056. |:caddfile|, |:lfile|, |:lgetfile|, |:laddfile|,
  1057. |:diffsplit|, |:diffpatch|, |:open|, |:pedit|,
  1058. |:redir|, |:source|, |:update|, |:visual|, |:vsplit|,
  1059. and |:qall| if 'confirm' is set.
  1060. {only in Win32, Motif, GTK and Mac GUI, in
  1061. console `browse edit` works if the FileExplorer
  1062. autocommand group exists}
  1063. When ":browse" is not possible you get an error
  1064. message. If the |+browse| feature is missing or the
  1065. {command} doesn't support browsing, the {command} is
  1066. executed without a dialog.
  1067. ":browse set" works like |:options|.
  1068. See also |:oldfiles| for ":browse oldfiles".
  1069. The syntax is best shown via some examples: >
  1070. :browse e $vim/foo
  1071. < Open the browser in the $vim/foo directory, and edit the
  1072. file chosen. >
  1073. :browse e
  1074. < Open the browser in the directory specified with 'browsedir',
  1075. and edit the file chosen. >
  1076. :browse w
  1077. < Open the browser in the directory of the current buffer,
  1078. with the current buffer filename as default, and save the
  1079. buffer under the filename chosen. >
  1080. :browse w C:/bar
  1081. < Open the browser in the C:/bar directory, with the current
  1082. buffer filename as default, and save the buffer under the
  1083. filename chosen.
  1084. Also see the 'browsedir' option.
  1085. For versions of Vim where browsing is not supported, the command is executed
  1086. unmodified.
  1087. *browsefilter*
  1088. For MS-Windows and GTK, you can modify the filters that are used in the browse
  1089. dialog. By setting the g:browsefilter or b:browsefilter variables, you can
  1090. change the filters globally or locally to the buffer. The variable is set to
  1091. a string in the format "{filter label}\t{pattern};{pattern}\n" where {filter
  1092. label} is the text that appears in the "Files of Type" comboBox, and {pattern}
  1093. is the pattern which filters the filenames. Several patterns can be given,
  1094. separated by ';'.
  1095. For Motif the same format is used, but only the very first pattern is actually
  1096. used (Motif only offers one pattern, but you can edit it).
  1097. For example, to have only Vim files in the dialog, you could use the following
  1098. command: >
  1099. let g:browsefilter = "Vim Scripts\t*.vim\nVim Startup Files\t*vimrc\n"
  1100. You can override the filter setting on a per-buffer basis by setting the
  1101. b:browsefilter variable. You would most likely set b:browsefilter in a
  1102. filetype plugin, so that the browse dialog would contain entries related to
  1103. the type of file you are currently editing. Disadvantage: This makes it
  1104. difficult to start editing a file of a different type. To overcome this, you
  1105. may want to add "All Files\t*.*\n" as the final filter, so that the user can
  1106. still access any desired file.
  1107. To avoid setting browsefilter when Vim does not actually support it, you can
  1108. use has("browsefilter"): >
  1109. if has("browsefilter")
  1110. let g:browsefilter = "whatever"
  1111. endif
  1112. ==============================================================================
  1113. 7. The current directory *current-directory*
  1114. You can use the |:cd|, |:tcd| and |:lcd| commands to change to another
  1115. directory, so you will not have to type that directory name in front of the
  1116. file names. It also makes a difference for executing external commands, e.g.
  1117. ":!ls".
  1118. Changing directory fails when the current buffer is modified, the '.' flag is
  1119. present in 'cpoptions' and "!" is not used in the command.
  1120. *:cd* *E747* *E472*
  1121. :cd[!] On non-Unix systems when 'cdhome' is off: Print the
  1122. current directory name.
  1123. Otherwise: Change the current directory to the home
  1124. directory. Clear any window-local directory.
  1125. Use |:pwd| to print the current directory on all
  1126. systems.
  1127. :cd[!] {path} Change the current directory to {path}.
  1128. If {path} is relative, it is searched for in the
  1129. directories listed in |'cdpath'|.
  1130. Clear any window-local directory.
  1131. Does not change the meaning of an already opened file,
  1132. because its full path name is remembered. Files from
  1133. the |arglist| may change though!
  1134. On MS-Windows this also changes the active drive.
  1135. To change to the directory of the current file: >
  1136. :cd %:h
  1137. <
  1138. *:cd-* *E186*
  1139. :cd[!] - Change to the previous current directory (before the
  1140. previous ":cd {path}" command).
  1141. *:chd* *:chdir*
  1142. :chd[ir][!] [path] Same as |:cd|.
  1143. *:tc* *:tcd*
  1144. :tc[d][!] {path} Like |:cd|, but only set the directory for the current
  1145. tab. The current window will also use this directory.
  1146. The current directory is not changed for windows in
  1147. other tabs and for windows in the current tab that
  1148. have their own window-local directory.
  1149. *:tcd-*
  1150. :tc[d][!] - Change to the previous current directory, before the
  1151. last ":tcd {path}" command.
  1152. *:tch* *:tchdir*
  1153. :tch[dir][!] Same as |:tcd|.
  1154. *:lc* *:lcd*
  1155. :lc[d][!] {path} Like |:cd|, but only set the current directory when
  1156. the cursor is in the current window. The current
  1157. directory for other windows is not changed, switching
  1158. to another window will stop using {path}.
  1159. *:lcd-*
  1160. :lcd[!] - Change to the previous current directory, before the
  1161. last ":lcd {path}" command.
  1162. *:lch* *:lchdir*
  1163. :lch[dir][!] Same as |:lcd|.
  1164. *:pw* *:pwd* *E187*
  1165. :pw[d] Print the current directory name.
  1166. Also see |getcwd()|.
  1167. *:pwd-verbose*
  1168. When 'verbose' is non-zero, |:pwd| will also display
  1169. what scope the current directory was set. Example: >
  1170. " Set by :cd
  1171. :verbose pwd
  1172. [global] /path/to/current
  1173. " Set by :lcd
  1174. :verbose pwd
  1175. [window] /path/to/current
  1176. " Set by :tcd
  1177. :verbose pwd
  1178. [tabpage] /path/to/current
  1179. So long as no |:lcd| or |:tcd| command has been used, all windows share the
  1180. same current directory. Using a command to jump to another window doesn't
  1181. change anything for the current directory.
  1182. When a |:lcd| command has been used for a window, the specified directory
  1183. becomes the current directory for that window. Windows where the |:lcd|
  1184. command has not been used stick to the global or tab-local current directory.
  1185. When jumping to another window the current directory is changed to the last
  1186. specified local current directory. If none was specified, the global or
  1187. tab-local current directory is used. When creating a new window it inherits
  1188. the local directory of the current window.
  1189. When a |:tcd| command has been used for a tab page, the specified directory
  1190. becomes the current directory for the current tab page and the current window.
  1191. The current directory of other tab pages is not affected. When jumping to
  1192. another tab page, the current directory is changed to the last specified local
  1193. directory for that tab page. If the current tab has no local current directory
  1194. the global current directory is used.
  1195. When a |:cd| command is used, the current window and tab page will lose the
  1196. local current directory and will use the global current directory from now on.
  1197. After using |:cd| the full path name will be used for reading and writing
  1198. files. On some networked file systems this may cause problems. The result of
  1199. using the full path name is that the file names currently in use will remain
  1200. referring to the same file. Example: If you have a file a:test and a
  1201. directory a:vim the commands ":e test" ":cd vim" ":w" will overwrite the file
  1202. a:test and not write a:vim/test. But if you do ":w test" the file a:vim/test
  1203. will be written, because you gave a new file name and did not refer to a
  1204. filename before the ":cd".
  1205. ==============================================================================
  1206. 8. Editing binary files *edit-binary*
  1207. Although Vim was made to edit text files, it is possible to edit binary
  1208. files. The |-b| Vim argument (b for binary) makes Vim do file I/O in binary
  1209. mode, and sets some options for editing binary files ('binary' on, 'textwidth'
  1210. to 0, 'modeline' off, 'expandtab' off). Setting the 'binary' option has the
  1211. same effect. Don't forget to do this before reading the file.
  1212. There are a few things to remember when editing binary files:
  1213. - When editing executable files the number of bytes must not change.
  1214. Use only the "R" or "r" command to change text. Do not delete characters
  1215. with "x" or by backspacing.
  1216. - Set the 'textwidth' option to 0. Otherwise lines will unexpectedly be
  1217. split in two.
  1218. - When there are not many <EOL>s, the lines will become very long. If you
  1219. want to edit a line that does not fit on the screen reset the 'wrap' option.
  1220. Horizontal scrolling is used then. If a line becomes too long (more than
  1221. about 32767 bytes on the Amiga, much more on 32-bit and 64-bit systems, see
  1222. |limits|) you cannot edit that line. The line will be split when reading
  1223. the file. It is also possible that you get an "out of memory" error when
  1224. reading the file.
  1225. - Make sure the 'binary' option is set BEFORE loading the
  1226. file. Otherwise both <CR><NL> and <NL> are considered to end a line
  1227. and when the file is written the <NL> will be replaced with <CR><NL>.
  1228. - <Nul> characters are shown on the screen as ^@. You can enter them with
  1229. "CTRL-V CTRL-@" or "CTRL-V 000"
  1230. - To insert a <NL> character in the file split a line. When writing the
  1231. buffer to a file a <NL> will be written for the <EOL>.
  1232. - Vim normally appends an <EOL> at the end of the file if there is none.
  1233. Setting the 'binary' option prevents this. If you want to add the final
  1234. <EOL>, set the 'endofline' option. You can also read the value of this
  1235. option to see if there was an <EOL> for the last line (you cannot see this
  1236. in the text).
  1237. ==============================================================================
  1238. 9. Encryption *encryption*
  1239. Vim is able to write files encrypted, and read them back. The encrypted text
  1240. cannot be read without the right key.
  1241. {only available when compiled with the |+cryptv| feature} *E833*
  1242. The text in the swap file and the undo file is also encrypted. *E843*
  1243. However, this is done block-by-block and may reduce the time needed to crack a
  1244. password. You can disable the swap file, but then a crash will cause you to
  1245. lose your work. The undo file can be disabled without too much disadvantage. >
  1246. :set noundofile
  1247. :noswapfile edit secrets
  1248. Note: The text in memory is not encrypted. A system administrator may be able
  1249. to see your text while you are editing it. When filtering text with
  1250. ":!filter" or using ":w !command" the text is also not encrypted, this may
  1251. reveal it to others. The 'viminfo' file is not encrypted.
  1252. You could do this to edit very secret text: >
  1253. :set noundofile viminfo=
  1254. :noswapfile edit secrets.txt
  1255. Keep in mind that without a swap file you risk losing your work in the event
  1256. of a crash or a power failure.
  1257. WARNING: If you make a typo when entering the key and then write the file and
  1258. exit, the text will be lost!
  1259. The normal way to work with encryption, is to use the ":X" command, which will
  1260. ask you to enter a key. A following write command will use that key to
  1261. encrypt the file. If you later edit the same file, Vim will ask you to enter
  1262. a key. If you type the same key as that was used for writing, the text will
  1263. be readable again. If you use a wrong key, it will be a mess.
  1264. *:X*
  1265. :X Prompt for an encryption key. The typing is done without showing the
  1266. actual text, so that someone looking at the display won't see it.
  1267. The typed key is stored in the 'key' option, which is used to encrypt
  1268. the file when it is written.
  1269. The file will remain unchanged until you write it. Note that commands
  1270. such as `:xit` and `ZZ` will NOT write the file unless there are other
  1271. changes.
  1272. See also |-x|.
  1273. The value of the 'key' options is used when text is written. When the option
  1274. is not empty, the written file will be encrypted, using the value as the
  1275. encryption key. A magic number is prepended, so that Vim can recognize that
  1276. the file is encrypted.
  1277. To disable the encryption, reset the 'key' option to an empty value: >
  1278. :set key=
  1279. You can use the 'cryptmethod' option to select the type of encryption, use one
  1280. of these: >
  1281. :setlocal cm=zip " weak method, backwards compatible
  1282. :setlocal cm=blowfish " method with flaws
  1283. :setlocal cm=blowfish2 " medium strong method
  1284. Do this before writing the file. When reading an encrypted file it will be
  1285. set automatically to the method used when that file was written. You can
  1286. change 'cryptmethod' before writing that file to change the method.
  1287. To set the default method, used for new files, use this in your |vimrc|
  1288. file: >
  1289. set cm=blowfish2
  1290. Using "blowfish2" is highly recommended. Only use another method if you
  1291. must use an older Vim version that does not support it.
  1292. The message given for reading and writing a file will show "[crypted]" when
  1293. using zip, "[blowfish]" when using blowfish, etc.
  1294. When writing an undo file, the same key and method will be used for the text
  1295. in the undo file. |persistent-undo|.
  1296. To test for blowfish support you can use these conditions: >
  1297. has('crypt-blowfish')
  1298. has('crypt-blowfish2')
  1299. This works since Vim 7.4.1099 while blowfish support was added earlier.
  1300. Thus the condition failing doesn't mean blowfish is not supported. You can
  1301. test for blowfish with: >
  1302. v:version >= 703
  1303. And for blowfish2 with: >
  1304. v:version > 704 || (v:version == 704 && has('patch401'))
  1305. If you are sure Vim includes patch 7.4.237 a simpler check is: >
  1306. has('patch-7.4.401')
  1307. <
  1308. *E817* *E818* *E819* *E820*
  1309. When encryption does not work properly, you would be able to write your text
  1310. to a file and never be able to read it back. Therefore a test is performed to
  1311. check if the encryption works as expected. If you get one of these errors
  1312. don't write the file encrypted! You need to rebuild the Vim binary to fix
  1313. this.
  1314. *E831* This is an internal error, "cannot happen". If you can reproduce it,
  1315. please report to the developers.
  1316. When reading a file that has been encrypted and the 'key' option is not empty,
  1317. it will be used for decryption. If the value is empty, you will be prompted
  1318. to enter the key. If you don't enter a key, or you enter the wrong key, the
  1319. file is edited without being decrypted. There is no warning about using the
  1320. wrong key (this makes brute force methods to find the key more difficult).
  1321. If want to start reading a file that uses a different key, set the 'key'
  1322. option to an empty string, so that Vim will prompt for a new one. Don't use
  1323. the ":set" command to enter the value, other people can read the command over
  1324. your shoulder.
  1325. Since the value of the 'key' option is supposed to be a secret, its value can
  1326. never be viewed. You should not set this option in a vimrc file.
  1327. An encrypted file can be recognized by the "file" command, if you add these
  1328. lines to "/etc/magic", "/usr/share/misc/magic" or wherever your system has the
  1329. "magic" file: >
  1330. 0 string VimCrypt~ Vim encrypted file
  1331. >9 string 01 - "zip" cryptmethod
  1332. >9 string 02 - "blowfish" cryptmethod
  1333. >9 string 03 - "blowfish2" cryptmethod
  1334. Notes:
  1335. - Encryption is not possible when doing conversion with 'charconvert'.
  1336. - Text you copy or delete goes to the numbered registers. The registers can
  1337. be saved in the .viminfo file, where they could be read. Change your
  1338. 'viminfo' option to be safe.
  1339. - Someone can type commands in Vim when you walk away for a moment, he should
  1340. not be able to get the key.
  1341. - If you make a typing mistake when entering the key, you might not be able to
  1342. get your text back!
  1343. - If you type the key with a ":set key=value" command, it can be kept in the
  1344. history, showing the 'key' value in a viminfo file.
  1345. - There is never 100% safety. The encryption in Vim has not been tested for
  1346. robustness.
  1347. - The algorithm used for 'cryptmethod' "zip" is breakable. A 4 character key
  1348. in about one hour, a 6 character key in one day (on a Pentium 133 PC). This
  1349. requires that you know some text that must appear in the file. An expert
  1350. can break it for any key. When the text has been decrypted, this also means
  1351. that the key can be revealed, and other files encrypted with the same key
  1352. can be decrypted.
  1353. - Pkzip uses the same encryption as 'cryptmethod' "zip", and US Govt has no
  1354. objection to its export. Pkzip's public file APPNOTE.TXT describes this
  1355. algorithm in detail.
  1356. - The implementation of 'cryptmethod' "blowfish" has a flaw. It is possible
  1357. to crack the first 64 bytes of a file and in some circumstances more of the
  1358. file. Use of it is not recommended, but it's still the strongest method
  1359. supported by Vim 7.3 and 7.4. The "zip" method is even weaker.
  1360. - Vim originates from the Netherlands. That is where the sources come from.
  1361. Thus the encryption code is not exported from the USA.
  1362. ==============================================================================
  1363. 10. Timestamps *timestamp* *timestamps*
  1364. Vim remembers the modification timestamp, mode and size of a file when you
  1365. begin editing it. This is used to avoid that you have two different versions
  1366. of the same file (without you knowing this).
  1367. After a shell command is run (|:!cmd| |suspend| |:read!| |K|) timestamps,
  1368. file modes and file sizes are compared for all buffers in a window. Vim will
  1369. run any associated |FileChangedShell| autocommands or display a warning for
  1370. any files that have changed. In the GUI this happens when Vim regains input
  1371. focus.
  1372. *E321* *E462*
  1373. If you want to automatically reload a file when it has been changed outside of
  1374. Vim, set the 'autoread' option. This doesn't work at the moment you write the
  1375. file though, only when the file wasn't changed inside of Vim.
  1376. *ignore-timestamp*
  1377. If you do not want to be asked or automatically reload the file, you can use
  1378. this: >
  1379. set buftype=nofile
  1380. Or, when starting gvim from a shell: >
  1381. gvim file.log -c "set buftype=nofile"
  1382. Note that if a FileChangedShell autocommand is defined you will not get a
  1383. warning message or prompt. The autocommand is expected to handle this.
  1384. There is no warning for a directory (e.g., with |netrw-browse|). But you do
  1385. get warned if you started editing a new file and it was created as a directory
  1386. later.
  1387. When Vim notices the timestamp of a file has changed, and the file is being
  1388. edited in a buffer but has not changed, Vim checks if the contents of the file
  1389. is equal. This is done by reading the file again (into a hidden buffer, which
  1390. is immediately deleted again) and comparing the text. If the text is equal,
  1391. you will get no warning.
  1392. If you don't get warned often enough you can use the following command.
  1393. *:checkt* *:checktime*
  1394. :checkt[ime] Check if any buffers were changed outside of Vim.
  1395. This checks and warns you if you would end up with two
  1396. versions of a file.
  1397. If this is called from an autocommand, a ":global"
  1398. command or is not typed the actual check is postponed
  1399. until a moment the side effects (reloading the file)
  1400. would be harmless.
  1401. Each loaded buffer is checked for its associated file
  1402. being changed. If the file was changed Vim will take
  1403. action. If there are no changes in the buffer and
  1404. 'autoread' is set, the buffer is reloaded. Otherwise,
  1405. you are offered the choice of reloading the file. If
  1406. the file was deleted you get an error message.
  1407. If the file previously didn't exist you get a warning
  1408. if it exists now.
  1409. Once a file has been checked the timestamp is reset,
  1410. you will not be warned again.
  1411. Syntax highlighting, marks, diff status,
  1412. 'fileencoding', 'fileformat' and 'binary' options
  1413. are not changed. See |v:fcs_choice| to reload these
  1414. too (for example, if a code formatting tools has
  1415. changed the file).
  1416. :[N]checkt[ime] {filename}
  1417. :[N]checkt[ime] [N]
  1418. Check the timestamp of a specific buffer. The buffer
  1419. may be specified by name, number or with a pattern.
  1420. *E813* *E814*
  1421. Vim will reload the buffer if you chose to. If a window is visible that
  1422. contains this buffer, the reloading will happen in the context of this window.
  1423. Otherwise a special window is used, so that most autocommands will work. You
  1424. can't close this window. A few other restrictions apply. Best is to make
  1425. sure nothing happens outside of the current buffer. E.g., setting
  1426. window-local options may end up in the wrong window. Splitting the window,
  1427. doing something there and closing it should be OK (if there are no side
  1428. effects from other autocommands). Closing unrelated windows and buffers will
  1429. get you into trouble.
  1430. Before writing a file the timestamp is checked. If it has changed, Vim will
  1431. ask if you really want to overwrite the file:
  1432. WARNING: The file has been changed since reading it!!!
  1433. Do you really want to write to it (y/n)?
  1434. If you hit 'y' Vim will continue writing the file. If you hit 'n' the write is
  1435. aborted. If you used ":wq" or "ZZ" Vim will not exit, you will get another
  1436. chance to write the file.
  1437. The message would normally mean that somebody has written to the file after
  1438. the edit session started. This could be another person, in which case you
  1439. probably want to check if your changes to the file and the changes from the
  1440. other person should be merged. Write the file under another name and check for
  1441. differences (the "diff" program can be used for this).
  1442. It is also possible that you modified the file yourself, from another edit
  1443. session or with another command (e.g., a filter command). Then you will know
  1444. which version of the file you want to keep.
  1445. The accuracy of the time check depends on the filesystem. On Unix it is
  1446. usually sub-second. With old file systems and on MS-Windows it is normally one
  1447. second. Use `has('nanotime')` to check if sub-second time stamp checks are
  1448. available.
  1449. There is one situation where you get the message while there is nothing wrong:
  1450. On a Win32 system on the day daylight saving time starts. There is something
  1451. in the Win32 libraries that confuses Vim about the hour time difference. The
  1452. problem goes away the next day.
  1453. ==============================================================================
  1454. 11. File Searching *file-searching*
  1455. The file searching is currently used for the 'path', 'cdpath' and 'tags'
  1456. options, for |finddir()| and |findfile()|. Other commands use |wildcards|
  1457. which is slightly different.
  1458. There are three different types of searching:
  1459. 1) Downward search: *starstar*
  1460. Downward search uses the wildcards '*', '**' and possibly others
  1461. supported by your operating system. '*' and '**' are handled inside Vim,
  1462. so they work on all operating systems. Note that "**" only acts as a
  1463. special wildcard when it is at the start of a name.
  1464. The usage of '*' is quite simple: It matches 0 or more characters. In a
  1465. search pattern this would be ".*". Note that the "." is not used for file
  1466. searching.
  1467. '**' is more sophisticated:
  1468. - It ONLY matches directories.
  1469. - It matches up to 30 directories deep by default, so you can use it to
  1470. search an entire directory tree
  1471. - The maximum number of levels matched can be given by appending a number
  1472. to '**'.
  1473. Thus '/usr/**2' can match: >
  1474. /usr
  1475. /usr/include
  1476. /usr/include/sys
  1477. /usr/include/g++
  1478. /usr/lib
  1479. /usr/lib/X11
  1480. ....
  1481. < It does NOT match '/usr/include/g++/std' as this would be three
  1482. levels.
  1483. The allowed number range is 0 ('**0' is removed) to 100
  1484. If the given number is smaller than 0 it defaults to 30, if it's
  1485. bigger than 100 then 100 is used. The system also has a limit on the
  1486. path length, usually 256 or 1024 bytes.
  1487. - '**' can only be at the end of the path or be followed by a path
  1488. separator or by a number and a path separator.
  1489. You can combine '*' and '**' in any order: >
  1490. /usr/**/sys/*
  1491. /usr/*tory/sys/**
  1492. /usr/**2/sys/*
  1493. 2) Upward search:
  1494. Here you can give a directory and then search the directory tree upward for
  1495. a file. You could give stop-directories to limit the upward search. The
  1496. stop-directories are appended to the path (for the 'path' option) or to
  1497. the filename (for the 'tags' option) with a ';'. If you want several
  1498. stop-directories separate them with ';'. If you want no stop-directory
  1499. ("search upward till the root directory) just use ';'. >
  1500. /usr/include/sys;/usr
  1501. < will search in: >
  1502. /usr/include/sys
  1503. /usr/include
  1504. /usr
  1505. <
  1506. If you use a relative path the upward search is started in Vim's current
  1507. directory or in the directory of the current file (if the relative path
  1508. starts with './' and 'd' is not included in 'cpoptions').
  1509. If Vim's current path is /u/user_x/work/release and you do >
  1510. :set path=include;/u/user_x
  1511. < and then search for a file with |gf| the file is searched in: >
  1512. /u/user_x/work/release/include
  1513. /u/user_x/work/include
  1514. /u/user_x/include
  1515. < Note: If your 'path' setting includes a non-existing directory, Vim will
  1516. skip the non-existing directory, and also does not search in the parent of
  1517. the non-existing directory if upwards searching is used.
  1518. 3) Combined up/downward search:
  1519. If Vim's current path is /u/user_x/work/release and you do >
  1520. set path=**;/u/user_x
  1521. < and then search for a file with |gf| the file is searched in: >
  1522. /u/user_x/work/release/**
  1523. /u/user_x/work/**
  1524. /u/user_x/**
  1525. <
  1526. BE CAREFUL! This might consume a lot of time, as the search of
  1527. '/u/user_x/**' includes '/u/user_x/work/**' and
  1528. '/u/user_x/work/release/**'. So '/u/user_x/work/release/**' is searched
  1529. three times and '/u/user_x/work/**' is searched twice.
  1530. In the above example you might want to set path to: >
  1531. :set path=**,/u/user_x/**
  1532. < This searches:
  1533. /u/user_x/work/release/** ~
  1534. /u/user_x/** ~
  1535. This searches the same directories, but in a different order.
  1536. Note that completion for ":find", ":sfind", and ":tabfind" commands do not
  1537. currently work with 'path' items that contain a URL or use the double star
  1538. with depth limiter (/usr/**2) or upward search (;) notations.
  1539. vim:tw=78:ts=8:noet:ft=help:norl: