windows.txt 56 KB

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