editing.txt 65 KB

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