windows.txt 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. *windows.txt* For Vim version 9.0. Last change: 2022 Nov 27
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Editing with multiple windows and buffers. *windows* *buffers*
  4. The commands which have been added to use multiple windows and buffers are
  5. explained here. Additionally, there are explanations for commands that work
  6. differently when used in combination with more than one window.
  7. The basics are explained in chapter 7 and 8 of the user manual |usr_07.txt|
  8. |usr_08.txt|.
  9. 1. Introduction |windows-intro|
  10. 2. Starting Vim |windows-starting|
  11. 3. Opening and closing a window |opening-window|
  12. 4. Moving cursor to other windows |window-move-cursor|
  13. 5. Moving windows around |window-moving|
  14. 6. Window resizing |window-resize|
  15. 7. Argument and buffer list commands |buffer-list|
  16. 8. Do a command in all buffers or windows |list-repeat|
  17. 9. Tag or file name under the cursor |window-tag|
  18. 10. The preview window |preview-window|
  19. 11. Using hidden buffers |buffer-hidden|
  20. 12. Special kinds of buffers |special-buffers|
  21. {not able to use multiple windows when the |+windows| feature was disabled at
  22. compile time}
  23. ==============================================================================
  24. 1. Introduction *windows-intro* *window*
  25. Summary:
  26. A buffer is the in-memory text of a file.
  27. A window is a viewport on a buffer.
  28. A tab page is a collection of windows.
  29. A window is a viewport onto a buffer. You can use multiple windows on one
  30. buffer, or several windows on different buffers.
  31. A buffer is a file loaded into memory for editing. The original file remains
  32. unchanged until you write the buffer to the file.
  33. A buffer can be in one of three states:
  34. *active-buffer*
  35. active: The buffer is displayed in a window. If there is a file for this
  36. buffer, it has been read into the buffer. The buffer may have been
  37. modified since then and thus be different from the file.
  38. *hidden-buffer*
  39. hidden: The buffer is not displayed. If there is a file for this buffer, it
  40. has been read into the buffer. Otherwise it's the same as an active
  41. buffer, you just can't see it.
  42. *inactive-buffer*
  43. inactive: The buffer is not displayed and does not contain anything. Options
  44. for the buffer are remembered if the file was once loaded. It can
  45. contain marks from the |viminfo| file. But the buffer doesn't
  46. contain text.
  47. In a table:
  48. state displayed loaded ":buffers" ~
  49. in window shows ~
  50. active yes yes 'a'
  51. hidden no yes 'h'
  52. inactive no no ' '
  53. Note: All CTRL-W commands can also be executed with |:wincmd|, for those
  54. places where a Normal mode command can't be used or is inconvenient.
  55. The main Vim window can hold several split windows. There are also tab pages
  56. |tab-page|, each of which can hold multiple windows.
  57. *window-ID* *winid* *windowid*
  58. Each window has a unique identifier called the window ID. This identifier
  59. will not change within a Vim session. The |win_getid()| and |win_id2tabwin()|
  60. functions can be used to convert between the window/tab number and the
  61. identifier. There is also the window number, which may change whenever
  62. windows are opened or closed, see |winnr()|.
  63. The window number is only valid in one specific tab. The window ID is valid
  64. across tabs. For most functions that take a window ID or a window number, the
  65. window number only applies to the current tab, while the window ID can refer
  66. to a window in any tab.
  67. Each buffer has a unique number and the number will not change within a Vim
  68. session. The |bufnr()| and |bufname()| functions can be used to convert
  69. between a buffer name and the buffer number.
  70. ==============================================================================
  71. 2. Starting Vim *windows-starting*
  72. By default, Vim starts with one window, just like Vi.
  73. The "-o" and "-O" arguments to Vim can be used to open a window for each file
  74. in the argument list. The "-o" argument will split the windows horizontally;
  75. the "-O" argument will split the windows vertically. If both "-o" and "-O"
  76. are given, the last one encountered will be used to determine the split
  77. orientation. For example, this will open three windows, split horizontally: >
  78. vim -o file1 file2 file3
  79. "-oN", where N is a decimal number, opens N windows split horizontally. If
  80. there are more file names than windows, only N windows are opened and some
  81. files do not get a window. If there are more windows than file names, the
  82. last few windows will be editing empty buffers. Similarly, "-ON" opens N
  83. windows split vertically, with the same restrictions.
  84. If there are many file names, the windows will become very small. You might
  85. want to set the 'winheight' and/or 'winwidth' options to create a workable
  86. situation.
  87. Buf/Win Enter/Leave |autocommand|s are not executed when opening the new
  88. windows and reading the files, that's only done when they are really entered.
  89. *status-line*
  90. A status line will be used to separate windows. The 'laststatus' option tells
  91. when the last window also has a status line:
  92. 'laststatus' = 0 never a status line
  93. 'laststatus' = 1 status line if there is more than one window
  94. 'laststatus' = 2 always a status line
  95. You can change the contents of the status line with the 'statusline' option.
  96. This option can be local to the window, so that you can have a different
  97. status line in each window.
  98. Normally, inversion is used to display the status line. This can be changed
  99. with the 's' character in the 'highlight' option. For example, "sb" sets it to
  100. bold characters. If no highlighting is used for the status line ("sn"), the
  101. '^' character is used for the current window, and '=' for other windows. If
  102. the mouse is supported and enabled with the 'mouse' option, a status line can
  103. be dragged to resize windows.
  104. Note: If you expect your status line to be in reverse video and it isn't,
  105. check if the 'highlight' option contains "si". In version 3.0, this meant to
  106. invert the status line. Now it should be "sr", reverse the status line, as
  107. "si" now stands for italic! If italic is not available on your terminal, the
  108. status line is inverted anyway; you will only see this problem on terminals
  109. that have termcap codes for italics.
  110. *filler-lines*
  111. The lines after the last buffer line in a window are called filler lines. By
  112. default, these lines start with a tilde (~) character. The 'eob' item in the
  113. 'fillchars' option can be used to change this character. By default, these
  114. characters are highlighted as NonText (|hl-NonText|). The EndOfBuffer
  115. highlight group (|hl-EndOfBuffer|) can be used to change the highlighting of
  116. the filler characters.
  117. ==============================================================================
  118. 3. Opening and closing a window *opening-window*
  119. CTRL-W s *CTRL-W_s*
  120. CTRL-W S *CTRL-W_S*
  121. CTRL-W CTRL-S *CTRL-W_CTRL-S*
  122. :[N]sp[lit] [++opt] [+cmd] [file] *:sp* *:split*
  123. Split current window in two. The result is two viewports on
  124. the same file.
  125. Make the new window N high (default is to use half the height
  126. of the current window). Reduces the current window height to
  127. create room (and others, if the 'equalalways' option is set,
  128. 'eadirection' isn't "hor", and one of them is higher than the
  129. current or the new window).
  130. If [file] is given it will be edited in the new window. If it
  131. is not loaded in any buffer, it will be read. Else the new
  132. window will use the already loaded buffer.
  133. Note: CTRL-S does not work on all terminals and might block
  134. further input, use CTRL-Q to get going again.
  135. Also see |++opt| and |+cmd|.
  136. *E242* *E1159*
  137. Be careful when splitting a window in an autocommand, it may
  138. mess up the window layout if this happens while making other
  139. window layout changes.
  140. CTRL-W CTRL-V *CTRL-W_CTRL-V*
  141. CTRL-W v *CTRL-W_v*
  142. :[N]vs[plit] [++opt] [+cmd] [file] *:vs* *:vsplit*
  143. Like |:split|, but split vertically. The windows will be
  144. spread out horizontally if
  145. 1. a width was not specified,
  146. 2. 'equalalways' is set,
  147. 3. 'eadirection' isn't "ver", and
  148. 4. one of the other windows is wider than the current or new
  149. window.
  150. If N was given make the new window N columns wide, if
  151. possible.
  152. Note: In other places CTRL-Q does the same as CTRL-V, but here
  153. it doesn't!
  154. CTRL-W n *CTRL-W_n*
  155. CTRL-W CTRL_N *CTRL-W_CTRL-N*
  156. :[N]new [++opt] [+cmd] *:new*
  157. Create a new window and start editing an empty file in it.
  158. Make new window N high (default is to use half the existing
  159. height). Reduces the current window height to create room (and
  160. others, if the 'equalalways' option is set and 'eadirection'
  161. isn't "hor").
  162. Also see |++opt| and |+cmd|.
  163. If 'fileformats' is not empty, the first format given will be
  164. used for the new buffer. If 'fileformats' is empty, the
  165. 'fileformat' of the current buffer is used. This can be
  166. overridden with the |++opt| argument.
  167. Autocommands are executed in this order:
  168. 1. WinLeave for the current window
  169. 2. WinEnter for the new window
  170. 3. BufLeave for the current buffer
  171. 4. BufEnter for the new buffer
  172. This behaves like a ":split" first, and then an ":enew"
  173. command.
  174. :[N]new [++opt] [+cmd] {file}
  175. :[N]sp[lit] [++opt] [+cmd] {file} *:split_f*
  176. Create a new window and start editing file {file} in it. This
  177. behaves almost like a ":split" first, and then an ":edit"
  178. command, but the alternate file name in the original window is
  179. set to {file}.
  180. If [+cmd] is given, execute the command when the file has been
  181. loaded |+cmd|.
  182. Also see |++opt|.
  183. Make new window N high (default is to use half the existing
  184. height). Reduces the current window height to create room
  185. (and others, if the 'equalalways' option is set).
  186. :[N]vne[w] [++opt] [+cmd] [file] *:vne* *:vnew*
  187. Like |:new|, but split vertically. If 'equalalways' is set
  188. and 'eadirection' isn't "ver" the windows will be spread out
  189. horizontally, unless a width was specified.
  190. :[N]sv[iew] [++opt] [+cmd] [file] *:sv* *:sview* *splitview*
  191. Same as ":split", but set 'readonly' option for this buffer.
  192. :[N]sf[ind] [++opt] [+cmd] {file} *:sf* *:sfi* *:sfind* *splitfind*
  193. Same as ":split", but search for {file} in 'path' like in
  194. |:find|. Doesn't split if {file} is not found.
  195. CTRL-W CTRL-^ *CTRL-W_CTRL-^* *CTRL-W_^*
  196. CTRL-W ^ Split the current window in two and edit the alternate file.
  197. When a count N is given, split the current window and edit
  198. buffer N. Similar to ":sp #" and ":sp #N", but it allows the
  199. other buffer to be unnamed. This command matches the behavior
  200. of |CTRL-^|, except that it splits a window first.
  201. *CTRL-W_:*
  202. CTRL-W : Does the same as typing |:| - enter a command line. Useful in a
  203. terminal window, where all Vim commands must be preceded with
  204. CTRL-W or 'termwinkey'.
  205. Note that the 'splitbelow' and 'splitright' options influence where a new
  206. window will appear.
  207. *E36*
  208. Creating a window will fail if there is not enough room. Every window needs
  209. at least one screen line and column, sometimes more. Options 'winminheight'
  210. and 'winminwidth' are relevant.
  211. *:vert* *:vertical*
  212. :vert[ical] {cmd}
  213. Execute {cmd}. If it contains a command that splits a window,
  214. it will be split vertically. For `vertical wincmd =` windows
  215. will be equalized only vertically.
  216. Doesn't work for |:execute| and |:normal|.
  217. *:hor* *:horizontal*
  218. :hor[izontal] {cmd}
  219. Execute {cmd}. Currently only makes a difference for
  220. `horizontal wincmd =`, which will equalize windows only
  221. horizontally.
  222. :lefta[bove] {cmd} *:lefta* *:leftabove*
  223. :abo[veleft] {cmd} *:abo* *:aboveleft*
  224. Execute {cmd}. If it contains a command that splits a window,
  225. it will be opened left (vertical split) or above (horizontal
  226. split) the current window. Overrules 'splitbelow' and
  227. 'splitright'.
  228. Doesn't work for |:execute| and |:normal|.
  229. :rightb[elow] {cmd} *:rightb* *:rightbelow*
  230. :bel[owright] {cmd} *:bel* *:belowright*
  231. Execute {cmd}. If it contains a command that splits a window,
  232. it will be opened right (vertical split) or below (horizontal
  233. split) the current window. Overrules 'splitbelow' and
  234. 'splitright'.
  235. Doesn't work for |:execute| and |:normal|.
  236. *:topleft* *E442*
  237. :to[pleft] {cmd}
  238. Execute {cmd}. If it contains a command that splits a window,
  239. it will appear at the top and occupy the full width of the Vim
  240. window. When the split is vertical the window appears at the
  241. far left and occupies the full height of the Vim window.
  242. Doesn't work for |:execute| and |:normal|.
  243. *:bo* *:botright*
  244. :bo[tright] {cmd}
  245. Execute {cmd}. If it contains a command that splits a window,
  246. it will appear at the bottom and occupy the full width of the
  247. Vim window. When the split is vertical the window appears at
  248. the far right and occupies the full height of the Vim window.
  249. Doesn't work for |:execute| and |:normal|.
  250. These command modifiers can be combined to make a vertically split window
  251. occupy the full height. Example: >
  252. :vertical topleft split tags
  253. Opens a vertically split, full-height window on the "tags" file at the far
  254. left of the Vim window.
  255. Closing a window
  256. ----------------
  257. :q[uit]
  258. :{count}q[uit] *:count_quit*
  259. CTRL-W q *CTRL-W_q*
  260. CTRL-W CTRL-Q *CTRL-W_CTRL-Q*
  261. Without {count}: Quit the current window. If {count} is
  262. given quit the {count} window.
  263. *edit-window*
  264. When quitting the last edit window (not counting help or
  265. preview windows), exit Vim.
  266. When 'hidden' is set, and there is only one window for the
  267. current buffer, it becomes hidden. When 'hidden' is not set,
  268. and there is only one window for the current buffer, and the
  269. buffer was changed, the command fails.
  270. (Note: CTRL-Q does not work on all terminals).
  271. If [count] is greater than the last window number the last
  272. window will be closed: >
  273. :1quit " quit the first window
  274. :$quit " quit the last window
  275. :9quit " quit the last window
  276. " if there are fewer than 9 windows opened
  277. :-quit " quit the previous window
  278. :+quit " quit the next window
  279. :+2quit " quit the second next window
  280. <
  281. When closing a help window, and this is not the only window,
  282. Vim will try to restore the previous window layout, see
  283. |:helpclose|.
  284. :q[uit]!
  285. :{count}q[uit]!
  286. Without {count}: Quit the current window. If {count} is
  287. given quit the {count} window.
  288. If this was the last window for a buffer, any changes to that
  289. buffer are lost. When quitting the last window (not counting
  290. help windows), exit Vim. The contents of the buffer are lost,
  291. even when 'hidden' is set.
  292. :clo[se][!]
  293. :{count}clo[se][!]
  294. CTRL-W c *CTRL-W_c* *:clo* *:close*
  295. Without {count}: Close the current window. If {count} is
  296. given close the {count} window.
  297. When the 'hidden' option is set, or when the buffer was
  298. changed and the [!] is used, the buffer becomes hidden (unless
  299. there is another window editing it).
  300. When there is only one |edit-window| in the current tab page
  301. and there is another tab page, this closes the current tab
  302. page. |tab-page|.
  303. This command fails when: *E444*
  304. - There is only one window on the screen.
  305. - When 'hidden' is not set, [!] is not used, the buffer has
  306. changes, and there is no other window on this buffer.
  307. Changes to the buffer are not written and won't get lost, so
  308. this is a "safe" command.
  309. CTRL-W CTRL-C *CTRL-W_CTRL-C*
  310. You might have expected that CTRL-W CTRL-C closes the current
  311. window, but that does not work, because the CTRL-C cancels the
  312. command.
  313. *:hide*
  314. :hid[e]
  315. :{count}hid[e]
  316. Without {count}: Quit the current window, unless it is the
  317. last window on the screen.
  318. If {count} is given quit the {count} window.
  319. The buffer becomes hidden (unless there is another window
  320. editing it or 'bufhidden' is "unload", "delete" or "wipe").
  321. If the window is the last one in the current tab page the tab
  322. page is closed. |tab-page|
  323. The value of 'hidden' is irrelevant for this command. Changes
  324. to the buffer are not written and won't get lost, so this is a
  325. "safe" command.
  326. :hid[e] {cmd} Execute {cmd} with 'hidden' is set. The previous value of
  327. 'hidden' is restored after {cmd} has been executed.
  328. Example: >
  329. :hide edit Makefile
  330. < This will edit "Makefile", and hide the current buffer if it
  331. has any changes.
  332. :on[ly][!]
  333. :{count}on[ly][!]
  334. CTRL-W o *CTRL-W_o* *E445*
  335. CTRL-W CTRL-O *CTRL-W_CTRL-O* *:on* *:only*
  336. Make the current window the only one on the screen. All other
  337. windows are closed. For {count} see the `:quit` command
  338. above |:count_quit|.
  339. When the 'hidden' option is set, all buffers in closed windows
  340. become hidden.
  341. When 'hidden' is not set, and the 'autowrite' option is set,
  342. modified buffers are written. Otherwise, windows that have
  343. buffers that are modified are not removed, unless the [!] is
  344. given, then they become hidden. But modified buffers are
  345. never abandoned, so changes cannot get lost.
  346. ==============================================================================
  347. 4. Moving cursor to other windows *window-move-cursor*
  348. CTRL-W <Down> *CTRL-W_<Down>*
  349. CTRL-W CTRL-J *CTRL-W_CTRL-J* *CTRL-W_j*
  350. CTRL-W j Move cursor to Nth window below current one. Uses the cursor
  351. position to select between alternatives.
  352. CTRL-W <Up> *CTRL-W_<Up>*
  353. CTRL-W CTRL-K *CTRL-W_CTRL-K* *CTRL-W_k*
  354. CTRL-W k Move cursor to Nth window above current one. Uses the cursor
  355. position to select between alternatives.
  356. CTRL-W <Left> *CTRL-W_<Left>*
  357. CTRL-W CTRL-H *CTRL-W_CTRL-H*
  358. CTRL-W <BS> *CTRL-W_<BS>* *CTRL-W_h*
  359. CTRL-W h Move cursor to Nth window left of current one. Uses the
  360. cursor position to select between alternatives.
  361. CTRL-W <Right> *CTRL-W_<Right>*
  362. CTRL-W CTRL-L *CTRL-W_CTRL-L* *CTRL-W_l*
  363. CTRL-W l Move cursor to Nth window right of current one. Uses the
  364. cursor position to select between alternatives.
  365. CTRL-W w *CTRL-W_w* *CTRL-W_CTRL-W*
  366. CTRL-W CTRL-W Without count: move cursor to window below/right of the
  367. current one. If there is no window below or right, go to
  368. top-left window.
  369. With count: go to Nth window (windows are numbered from
  370. top-left to bottom-right). To obtain the window number see
  371. |bufwinnr()| and |winnr()|. When N is larger than the number
  372. of windows go to the last window.
  373. *CTRL-W_W*
  374. CTRL-W W Without count: move cursor to window above/left of current
  375. one. If there is no window above or left, go to bottom-right
  376. window. With count: go to Nth window, like with CTRL-W w.
  377. CTRL-W t *CTRL-W_t* *CTRL-W_CTRL-T*
  378. CTRL-W CTRL-T Move cursor to top-left window.
  379. CTRL-W b *CTRL-W_b* *CTRL-W_CTRL-B*
  380. CTRL-W CTRL-B Move cursor to bottom-right window.
  381. CTRL-W p *CTRL-W_p* *CTRL-W_CTRL-P*
  382. CTRL-W CTRL-P Go to previous (last accessed) window.
  383. *CTRL-W_P* *E441*
  384. CTRL-W P Go to preview window. When there is no preview window this is
  385. an error.
  386. {not available when compiled without the |+quickfix| feature}
  387. If Visual mode is active and the new window is not for the same buffer, the
  388. Visual mode is ended. If the window is on the same buffer, the cursor
  389. position is set to keep the same Visual area selected.
  390. *:winc* *:wincmd*
  391. These commands can also be executed with ":wincmd":
  392. :[count]winc[md] {arg}
  393. Like executing CTRL-W [count] {arg}. Example: >
  394. :wincmd j
  395. < Moves to the window below the current one.
  396. This command is useful when a Normal mode cannot be used (for
  397. the |CursorHold| autocommand event). Or when a Normal mode
  398. command is inconvenient.
  399. The count can also be a window number. Example: >
  400. :exe nr .. "wincmd w"
  401. < This goes to window "nr".
  402. ==============================================================================
  403. 5. Moving windows around *window-moving*
  404. CTRL-W r *CTRL-W_r* *CTRL-W_CTRL-R* *E443*
  405. CTRL-W CTRL-R Rotate windows downwards/rightwards. The first window becomes
  406. the second one, the second one becomes the third one, etc.
  407. The last window becomes the first window. The cursor remains
  408. in the same window.
  409. This only works within the row or column of windows that the
  410. current window is in.
  411. *CTRL-W_R*
  412. CTRL-W R Rotate windows upwards/leftwards. The second window becomes
  413. the first one, the third one becomes the second one, etc. The
  414. first window becomes the last window. The cursor remains in
  415. the same window.
  416. This only works within the row or column of windows that the
  417. current window is in.
  418. CTRL-W x *CTRL-W_x* *CTRL-W_CTRL-X*
  419. CTRL-W CTRL-X Without count: Exchange current window with next one. If there
  420. is no next window, exchange with previous window.
  421. With count: Exchange current window with Nth window (first
  422. window is 1). The cursor is put in the other window.
  423. When vertical and horizontal window splits are mixed, the
  424. exchange is only done in the row or column of windows that the
  425. current window is in.
  426. The following commands can be used to change the window layout. For example,
  427. when there are two vertically split windows, CTRL-W K will change that in
  428. horizontally split windows. CTRL-W H does it the other way around.
  429. *CTRL-W_K*
  430. CTRL-W K Move the current window to be at the very top, using the full
  431. width of the screen. This works like closing the current
  432. window and then creating another one with ":topleft split",
  433. except that the current window contents is used for the new
  434. window.
  435. *CTRL-W_J*
  436. CTRL-W J Move the current window to be at the very bottom, using the
  437. full width of the screen. This works like closing the current
  438. window and then creating another one with ":botright split",
  439. except that the current window contents is used for the new
  440. window.
  441. *CTRL-W_H*
  442. CTRL-W H Move the current window to be at the far left, using the
  443. full height of the screen. This works like closing the
  444. current window and then creating another one with
  445. `:vert topleft split`, except that the current window contents
  446. is used for the new window.
  447. *CTRL-W_L*
  448. CTRL-W L Move the current window to be at the far right, using the full
  449. height of the screen. This works like closing the
  450. current window and then creating another one with
  451. `:vert botright split`, except that the current window
  452. contents is used for the new window.
  453. *CTRL-W_T*
  454. CTRL-W T Move the current window to a new tab page. This fails if
  455. there is only one window in the current tab page.
  456. When a count is specified the new tab page will be opened
  457. before the tab page with this index. Otherwise it comes after
  458. the current tab page.
  459. ==============================================================================
  460. 6. Window resizing *window-resize*
  461. *CTRL-W_=*
  462. CTRL-W = Make all windows (almost) equally high and wide, but use
  463. 'winheight' and 'winwidth' for the current window.
  464. Windows with 'winfixheight' set keep their height and windows
  465. with 'winfixwidth' set keep their width.
  466. To equalize only vertically (make window equally high) use
  467. `vertical wincmd =`.
  468. To equalize only horizontally (make window equally wide) use
  469. `horizontal wincmd =`.
  470. :res[ize] -N *:res* *:resize* *CTRL-W_-*
  471. CTRL-W - Decrease current window height by N (default 1).
  472. If used after |:vertical|: decrease width by N.
  473. :res[ize] +N *CTRL-W_+*
  474. CTRL-W + Increase current window height by N (default 1).
  475. If used after |:vertical|: increase width by N.
  476. :res[ize] [N]
  477. CTRL-W CTRL-_ *CTRL-W_CTRL-_* *CTRL-W__*
  478. CTRL-W _ Set current window height to N (default: highest possible).
  479. :{winnr}res[ize] [+-]N
  480. Like `:resize` above, but apply the size to window {winnr}
  481. instead of the current window.
  482. z{nr}<CR> Set current window height to {nr}.
  483. *CTRL-W_<*
  484. CTRL-W < Decrease current window width by N (default 1).
  485. *CTRL-W_>*
  486. CTRL-W > Increase current window width by N (default 1).
  487. :vert[ical] res[ize] [N] *:vertical-resize* *CTRL-W_bar*
  488. CTRL-W | Set current window width to N (default: widest possible).
  489. You can also resize a window by dragging a status line up or down with the
  490. mouse. Or by dragging a vertical separator line left or right. This only
  491. works if the version of Vim that is being used supports the mouse and the
  492. 'mouse' option has been set to enable it.
  493. The option 'winheight' ('wh') is used to set the minimal window height of the
  494. current window. This option is used each time another window becomes the
  495. current window. If the option is '0', it is disabled. Set 'winheight' to a
  496. very large value, e.g., '9999', to make the current window always fill all
  497. available space. Set it to a reasonable value, e.g., '10', to make editing in
  498. the current window comfortable.
  499. The equivalent 'winwidth' ('wiw') option is used to set the minimal width of
  500. the current window.
  501. When the option 'equalalways' ('ea') is set, all the windows are automatically
  502. made the same size after splitting or closing a window. If you don't set this
  503. option, splitting a window will reduce the size of the current window and
  504. leave the other windows the same. When closing a window, the extra lines are
  505. given to the window above it.
  506. The 'eadirection' option limits the direction in which the 'equalalways'
  507. option is applied. The default "both" resizes in both directions. When the
  508. value is "ver" only the heights of windows are equalized. Use this when you
  509. have manually resized a vertically split window and want to keep this width.
  510. Likewise, "hor" causes only the widths of windows to be equalized.
  511. The option 'cmdheight' ('ch') is used to set the height of the command-line.
  512. If you are annoyed by the |hit-enter| prompt for long messages, set this
  513. option to 2 or 3.
  514. If there is only one window, resizing that window will also change the command
  515. line height. If there are several windows, resizing the current window will
  516. also change the height of the window below it (and sometimes the window above
  517. it).
  518. The minimal height and width of a window is set with 'winminheight' and
  519. 'winminwidth'. These are hard values, a window will never become smaller.
  520. WinScrolled and WinResized autocommands ~
  521. *win-scrolled-resized*
  522. If you want to get notified of changes in window sizes, the |WinResized|
  523. autocommand event can be used.
  524. If you want to get notified of text in windows scrolling vertically or
  525. horizontally, the |WinScrolled| autocommand event can be used. This will also
  526. trigger in window size changes.
  527. Exception: the events will not be triggered when the text scrolls for
  528. 'incsearch'.
  529. *WinResized-event*
  530. The |WinResized| event is triggered after updating the display, several
  531. windows may have changed size then. A list of the IDs of windows that changed
  532. since last time is provided in the v:event.windows variable, for example:
  533. [1003, 1006]
  534. *WinScrolled-event*
  535. The |WinScrolled| event is triggered after |WinResized|, and also if a window
  536. was scrolled. That can be vertically (the text at the top of the window
  537. changed) or horizontally (when 'wrap' is off or when the first displayed part
  538. of the first line changes). Note that |WinScrolled| will trigger many more
  539. times than |WinResized|, it may slow down editing a bit.
  540. The information provided by |WinScrolled| is a dictionary for each window that
  541. has changes, using the window ID as the key, and a total count of the changes
  542. with the key "all". Example value for |v:event| (|Vim9| syntax):
  543. {
  544. all: {width: 0, height: 2, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},
  545. 1003: {width: 0, height: -1, leftcol: 0, skipcol: 0, topline: 0, topfill: 0},
  546. 1006: {width: 0, height: 1, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},
  547. }
  548. Note that the "all" entry has the absolute values of the individual windows
  549. accumulated.
  550. If you need more information about what changed, or you want to "debounce" the
  551. events (not handle every event to avoid doing too much work), you may want to
  552. use the `winlayout()` and `getwininfo()` functions.
  553. |WinScrolled| and |WinResized| do not trigger when the first autocommand is
  554. added, only after the first scroll or resize. They may trigger when switching
  555. to another tab page.
  556. The commands executed are expected to not cause window size or scroll changes.
  557. If this happens anyway, the event will trigger again very soon. In other
  558. words: Just before triggering the event, the current sizes and scroll
  559. positions are stored and used to decide whether there was a change.
  560. *E1312*
  561. It is not allowed to change the window layout here (split, close or move
  562. windows).
  563. ==============================================================================
  564. 7. Argument and buffer list commands *buffer-list*
  565. args list buffer list meaning ~
  566. 1. :[N]argument [N] 11. :[N]buffer [N] to arg/buf N
  567. 2. :[N]next [file ..] 12. :[N]bnext [N] to Nth next arg/buf
  568. 3. :[N]Next [N] 13. :[N]bNext [N] to Nth previous arg/buf
  569. 4. :[N]previous [N] 14. :[N]bprevious [N] to Nth previous arg/buf
  570. 5. :rewind / :first 15. :brewind / :bfirst to first arg/buf
  571. 6. :last 16. :blast to last arg/buf
  572. 7. :all 17. :ball edit all args/buffers
  573. 18. :unhide edit all loaded buffers
  574. 19. :[N]bmod [N] to Nth modified buf
  575. split & args list split & buffer list meaning ~
  576. 21. :[N]sargument [N] 31. :[N]sbuffer [N] split + to arg/buf N
  577. 22. :[N]snext [file ..] 32. :[N]sbnext [N] split + to Nth next arg/buf
  578. 23. :[N]sNext [N] 33. :[N]sbNext [N] split + to Nth previous arg/buf
  579. 24. :[N]sprevious [N] 34. :[N]sbprevious [N] split + to Nth previous arg/buf
  580. 25. :srewind / :sfirst 35. :sbrewind / :sbfirst split + to first arg/buf
  581. 26. :slast 36. :sblast split + to last arg/buf
  582. 27. :sall 37. :sball edit all args/buffers
  583. 38. :sunhide edit all loaded buffers
  584. 39. :[N]sbmod [N] split + to Nth modified buf
  585. 40. :args list of arguments
  586. 41. :buffers list of buffers
  587. The meaning of [N] depends on the command:
  588. [N] is the number of buffers to go forward/backward on 2/12/22/32,
  589. 3/13/23/33, and 4/14/24/34
  590. [N] is an argument number, defaulting to current argument, for 1 and 21
  591. [N] is a buffer number, defaulting to current buffer, for 11 and 31
  592. [N] is a count for 19 and 39
  593. Note: ":next" is an exception, because it must accept a list of file names
  594. for compatibility with Vi.
  595. The argument list and multiple windows
  596. --------------------------------------
  597. The current position in the argument list can be different for each window.
  598. Remember that when doing ":e file", the position in the argument list stays
  599. the same, but you are not editing the file at that position. To indicate
  600. this, the file message (and the title, if you have one) shows
  601. "(file (N) of M)", where "(N)" is the current position in the file list, and
  602. "M" the number of files in the file list.
  603. All the entries in the argument list are added to the buffer list. Thus, you
  604. can also get to them with the buffer list commands, like ":bnext".
  605. :[N]al[l][!] [N] *:al* *:all* *:sal* *:sall*
  606. :[N]sal[l][!] [N]
  607. Rearrange the screen to open one window for each argument.
  608. All other windows are closed. When a count is given, this is
  609. the maximum number of windows to open.
  610. With the |:tab| modifier open a tab page for each argument.
  611. When there are more arguments than 'tabpagemax' further ones
  612. become split windows in the last tab page.
  613. When the 'hidden' option is set, all buffers in closed windows
  614. become hidden.
  615. When 'hidden' is not set, and the 'autowrite' option is set,
  616. modified buffers are written. Otherwise, windows that have
  617. buffers that are modified are not removed, unless the [!] is
  618. given, then they become hidden. But modified buffers are
  619. never abandoned, so changes cannot get lost.
  620. [N] is the maximum number of windows to open. 'winheight'
  621. also limits the number of windows opened ('winwidth' if
  622. |:vertical| was prepended).
  623. Buf/Win Enter/Leave autocommands are not executed for the new
  624. windows here, that's only done when they are really entered.
  625. If autocommands change the window layout while this command is
  626. busy an error will be given. *E249*
  627. :[N]sa[rgument][!] [++opt] [+cmd] [N] *:sa* *:sargument*
  628. Short for ":split | argument [N]": split window and go to Nth
  629. argument. But when there is no such argument, the window is
  630. not split. Also see |++opt| and |+cmd|.
  631. :[N]sn[ext][!] [++opt] [+cmd] [file ..] *:sn* *:snext*
  632. Short for ":split | [N]next": split window and go to Nth next
  633. argument. But when there is no next file, the window is not
  634. split. Also see |++opt| and |+cmd|.
  635. :[N]spr[evious][!] [++opt] [+cmd] [N] *:spr* *:sprevious*
  636. :[N]sN[ext][!] [++opt] [+cmd] [N] *:sN* *:sNext*
  637. Short for ":split | [N]Next": split window and go to Nth
  638. previous argument. But when there is no previous file, the
  639. window is not split. Also see |++opt| and |+cmd|.
  640. *:sre* *:srewind*
  641. :sre[wind][!] [++opt] [+cmd]
  642. Short for ":split | rewind": split window and go to first
  643. argument. But when there is no argument list, the window is
  644. not split. Also see |++opt| and |+cmd|.
  645. *:sfir* *:sfirst*
  646. :sfir[st] [++opt] [+cmd]
  647. Same as ":srewind".
  648. *:sla* *:slast*
  649. :sla[st][!] [++opt] [+cmd]
  650. Short for ":split | last": split window and go to last
  651. argument. But when there is no argument list, the window is
  652. not split. Also see |++opt| and |+cmd|.
  653. *:dr* *:drop*
  654. :dr[op] [++opt] [+cmd] {file} ..
  655. Edit the first {file} in a window.
  656. - If the file is already open in a window change to that
  657. window.
  658. - If the file is not open in a window edit the file in the
  659. current window. If the current buffer can't be |abandon|ed,
  660. the window is split first.
  661. - Windows that are not in the argument list or are not full
  662. width will be closed if possible.
  663. The |argument-list| is set, like with the |:next| command.
  664. The purpose of this command is that it can be used from a
  665. program that wants Vim to edit another file, e.g., a debugger.
  666. When using the |:tab| modifier each argument is opened in a
  667. tab page. The last window is used if it's empty.
  668. Also see |++opt| and |+cmd|.
  669. ==============================================================================
  670. 8. Do a command in all buffers or windows *list-repeat*
  671. *:windo*
  672. :[range]windo {cmd} Execute {cmd} in each window or if [range] is given
  673. only in windows for which the window number lies in
  674. the [range]. It works like doing this: >
  675. CTRL-W t
  676. :{cmd}
  677. CTRL-W w
  678. :{cmd}
  679. etc.
  680. < This only operates in the current tab page.
  681. When an error is detected on one window, further
  682. windows will not be visited.
  683. The last window (or where an error occurred) becomes
  684. the current window.
  685. {cmd} can contain '|' to concatenate several commands.
  686. {cmd} must not open or close windows or reorder them.
  687. Also see |:tabdo|, |:argdo|, |:bufdo|, |:cdo|, |:ldo|,
  688. |:cfdo| and |:lfdo|
  689. *:bufdo*
  690. :[range]bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list or if
  691. [range] is given only for buffers for which their
  692. buffer number is in the [range]. It works like doing
  693. this: >
  694. :bfirst
  695. :{cmd}
  696. :bnext
  697. :{cmd}
  698. etc.
  699. < When the current file can't be |abandon|ed and the [!]
  700. is not present, the command fails.
  701. When an error is detected on one buffer, further
  702. buffers will not be visited.
  703. Unlisted buffers are skipped.
  704. The last buffer (or where an error occurred) becomes
  705. the current buffer.
  706. {cmd} can contain '|' to concatenate several commands.
  707. {cmd} must not delete buffers or add buffers to the
  708. buffer list.
  709. Note: While this command is executing, the Syntax
  710. autocommand event is disabled by adding it to
  711. 'eventignore'. This considerably speeds up editing
  712. each buffer.
  713. Also see |:tabdo|, |:argdo|, |:windo|, |:cdo|, |:ldo|,
  714. |:cfdo| and |:lfdo|
  715. Examples: >
  716. :windo set nolist foldcolumn=0 | normal! zn
  717. This resets the 'list' option and disables folding in all windows. >
  718. :bufdo set fileencoding= | update
  719. This resets the 'fileencoding' in each buffer and writes it if this changed
  720. the buffer. The result is that all buffers will use the 'encoding' encoding
  721. (if conversion succeeds).
  722. ==============================================================================
  723. 9. Tag or file name under the cursor *window-tag*
  724. *:sta* *:stag*
  725. :sta[g][!] [tagname]
  726. Does ":tag[!] [tagname]" and splits the window for the found
  727. tag. See also |:tag|.
  728. CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]*
  729. CTRL-W CTRL-] Split current window in two. Use identifier under cursor as a
  730. tag and jump to it in the new upper window.
  731. In Visual mode uses the Visually selected text as a tag.
  732. Make new window N high.
  733. *CTRL-W_g]*
  734. CTRL-W g ] Split current window in two. Use identifier under cursor as a
  735. tag and perform ":tselect" on it in the new upper window.
  736. In Visual mode uses the Visually selected text as a tag.
  737. Make new window N high.
  738. *CTRL-W_g_CTRL-]*
  739. CTRL-W g CTRL-] Split current window in two. Use identifier under cursor as a
  740. tag and perform ":tjump" on it in the new upper window.
  741. In Visual mode uses the Visually selected text as a tag.
  742. Make new window N high.
  743. CTRL-W f *CTRL-W_f* *CTRL-W_CTRL-F*
  744. CTRL-W CTRL-F Split current window in two. Edit file name under cursor.
  745. Like ":split gf", but window isn't split if the file does not
  746. exist.
  747. Uses the 'path' variable as a list of directory names where to
  748. look for the file. Also the path for current file is
  749. used to search for the file name.
  750. If the name is a hypertext link that looks like
  751. "type://machine/path", only "/path" is used.
  752. If a count is given, the count'th matching file is edited.
  753. CTRL-W F *CTRL-W_F*
  754. Split current window in two. Edit file name under cursor and
  755. jump to the line number following the file name. See |gF| for
  756. details on how the line number is obtained.
  757. CTRL-W gf *CTRL-W_gf*
  758. Open a new tab page and edit the file name under the cursor.
  759. Like "tab split" and "gf", but the new tab page isn't created
  760. if the file does not exist.
  761. CTRL-W gF *CTRL-W_gF*
  762. Open a new tab page and edit the file name under the cursor
  763. and jump to the line number following the file name. Like
  764. "tab split" and "gF", but the new tab page isn't created if
  765. the file does not exist.
  766. CTRL-W gt *CTRL-W_gt*
  767. Go to next tab page, same as `gt`.
  768. CTRL-W gT *CTRL-W_gT*
  769. Go to previous tab page, same as `gT`.
  770. Also see |CTRL-W_CTRL-I|: open window for an included file that includes
  771. the keyword under the cursor.
  772. ==============================================================================
  773. 10. The preview window *preview-window*
  774. The preview window is a special window to show (preview) another file. It is
  775. normally a small window used to show an include file or definition of a
  776. function.
  777. {not available when compiled without the |+quickfix| feature}
  778. There can be only one preview window (per tab page). It is created with one
  779. of the commands below. The 'previewheight' option can be set to specify the
  780. height of the preview window when it's opened. The 'previewwindow' option is
  781. set in the preview window to be able to recognize it. The 'winfixheight'
  782. option is set to have it keep the same height when opening/closing other
  783. windows.
  784. *preview-popup*
  785. Alternatively, a popup window can be used by setting the 'previewpopup'
  786. option. When set, it overrules the 'previewwindow' and 'previewheight'
  787. settings. The option is a comma-separated list of values:
  788. height maximum height of the popup
  789. width maximum width of the popup
  790. highlight highlight group of the popup (default is Pmenu)
  791. Example: >
  792. :set previewpopup=height:10,width:60
  793. A few peculiarities:
  794. - If the file is in a buffer already, it will be re-used. This will allow for
  795. editing the file while it's visible in the popup window.
  796. - No ATTENTION dialog will be used, since you can't edit the file in the popup
  797. window. However, if you later open the same buffer in a normal window, you
  798. may not notice it's edited elsewhere. And when then using ":edit" to
  799. trigger the ATTENTION and responding "A" for Abort, the preview window will
  800. become empty.
  801. *:pta* *:ptag*
  802. :pta[g][!] [tagname]
  803. Does ":tag[!] [tagname]" and shows the found tag in a
  804. "Preview" window without changing the current buffer or cursor
  805. position. If a "Preview" window already exists, it is re-used
  806. (like a help window is). If a new one is opened,
  807. 'previewheight' is used for the height of the window. See
  808. also |:tag|.
  809. See below for an example. |CursorHold-example|
  810. Small difference from |:tag|: When [tagname] is equal to the
  811. already displayed tag, the position in the matching tag list
  812. is not reset. This makes the CursorHold example work after a
  813. |:ptnext|.
  814. CTRL-W z *CTRL-W_z*
  815. CTRL-W CTRL-Z *CTRL-W_CTRL-Z* *:pc* *:pclose*
  816. :pc[lose][!] Close any "Preview" window currently open. When the 'hidden'
  817. option is set, or when the buffer was changed and the [!] is
  818. used, the buffer becomes hidden (unless there is another
  819. window editing it). The command fails if any "Preview" buffer
  820. cannot be closed. See also |:close|.
  821. *:pp* *:ppop*
  822. :[count]pp[op][!]
  823. Does ":[count]pop[!]" in the preview window. See |:pop| and
  824. |:ptag|.
  825. CTRL-W } *CTRL-W_}*
  826. Use identifier under cursor as a tag and perform a :ptag on
  827. it. Make the new Preview window (if required) N high. If N is
  828. not given, 'previewheight' is used.
  829. CTRL-W g } *CTRL-W_g}*
  830. Use identifier under cursor as a tag and perform a :ptjump on
  831. it. Make the new Preview window (if required) N high. If N is
  832. not given, 'previewheight' is used.
  833. *:ped* *:pedit*
  834. :ped[it][!] [++opt] [+cmd] {file}
  835. Edit {file} in the preview window. The preview window is
  836. opened like with |:ptag|. The current window and cursor
  837. position isn't changed. Useful example: >
  838. :pedit +/fputc /usr/include/stdio.h
  839. <
  840. *:ps* *:psearch*
  841. :[range]ps[earch][!] [count] [/]pattern[/]
  842. Works like |:ijump| but shows the found match in the preview
  843. window. The preview window is opened like with |:ptag|. The
  844. current window and cursor position isn't changed. Useful
  845. example: >
  846. :psearch popen
  847. < Like with the |:ptag| command, you can use this to
  848. automatically show information about the word under the
  849. cursor. This is less clever than using |:ptag|, but you don't
  850. need a tags file and it will also find matches in system
  851. include files. Example: >
  852. :au! CursorHold *.[ch] ++nested exe "silent! psearch " .. expand("<cword>")
  853. < Warning: This can be slow.
  854. Example *CursorHold-example* >
  855. :au! CursorHold *.[ch] ++nested exe "silent! ptag " .. expand("<cword>")
  856. This will cause a ":ptag" to be executed for the keyword under the cursor,
  857. when the cursor hasn't moved for the time set with 'updatetime'. The "nested"
  858. makes other autocommands be executed, so that syntax highlighting works in the
  859. preview window. The "silent!" avoids an error message when the tag could not
  860. be found. Also see |CursorHold|. To disable this again: >
  861. :au! CursorHold
  862. A nice addition is to highlight the found tag, avoid the ":ptag" when there
  863. is no word under the cursor, and a few other things: >
  864. :au! CursorHold *.[ch] ++nested call PreviewWord()
  865. :func PreviewWord()
  866. : if &previewwindow " don't do this in the preview window
  867. : return
  868. : endif
  869. : let w = expand("<cword>") " get the word under cursor
  870. : if w =~ '\a' " if the word contains a letter
  871. :
  872. : " Delete any existing highlight before showing another tag
  873. : silent! wincmd P " jump to preview window
  874. : if &previewwindow " if we really get there...
  875. : match none " delete existing highlight
  876. : wincmd p " back to old window
  877. : endif
  878. :
  879. : " Try displaying a matching tag for the word under the cursor
  880. : try
  881. : exe "ptag " .. w
  882. : catch
  883. : return
  884. : endtry
  885. :
  886. : silent! wincmd P " jump to preview window
  887. : if &previewwindow " if we really get there...
  888. : if has("folding")
  889. : silent! .foldopen " don't want a closed fold
  890. : endif
  891. : call search("$", "b") " to end of previous line
  892. : let w = substitute(w, '\\', '\\\\', "")
  893. : call search('\<\V' .. w .. '\>') " position cursor on match
  894. : " Add a match highlight to the word at this position
  895. : hi previewWord term=bold ctermbg=green guibg=green
  896. : exe 'match previewWord "\%' .. line(".") .. 'l\%' .. col(".") .. 'c\k*"'
  897. : wincmd p " back to old window
  898. : endif
  899. : endif
  900. :endfun
  901. ==============================================================================
  902. 11. Using hidden buffers *buffer-hidden*
  903. A hidden buffer is not displayed in a window, but is still loaded into memory.
  904. This makes it possible to jump from file to file, without the need to read or
  905. write the file every time you get another buffer in a window.
  906. *:buffer-!*
  907. If the option 'hidden' ('hid') is set, abandoned buffers are kept for all
  908. commands that start editing another file: ":edit", ":next", ":tag", etc. The
  909. commands that move through the buffer list sometimes make the current buffer
  910. hidden although the 'hidden' option is not set. This happens when a buffer is
  911. modified, but is forced (with '!') to be removed from a window, and
  912. 'autowrite' is off or the buffer can't be written.
  913. You can make a hidden buffer not hidden by starting to edit it with any
  914. command, or by deleting it with the ":bdelete" command.
  915. The 'hidden' is global, it is used for all buffers. The 'bufhidden' option
  916. can be used to make an exception for a specific buffer. It can take these
  917. values:
  918. <empty> Use the value of 'hidden'.
  919. hide Hide this buffer, also when 'hidden' is not set.
  920. unload Don't hide but unload this buffer, also when 'hidden'
  921. is set.
  922. delete Delete the buffer.
  923. *hidden-quit*
  924. When you try to quit Vim while there is a hidden, modified buffer, you will
  925. get an error message and Vim will make that buffer the current buffer. You
  926. can then decide to write this buffer (":wq") or quit without writing (":q!").
  927. Be careful: there may be more hidden, modified buffers!
  928. A buffer can also be unlisted. This means it exists, but it is not in the
  929. list of buffers. |unlisted-buffer|
  930. :files[!] [flags] *:files*
  931. :buffers[!] [flags] *:buffers* *:ls*
  932. :ls[!] [flags]
  933. Show all buffers. Example:
  934. 1 #h "/test/text" line 1 ~
  935. 2u "asdf" line 0 ~
  936. 3 %a + "version.c" line 1 ~
  937. When the [!] is included the list will show unlisted buffers
  938. (the term "unlisted" is a bit confusing then...).
  939. Each buffer has a unique number. That number will not change,
  940. thus you can always go to a specific buffer with ":buffer N"
  941. or "N CTRL-^", where N is the buffer number.
  942. For the file name these special values are used:
  943. [Prompt] |prompt-buffer|
  944. [Popup] buffer of a |popup-window|
  945. [Scratch] 'buftype' is "nofile"
  946. [No Name] no file name specified
  947. For a |terminal-window| buffer the status is used.
  948. Indicators (chars in the same column are mutually exclusive):
  949. u an unlisted buffer (only displayed when [!] is used)
  950. |unlisted-buffer|
  951. % the buffer in the current window
  952. # the alternate buffer for ":e #" and CTRL-^
  953. a an active buffer: it is loaded and visible
  954. h a hidden buffer: It is loaded, but currently not
  955. displayed in a window |hidden-buffer|
  956. - a buffer with 'modifiable' off
  957. = a readonly buffer
  958. R a terminal buffer with a running job
  959. F a terminal buffer with a finished job
  960. ? a terminal buffer without a job: `:terminal NONE`
  961. + a modified buffer
  962. x a buffer with read errors
  963. [flags] can be a combination of the following characters,
  964. which restrict the buffers to be listed:
  965. + modified buffers
  966. - buffers with 'modifiable' off
  967. = readonly buffers
  968. a active buffers
  969. u unlisted buffers (overrides the "!")
  970. h hidden buffers
  971. x buffers with a read error
  972. % current buffer
  973. # alternate buffer
  974. R terminal buffers with a running job
  975. F terminal buffers with a finished job
  976. ? terminal buffers without a job: `:terminal NONE`
  977. t show time last used and sort buffers
  978. Combining flags means they are "and"ed together, e.g.:
  979. h+ hidden buffers which are modified
  980. a+ active buffers which are modified
  981. When using |:filter| the pattern is matched against the
  982. displayed buffer name, e.g.: >
  983. filter /\.vim/ ls
  984. <
  985. *:bad* *:badd*
  986. :bad[d] [+lnum] {fname}
  987. Add file name {fname} to the buffer list, without loading it,
  988. if it wasn't listed yet. If the buffer was previously
  989. deleted, not wiped, it will be made listed again.
  990. If "lnum" is specified, the cursor will be positioned at that
  991. line when the buffer is first entered. Note that other
  992. commands after the + will be ignored.
  993. *:balt*
  994. :balt [+lnum] {fname}
  995. Like `:badd` and also set the alternate file for the current
  996. window to {fname}.
  997. :[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516*
  998. :bd[elete][!] [N]
  999. Unload buffer [N] (default: current buffer) and delete it from
  1000. the buffer list. If the buffer was changed, this fails,
  1001. unless when [!] is specified, in which case changes are lost.
  1002. The file remains unaffected. Any windows for this buffer are
  1003. closed. If buffer [N] is the current buffer, another buffer
  1004. will be displayed instead. This is the most recent entry in
  1005. the jump list that points into a loaded buffer.
  1006. Actually, the buffer isn't completely deleted, it is removed
  1007. from the buffer list |unlisted-buffer| and option values,
  1008. variables and mappings/abbreviations for the buffer are
  1009. cleared. Examples: >
  1010. :.,$-bdelete " delete buffers from the current one to
  1011. " last but one
  1012. :%bdelete " delete all buffers
  1013. <
  1014. :bdelete[!] {bufname} *E93* *E94*
  1015. Like ":bdelete[!] [N]", but buffer given by name, see
  1016. |{bufname}|.
  1017. :bdelete[!] N1 N2 ...
  1018. Do ":bdelete[!]" for buffer N1, N2, etc. The arguments can be
  1019. buffer numbers or buffer names (but not buffer names that are
  1020. a number). Insert a backslash before a space in a buffer
  1021. name.
  1022. :N,Mbdelete[!] Do ":bdelete[!]" for all buffers in the range N to M
  1023. |inclusive|.
  1024. :[N]bw[ipeout][!] *:bw* *:bwipe* *:bwipeout* *E517*
  1025. :bw[ipeout][!] {bufname}
  1026. :N,Mbw[ipeout][!]
  1027. :bw[ipeout][!] N1 N2 ...
  1028. Like |:bdelete|, but really delete the buffer. Everything
  1029. related to the buffer is lost. All marks in this buffer
  1030. become invalid, option settings are lost, etc. Don't use this
  1031. unless you know what you are doing. Examples: >
  1032. :.+,$bwipeout " wipe out all buffers after the current
  1033. " one
  1034. :%bwipeout " wipe out all buffers
  1035. <
  1036. :[N]bun[load][!] *:bun* *:bunload* *E515*
  1037. :bun[load][!] [N]
  1038. Unload buffer [N] (default: current buffer). The memory
  1039. allocated for this buffer will be freed. The buffer remains
  1040. in the buffer list.
  1041. If the buffer was changed, this fails, unless when [!] is
  1042. specified, in which case the changes are lost.
  1043. Any windows for this buffer are closed. If buffer [N] is the
  1044. current buffer, another buffer will be displayed instead.
  1045. This is the most recent entry in the jump list that points
  1046. into a loaded buffer.
  1047. :bunload[!] {bufname}
  1048. Like ":bunload[!] [N]", but buffer given by name.
  1049. Also see |{bufname}|.
  1050. :N,Mbunload[!] Do ":bunload[!]" for all buffers in the range N to M
  1051. |inclusive|.
  1052. :bunload[!] N1 N2 ...
  1053. Do ":bunload[!]" for buffer N1, N2, etc. The arguments can be
  1054. buffer numbers or buffer names (but not buffer names that are
  1055. a number). Insert a backslash before a space in a buffer
  1056. name.
  1057. :[N]b[uffer][!] [+cmd] [N] *:b* *:bu* *:buf* *:buffer* *E86*
  1058. Edit buffer [N] from the buffer list. If [N] is not given,
  1059. the current buffer remains being edited. See |:buffer-!| for
  1060. [!]. This will also edit a buffer that is not in the buffer
  1061. list, without setting the 'buflisted' flag.
  1062. The notation with single quotes does not work here,
  1063. `:buf 12'345'` uses 12'345 as a buffer name.
  1064. Also see |+cmd|.
  1065. :[N]b[uffer][!] [+cmd] {bufname} *{bufname}*
  1066. Edit buffer for {bufname} from the buffer list. A partial
  1067. name also works, so long as it is unique in the list of
  1068. buffers.
  1069. Note that a buffer whose name is a number cannot be referenced
  1070. by that name; use the buffer number instead.
  1071. Insert a backslash before a space in a buffer name.
  1072. See |:buffer-!| for [!].
  1073. This will also edit a buffer that is not in the buffer list,
  1074. without setting the 'buflisted' flag.
  1075. Also see |+cmd|.
  1076. :[N]sb[uffer] [+cmd] [N] *:sb* *:sbuffer*
  1077. Split window and edit buffer [N] from the buffer list. If [N]
  1078. is not given, the current buffer is edited. Respects the
  1079. "useopen" setting of 'switchbuf' when splitting. This will
  1080. also edit a buffer that is not in the buffer list, without
  1081. setting the 'buflisted' flag.
  1082. Also see |+cmd|.
  1083. :[N]sb[uffer] [+cmd] {bufname}
  1084. Split window and edit buffer for |{bufname}| from the buffer
  1085. list. This will also edit a buffer that is not in the buffer
  1086. list, without setting the 'buflisted' flag.
  1087. Note: If what you want to do is split the buffer, make a copy
  1088. under another name, you can do it this way: >
  1089. :w foobar | sp #
  1090. < Also see |+cmd|.
  1091. :[N]bn[ext][!] [+cmd] [N] *:bn* *:bnext* *E87*
  1092. Go to [N]th next buffer in buffer list. [N] defaults to one.
  1093. Wraps around the end of the buffer list.
  1094. See |:buffer-!| for [!].
  1095. Also see |+cmd|.
  1096. If you are in a help buffer, this takes you to the next help
  1097. buffer (if there is one). Similarly, if you are in a normal
  1098. (non-help) buffer, this takes you to the next normal buffer.
  1099. This is so that if you have invoked help, it doesn't get in
  1100. the way when you're browsing code/text buffers. The next three
  1101. commands also work like this.
  1102. *:sbn* *:sbnext*
  1103. :[N]sbn[ext] [+cmd] [N]
  1104. Split window and go to [N]th next buffer in buffer list.
  1105. Wraps around the end of the buffer list. Uses 'switchbuf'
  1106. Also see |+cmd|.
  1107. :[N]bN[ext][!] [+cmd] [N] *:bN* *:bNext* *:bp* *:bprevious* *E88*
  1108. :[N]bp[revious][!] [+cmd] [N]
  1109. Go to [N]th previous buffer in buffer list. [N] defaults to
  1110. one. Wraps around the start of the buffer list.
  1111. See |:buffer-!| for [!] and 'switchbuf'.
  1112. Also see |+cmd|.
  1113. :[N]sbN[ext] [+cmd] [N] *:sbN* *:sbNext* *:sbp* *:sbprevious*
  1114. :[N]sbp[revious] [+cmd] [N]
  1115. Split window and go to [N]th previous buffer in buffer list.
  1116. Wraps around the start of the buffer list.
  1117. Uses 'switchbuf'.
  1118. Also see |+cmd|.
  1119. :br[ewind][!] [+cmd] *:br* *:bre* *:brewind*
  1120. Go to first buffer in buffer list. If the buffer list is
  1121. empty, go to the first unlisted buffer.
  1122. See |:buffer-!| for [!].
  1123. :bf[irst] [+cmd] *:bf* *:bfirst*
  1124. Same as |:brewind|.
  1125. Also see |+cmd|.
  1126. :sbr[ewind] [+cmd] *:sbr* *:sbrewind*
  1127. Split window and go to first buffer in buffer list. If the
  1128. buffer list is empty, go to the first unlisted buffer.
  1129. Respects the 'switchbuf' option.
  1130. Also see |+cmd|.
  1131. :sbf[irst] [+cmd] *:sbf* *:sbfirst*
  1132. Same as ":sbrewind".
  1133. :bl[ast][!] [+cmd] *:bl* *:blast*
  1134. Go to last buffer in buffer list. If the buffer list is
  1135. empty, go to the last unlisted buffer.
  1136. See |:buffer-!| for [!].
  1137. :sbl[ast] [+cmd] *:sbl* *:sblast*
  1138. Split window and go to last buffer in buffer list. If the
  1139. buffer list is empty, go to the last unlisted buffer.
  1140. Respects 'switchbuf' option.
  1141. :[N]bm[odified][!] [+cmd] [N] *:bm* *:bmodified* *E84*
  1142. Go to [N]th next modified buffer. Note: this command also
  1143. finds unlisted buffers. If there is no modified buffer the
  1144. command fails.
  1145. :[N]sbm[odified] [+cmd] [N] *:sbm* *:sbmodified*
  1146. Split window and go to [N]th next modified buffer.
  1147. Respects 'switchbuf' option.
  1148. Note: this command also finds buffers not in the buffer list.
  1149. :[N]unh[ide] [N] *:unh* *:unhide* *:sun* *:sunhide*
  1150. :[N]sun[hide] [N]
  1151. Rearrange the screen to open one window for each loaded buffer
  1152. in the buffer list. When a count is given, this is the
  1153. maximum number of windows to open.
  1154. :[N]ba[ll] [N] *:ba* *:ball* *:sba* *:sball*
  1155. :[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in
  1156. the buffer list. When a count is given, this is the maximum
  1157. number of windows to open. 'winheight' also limits the number
  1158. of windows opened ('winwidth' if |:vertical| was prepended).
  1159. Buf/Win Enter/Leave autocommands are not executed for the new
  1160. windows here, that's only done when they are really entered.
  1161. When the |:tab| modifier is used new windows are opened in a
  1162. new tab, up to 'tabpagemax'.
  1163. Note: All the commands above that start editing another buffer, keep the
  1164. 'readonly' flag as it was. This differs from the ":edit" command, which sets
  1165. the 'readonly' flag each time the file is read.
  1166. ==============================================================================
  1167. 12. Special kinds of buffers *special-buffers*
  1168. Instead of containing the text of a file, buffers can also be used for other
  1169. purposes. A few options can be set to change the behavior of a buffer:
  1170. 'bufhidden' what happens when the buffer is no longer displayed
  1171. in a window.
  1172. 'buftype' what kind of a buffer this is
  1173. 'swapfile' whether the buffer will have a swap file
  1174. 'buflisted' buffer shows up in the buffer list
  1175. A few useful kinds of a buffer:
  1176. quickfix Used to contain the error list or the location list. See
  1177. |:cwindow| and |:lwindow|. This command sets the 'buftype'
  1178. option to "quickfix". You are not supposed to change this!
  1179. 'swapfile' is off.
  1180. help Contains a help file. Will only be created with the |:help|
  1181. command. The flag that indicates a help buffer is internal
  1182. and can't be changed. The 'buflisted' option will be reset
  1183. for a help buffer.
  1184. terminal A terminal window buffer, see |terminal|. The contents cannot
  1185. be read or changed until the job ends.
  1186. directory Displays directory contents. Can be used by a file explorer
  1187. plugin. The buffer is created with these settings: >
  1188. :setlocal buftype=nowrite
  1189. :setlocal bufhidden=delete
  1190. :setlocal noswapfile
  1191. < The buffer name is the name of the directory and is adjusted
  1192. when using the |:cd| command.
  1193. *scratch-buffer*
  1194. scratch Contains text that can be discarded at any time. It is kept
  1195. when closing the window, it must be deleted explicitly.
  1196. Settings: >
  1197. :setlocal buftype=nofile
  1198. :setlocal bufhidden=hide
  1199. :setlocal noswapfile
  1200. < The buffer name can be used to identify the buffer, if you
  1201. give it a meaningful name.
  1202. *unlisted-buffer*
  1203. unlisted The buffer is not in the buffer list. It is not used for
  1204. normal editing, but to show a help file, remember a file name
  1205. or marks. The ":bdelete" command will also set this option,
  1206. thus it doesn't completely delete the buffer. Settings: >
  1207. :setlocal nobuflisted
  1208. <
  1209. vim:tw=78:ts=8:noet:ft=help:norl: