Movatterモバイル変換


[0]ホーム

URL:


Windows

Nvim:help pages,generated fromsource using thetree-sitter-vimdoc parser.


Editing with multiple windows and buffers.buffers
The commands which have been added to use multiple windows and buffers areexplained here. Additionally, there are explanations for commands that workdifferently when used in combination with more than one window.
The basics are explained in chapter 7 and 8 of the user manualusr_07.txtusr_08.txt.

1. Introductionwindows-introwindow

Summary: A buffer is the in-memory text of a file. A window is a viewport on a buffer. A tab page is a collection of windows.
A window is a viewport onto a buffer. You can use multiple windows on onebuffer, or several windows on different buffers.
A buffer is a file loaded into memory for editing. The original file remainsunchanged until you write the buffer to the file.
A buffer can be in one of three states:
active-buffer
active: The buffer is displayed in a window. If there is a file for this buffer, it has been read into the buffer. The buffer may have been modified since then and thus be different from the file.hidden-buffer
hidden: The buffer is not displayed. If there is a file for this buffer, it has been read into the buffer. Otherwise it's the same as an active buffer, you just can't see it.inactive-buffer
inactive: The buffer is not displayed and does not contain anything. Options for the buffer are remembered if the file was once loaded. It can contain marks from theshada file. But the buffer doesn't contain text.
In a table:
statedisplayedloaded":buffers"
in windowshows
active yes yes 'a'hidden no yes 'h'inactive no no ' '
buffer-reuse
Each buffer has a unique number and the number will not change within a Vimsession. Thebufnr() andbufname() functions can be used to convertbetween a buffer name and the buffer number. There is one exception: if a newempty buffer is created and it is not modified, the buffer will be re-usedwhen loading another file into that buffer. This also means the buffer numberwill not change.
The main Vim window can hold several split windows. There are also tab pagestab-page, each of which can hold multiple windows.
focusable
If a window is focusable, it is part of the "navigation stack", that is,editor commands such as :windo,CTRL-W, etc., will consider the window asone that can be made the "current window". A non-focusable window will beskipped by such commands as it isn't assigned a window number. It can beexplicitly focused bynvim_set_current_win(), because it is stillassigned awindow-ID. If it is focused, it will also have a window number.Non-focusable windows are not listed by:tabs, or counted by the default'tabline'. Their buffer content is not included in'complete' "w" completion.
Windows (especially floating windows) can have many otherapi-win_configproperties such as "hide" and "fixed" which also affect behavior.
window-IDwinidwindowidEach window has a unique identifier called the window ID. This identifierwill not change within a Vim session. Thewin_getid() andwin_id2tabwin()functions can be used to convert between the window/tab number and theidentifier. There is also the window number, which may change wheneverwindows are opened or closed, seewinnr().The window number is only valid in one specific tab. The window ID is validacross tabs. For most functions that take a window ID or a window number, thewindow number only applies to the current tab, while the window ID can referto a window in any tab.

2. Starting Vimwindows-starting

By default, Vim starts with one window, just like Vi.
The "-o" and "-O" arguments to Vim can be used to open a window for each filein the argument list. The "-o" argument will split the windows horizontally;the "-O" argument will split the windows vertically. If both "-o" and "-O"are given, the last one encountered will be used to determine the splitorientation. For example, this will open three windows, split horizontally:
vim -o file1 file2 file3
"-oN", where N is a decimal number, opens N windows split horizontally. Ifthere are more file names than windows, only N windows are opened and somefiles do not get a window. If there are more windows than file names, thelast few windows will be editing empty buffers. Similarly, "-ON" opens Nwindows split vertically, with the same restrictions.
If there are many file names, the windows will become very small. You mightwant to set the'winheight' and/or'winwidth' options to create a workablesituation.
Buf/Win Enter/Leaveautocommands are not executed when opening the newwindows and reading the files, that's only done when they are really entered.
status-line
A status line will be used to separate windows. The'laststatus' option tellswhen the last window also has a status line:'laststatus' = 0never a status line'laststatus' = 1status line if there is more than one window'laststatus' = 2always a status line'laststatus' = 3have a global statusline at the bottom insteadof one for each window
You can change the contents of the status line with the'statusline' option.This option can be local to the window, so that you can have a differentstatus line in each window.
Normally, inversion is used to display the status line. This can be changedwith thehl-StatusLine highlight group. If no highlighting is used for thestatus line, the '^' character is used for the current window, and '=' forother windows. If'mouse' is enabled, a status line can be dragged to resizewindows.
filler-lines
The lines after the last buffer line in a window are called filler lines. Bydefault, these lines start with a tilde (~) character. The "eob" item in the'fillchars' option can be used to change this character. By default, thesecharacters are highlighted as NonText (hl-NonText). The EndOfBufferhighlight group (hl-EndOfBuffer) can be used to change the highlighting ofthe filler characters.

3. Opening and closing a windowopening-window

CTRL-W sCTRL-W_s
CTRL-W SCTRL-W_S
CTRL-WCTRL-SCTRL-W_CTRL-S
:[N]sp[lit] [++opt] [+cmd]:sp:splitSplit current window in two. The result is two viewports onthe same file.
Make the new window N high (default is to use half the heightof the current window). Reduces the current window height tocreate room (and others, if the'equalalways' option is set,'eadirection' isn't "hor", and one of them is higher than thecurrent or the new window).
Note:CTRL-S does not work on all terminals and might blockfurther input, useCTRL-Q to get going again.Also see++opt and+cmd.E242E1159Be careful when splitting a window in an autocommand, it maymess up the window layout if this happens while making otherwindow layout changes.
:[N]sp[lit] [++opt] [+cmd]{file}:split_f
Like:split but create a new window and start editing file{file} in it.This behaves almost like a ":split" first, and then an ":edit"command, but the alternate file name in the original window isset to{file}.If [+cmd] is given, execute the command when the file has beenloaded+cmd.Also see++opt.Make new window N high (default is to use half the existingheight). Reduces the current window height to create room(and others, if the'equalalways' option is set).
CTRL-WCTRL-VCTRL-W_CTRL-V
CTRL-W vCTRL-W_v
:[N]vs[plit] [++opt] [+cmd] [file]:vs:vsplitLike:split, but split vertically. The windows will bespread out horizontally if1. a width was not specified,2.'equalalways' is set,3.'eadirection' isn't "ver", and4. one of the other windows is wider than the current or new window.If N was given make the new window N columns wide, ifpossible.Note: In other placesCTRL-Q does the same asCTRL-V, but hereit doesn't!
CTRL-W nCTRL-W_n
CTRL-WCTRL-NCTRL-W_CTRL-N
:[N]new [++opt] [+cmd]:new
Create a new window and start editing an empty file in it.Make new window N high (default is to use half the existingheight). Reduces the current window height to create room(and others, if the'equalalways' option is set and'eadirection' isn't "hor").Also see++opt and+cmd.If'fileformats' is not empty, the first format given will beused for the new buffer. If'fileformats' is empty, the'fileformat' of the current buffer is used. This can beoverridden with the++opt argument.Autocommands are executed in this order:1. WinLeave for the current window2. WinEnter for the new window3. BufLeave for the current buffer4. BufEnter for the new bufferThis behaves like a ":split" first, and then an ":enew"command.
:[N]new [++opt] [+cmd]{file}Like:split_f, create a new window and start editing{file}.
:[N]vne[w] [++opt] [+cmd] [file]:vne:vnewLike:new, but split vertically. If'equalalways' is setand'eadirection' isn't "ver" the windows will be spread outhorizontally, unless a width was specified.
:[N]sv[iew] [++opt] [+cmd] [file]:sv:sviewsplitviewSame as ":split", but set'readonly' option for this buffer.
:[N]sf[ind] [++opt] [+cmd]{file}:sf:sfi:sfindsplitfindSame as ":split", but search for{file} in'path' like in:find. Doesn't split if{file} is not found.
CTRL-WCTRL-^CTRL-W_CTRL-^CTRL-W_^CTRL-W ^Split the current window in two and edit the alternate file.When a count N is given, split the current window and editbuffer N. Similar to ":sp #" and ":sp #N", but it allows theother buffer to be unnamed. This command matches the behaviorofCTRL-^, except that it splits a window first.
CTRL-W geCTRL-W_ge
Detach the current window as an external window.Only available when using a UI withui-multigrid support.
Note that the'splitbelow' and'splitright' options influence where a newwindow will appear.E36
Creating a window will fail if there is not enough room. Every window needsat least one screen line and column, sometimes more. Options'winminheight'and'winminwidth' are relevant.
:vert:vertical:vert[ical]{cmd}Execute{cmd}. If it contains a command that splits a window,it will be split vertically. Forvertical wincmd = windowswill be equalized only vertically.Doesn't work for:execute and:normal.
:hor:horizontal:hor[izontal]{cmd}Execute{cmd} in a horizontal split window. Supports thesecommands:
:wincmd =: equalize windows only horizontally.
:terminal: open aterminal buffer in a split window.
:checkhealth: open a healthcheck buffer in a split window.
:lefta[bove]{cmd}:lefta:leftabove:abo[veleft]{cmd}:abo:aboveleftExecute{cmd}. If it contains a command that splits a window,it will be opened left (vertical split) or above (horizontalsplit) the current window. Overrules'splitbelow' and'splitright'.Doesn't work for:execute and:normal.
:rightb[elow]{cmd}:rightb:rightbelow:bel[owright]{cmd}:bel:belowrightExecute{cmd}. If it contains a command that splits a window,it will be opened right (vertical split) or below (horizontalsplit) the current window. Overrules'splitbelow' and'splitright'.Doesn't work for:execute and:normal.
:topleftE442:to[pleft]{cmd}Execute{cmd}. If it contains a command that splits a window,it will appear at the top and occupy the full width of the Vimwindow. When the split is vertical the window appears at thefar left and occupies the full height of the Vim window.Doesn't work for:execute and:normal.
:bo:botright:bo[tright]{cmd}Execute{cmd}. If it contains a command that splits a window,it will appear at the bottom and occupy the full width of theVim window. When the split is vertical the window appears atthe far right and occupies the full height of the Vim window.Doesn't work for:execute and:normal.
These command modifiers can be combined to make a vertically split windowoccupy the full height. Example:
:vertical topleft split tags
Opens a vertically split, full-height window on the "tags" file at the farleft of the Vim window.

Closing a window

:q[uit]:{count}q[uit]:count_quit
CTRL-W qCTRL-W_q
CTRL-WCTRL-QCTRL-W_CTRL-Q
Without{count}: Quit the current window. If{count} isgiven quit the{count} window.edit-window
When quitting the last edit window (not counting help orpreview windows), exit Vim.
When'hidden' is set, and there is only one window for thecurrent buffer, it becomes hidden. When'hidden' is not set,and there is only one window for the current buffer, and thebuffer was changed, the command fails.(Note:CTRL-Q does not work on all terminals).If [count] is greater than the last window number the lastwindow will be closed:
:1quit  " quit the first window:$quit  " quit the last window:9quit  " quit the last window        " if there are fewer than 9 windows opened:-quit  " quit the previous window:+quit  " quit the next window:+2quit " quit the second next window
When closing a help window, and this is not the only window,Vim will try to restore the previous window layout, see:helpclose.
:q[uit]!:{count}q[uit]!Without{count}: Quit the current window. If{count} isgiven quit the{count} windowIf this was the last window for a buffer, any changes to thatbuffer are lost. When quitting the last window (not countinghelp windows), exit Vim. The contents of the buffer are lost,even when'hidden' is set.
:clo[se][!]:{count}clo[se][!]CTRL-W cCTRL-W_c:clo:closeWithout{count}: Close the current window. If given close the{count} window.
When'hidden' is set, or when the buffer was changed and the[!] is used, the buffer becomes hidden (unless there is anotherwindow editing it).
When there is only oneedit-window in the current tab pageand there is another tab page, this closes the current tabpage.tab-page.
This command fails when:E444
There is only one window on the screen.
When'hidden' is not set, [!] is not used, the buffer has changes, and there is no other window on this buffer.Changes to the buffer are not written and won't get lost, sothis is a "safe" command.
CTRL-WCTRL-CCTRL-W_CTRL-C
You might have expected thatCTRL-WCTRL-C closes the currentwindow, but that does not work, because theCTRL-C cancels thecommand.
:hide
:hid[e]:{count}hid[e]Without{count}: Quit the current window, unless it is thelast window on the screen.If{count} is given quit the{count} window.
The buffer becomes hidden (unless there is another windowediting it or'bufhidden' isunload,delete orwipe).If the window is the last one in the current tab page the tabpage is closed.tab-page
The value of'hidden' is irrelevant for this command.Changes to the buffer are not written and won't get lost, sothis is a "safe" command.
:hid[e]{cmd}Execute{cmd} with'hidden' set. The previous value of'hidden' is restored after{cmd} has been executed.Example:
:hide edit Makefile
This will edit "Makefile", and hide the current buffer if ithas any changes.
:on[ly][!]:{count}on[ly][!]CTRL-W oCTRL-W_oE445CTRL-WCTRL-OCTRL-W_CTRL-O:on:onlyMake the current window the only one on the screen. All otherwindows are closed. For{count} see the:quit commandabove:count_quit.
When the'hidden' option is set, all buffers in closed windowsbecome hidden.
When'hidden' is not set, and the'autowrite' option is set,modified buffers are written. Otherwise, windows that havebuffers that are modified are not removed, unless the [!] isgiven, then they become hidden. But modified buffers arenever abandoned, so changes cannot get lost.
:fc:fclose:[count]fc[lose][!]Close [count] floating windows with the highest zindex values.'!' to close all floating windows.

4. Moving cursor to other windowswindow-move-cursor

CTRL-W<Down>CTRL-W_<Down>
CTRL-WCTRL-JCTRL-W_CTRL-JCTRL-W_jCTRL-W jMove cursor to Nth window below current one. Uses the cursorposition to select between alternatives.
CTRL-W<Up>CTRL-W_<Up>
CTRL-WCTRL-KCTRL-W_CTRL-KCTRL-W_kCTRL-W kMove cursor to Nth window above current one. Uses the cursorposition to select between alternatives.
CTRL-W<Left>CTRL-W_<Left>
CTRL-WCTRL-HCTRL-W_CTRL-H
CTRL-W<BS>CTRL-W_<BS>CTRL-W_hCTRL-W hMove cursor to Nth window left of current one. Uses thecursor position to select between alternatives.
CTRL-W<Right>CTRL-W_<Right>
CTRL-WCTRL-LCTRL-W_CTRL-LCTRL-W_lCTRL-W lMove cursor to Nth window right of current one. Uses thecursor position to select between alternatives.
CTRL-W wCTRL-W_wCTRL-W_CTRL-WCTRL-WCTRL-WWithout count: move cursor to thefocusable windowbelow/right of the current one. If none, go to the top-leftwindow. With count: go to Nth window (numbered top-left tobottom-right), skipping unfocusable windows. To obtain thewindow number seebufwinnr() andwinnr(). When N islarger than the number of windows go to the last focusablewindow.
CTRL-W_W
CTRL-W WWithout count: move cursor to thefocusable windowabove/left of current one. If none, go to the bottom-rightwindow. With count: go to Nth window, likeCTRL-W w.
CTRL-W tCTRL-W_tCTRL-W_CTRL-TCTRL-WCTRL-TMove cursor to top-left window.
CTRL-W bCTRL-W_bCTRL-W_CTRL-BCTRL-WCTRL-BMove cursor to bottom-right window.
CTRL-W pCTRL-W_pCTRL-W_CTRL-PCTRL-WCTRL-PGo to previous (last accessed) window.
CTRL-W_PE441CTRL-W PGo to preview window. When there is no preview window this isan error.
If Visual mode is active and the new window is not for the same buffer, theVisual mode is ended. If the window is on the same buffer, the cursorposition is set to keep the same Visual area selected.
:winc:wincmdThese commands can also be executed with ":wincmd":
:[count]winc[md]{arg}:winc[md] [count]{arg}Like executingCTRL-W [count]{arg}. Example:
:wincmd j
Moves to the window below the current one.This command is useful when a Normal mode cannot be used (fortheCursorHold autocommand event). Or when a Normal modecommand is inconvenient.The count can also be a window number. Example:
:exe nr .. "wincmd w"
This goes to window "nr".
Note: AllCTRL-W commands can also be executed with:wincmd, for thoseplaces where a Normal mode command can't be used or is inconvenient (e.g.in a browser-based terminal).

5. Moving windows aroundwindow-moving

CTRL-W rCTRL-W_rCTRL-W_CTRL-RE443CTRL-WCTRL-RRotate windows downwards/rightwards. The first window becomesthe second one, the second one becomes the third one, etc.The last window becomes the first window. The cursor remainsin the same window.This only works within the row or column of windows that thecurrent window is in.
CTRL-W_R
CTRL-W RRotate windows upwards/leftwards. The second window becomesthe first one, the third one becomes the second one, etc. Thefirst window becomes the last window. The cursor remains inthe same window.This only works within the row or column of windows that thecurrent window is in.
CTRL-W xCTRL-W_xCTRL-W_CTRL-XCTRL-WCTRL-XWithout count: Exchange current window with next one. Ifthere is no next window, exchange with previous window.With count: Exchange current window with Nth window (firstwindow is 1). The cursor is put in the other window.When vertical and horizontal window splits are mixed, theexchange is only done in the row or column of windows that thecurrent window is in.
The following commands can be used to change the window layout. For example,when there are two vertically split windows,CTRL-W K will change that inhorizontally split windows.CTRL-W H does it the other way around.
CTRL-W_K
CTRL-W KMove the current window to be at the very top, using the fullwidth of the screen. This works like:topleft split, exceptit is applied to the current window and no new window iscreated.
CTRL-W_J
CTRL-W JMove the current window to be at the very bottom, using thefull width of the screen. This works like:botright split,except it is applied to the current window and no new windowis created.
CTRL-W_H
CTRL-W HMove the current window to be at the far left, using thefull height of the screen. This works like:vert topleft split, except it is applied to the currentwindow and no new window is created.
CTRL-W_L
CTRL-W LMove the current window to be at the far right, using the fullheight of the screen. This works like:vert botright split,except it is applied to the current window and no new windowis created.
CTRL-W_T
CTRL-W TMove the current window to a new tab page. This fails ifthere is only one window in the current tab page.This works like:tab split, except the previous window isclosed.When a count is specified the new tab page will be openedbefore the tab page with this index. Otherwise it comes afterthe current tab page.

6. Window resizingwindow-resize

CTRL-W_=
CTRL-W =Make all windows (almost) equally high and wide, but use'winheight' and'winwidth' for the current window.Windows with'winfixheight' set keep their height and windowswith'winfixwidth' set keep their width.To equalize only vertically (make window equally high) usevertical wincmd = .To equalize only horizontally (make window equally wide) usehorizontal wincmd = .
:res[ize] -N:res:resizeCTRL-W_-CTRL-W -Decrease current window height by N (default 1).If used after:vertical: decrease width by N.
:res[ize] +NCTRL-W_+
CTRL-W +Increase current window height by N (default 1).If used after:vertical: increase width by N.
:res[ize] [N]CTRL-WCTRL-_CTRL-W_CTRL-_CTRL-W__CTRL-W _Set current window height to N (default: highest possible).
:{winnr}res[ize] [+-]NLike:resize above, but apply the size to window{winnr}instead of the current window.
z{nr}<CR>Set current window height to{nr}.
CTRL-W_<
CTRL-W <Decrease current window width by N (default 1).
CTRL-W_>
CTRL-W >Increase current window width by N (default 1).
:vert[ical] res[ize] [N]:vertical-resizeCTRL-W_barCTRL-W |Set current window width to N (default: widest possible).
You can also resize a window by dragging a status line up or down with themouse. Or by dragging a vertical separator line left or right. This onlyworks if the version of Vim that is being used supports the mouse and the'mouse' option has been set to enable it.
The option'winheight' ('wh') is used to set the minimal window height of thecurrent window. This option is used each time another window becomes thecurrent window. If the option is '0', it is disabled. Set'winheight' to avery large value, e.g., '9999', to make the current window always fill allavailable space. Set it to a reasonable value, e.g., '10', to make editing inthe current window comfortable.
The equivalent'winwidth' ('wiw') option is used to set the minimal width ofthe current window.
When the option'equalalways' ('ea') is set, all the windows are automaticallymade the same size after splitting or closing a window. If you don't set thisoption, splitting a window will reduce the size of the current window andleave the other windows the same. When closing a window, the extra lines aregiven to the window above it.
The'eadirection' option limits the direction in which the'equalalways'option is applied. The default "both" resizes in both directions. When thevalue is "ver" only the heights of windows are equalized. Use this when youhave manually resized a vertically split window and want to keep this width.Likewise, "hor" causes only the widths of windows to be equalized.
The option'cmdheight' ('ch') is used to set the height of the command-line.If you are annoyed by thehit-enter prompt for long messages, set thisoption to 2 or 3.
If there is only one window, resizing that window will also change the commandline height. If there are several windows, resizing the current window willalso change the height of the window below it (and sometimes the window aboveit).
The minimal height and width of a window is set with'winminheight' and'winminwidth'. These are hard values, a window will never become smaller.
WinScrolled and WinResized autocommands
win-scrolled-resized
If you want to get notified of changes in window sizes, theWinResizedautocommand event can be used.If you want to get notified of text in windows scrolling vertically orhorizontally, theWinScrolled autocommand event can be used. This will alsotrigger in window size changes.Exception: the events will not be triggered when the text scrolls for'incsearch'.WinResized-event
TheWinResized event is triggered after updating the display, severalwindows may have changed size then. A list of the IDs of windows that changedsince last time is provided in the v:event.windows variable, for example:[1003, 1006]WinScrolled-event
TheWinScrolled event is triggered afterWinResized, and also if a windowwas scrolled. That can be vertically (the text at the top of the windowchanged) or horizontally (when'wrap' is off or when the first displayed partof the first line changes). Note thatWinScrolled will trigger many moretimes thanWinResized, it may slow down editing a bit.
The information provided byWinScrolled is a dictionary for each window thathas changes, using the window ID as the key, and a total count of the changeswith the key "all". Example value forv:event:
{   all:  {width: 0, height:  2, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},   1003: {width: 0, height: -1, leftcol: 0, skipcol: 0, topline: 0, topfill: 0},   1006: {width: 0, height:  1, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},}
Note that the "all" entry has the absolute values of the individual windowsaccumulated.
If you need more information about what changed, or you want to "debounce" theevents (not handle every event to avoid doing too much work), you may want touse thewinlayout() andgetwininfo() functions.
WinScrolled andWinResized do not trigger when the first autocommand isadded, only after the first scroll or resize. They may trigger when switchingto another tab page.
The commands executed are expected to not cause window size or scroll changes.If this happens anyway, the event will trigger again very soon. In otherwords: Just before triggering the event, the current sizes and scrollpositions are stored and used to decide whether there was a change.

7. Argument and buffer list commandsbuffer-list

args list buffer list meaning
1. :[N]argument [N]11. :[N]buffer [N]to arg/buf N2. :[N]next [file ..]12. :[N]bnext [N]to Nth next arg/buf3. :[N]Next [N]13. :[N]bNext [N]to Nth previous arg/buf4. :[N]previous[N]14. :[N]bprevious [N]to Nth previous arg/buf5. :rewind / :first15. :brewind / :bfirstto first arg/buf6. :last16. :blastto last arg/buf7. :all17. :balledit all args/buffers18. :unhideedit all loaded buffers19. :[N]bmod [N]to Nth modified buf
split & args list split & buffer list meaning
21. :[N]sargument [N] 31. :[N]sbuffer [N]split + to arg/buf N22. :[N]snext [file ..] 32. :[N]sbnext [N] split + to Nth next arg/buf23. :[N]sNext [N] 33. :[N]sbNext [N] split + to Nth previous arg/buf24. :[N]sprevious [N] 34. :[N]sbprevious [N] split + to Nth previous arg/buf25. :srewind / :sfirst35. :sbrewind / :sbfirst split + to first arg/buf26. :slast36. :sblastsplit + to last arg/buf27. :sall37. :sballedit all args/buffers38. :sunhideedit all loaded buffers39. :[N]sbmod [N]split + to Nth modified buf
40. :argslist of arguments41. :bufferslist of buffers
The meaning of [N] depends on the command: [N] is the number of buffers to go forward/backward on 2/12/22/32, 3/13/23/33, and 4/14/24/34 [N] is an argument number, defaulting to current argument, for 1 and 21 [N] is a buffer number, defaulting to current buffer, for 11 and 31 [N] is a count for 19 and 39
Note: ":next" is an exception, because it must accept a list of file namesfor compatibility with Vi.

The argument list and multiple windows

The current position in the argument list can be different for each window.Remember that when doing ":e file", the position in the argument list staysthe same, but you are not editing the file at that position. To indicatethis, the file message (and the title, if you have one) shows"(file (N) of M)", where "(N)" is the current position in the file list, and"M" the number of files in the file list.
All the entries in the argument list are added to the buffer list. Thus, youcan also get to them with the buffer list commands, like ":bnext".
:[N]al[l][!] [N]:al:all:sal:sall:[N]sal[l][!] [N]Rearrange the screen to open one window for each argument.All other windows are closed. When a count is given, this isthe maximum number of windows to open.With the:tab modifier open a tab page for each argument.When there are more arguments than'tabpagemax' further onesbecome split windows in the last tab page.When the'hidden' option is set, all buffers in closed windowsbecome hidden.When'hidden' is not set, and the'autowrite' option is set,modified buffers are written. Otherwise, windows that havebuffers that are modified are not removed, unless the [!] isgiven, then they become hidden. But modified buffers arenever abandoned, so changes cannot get lost.[N] is the maximum number of windows to open.'winheight'also limits the number of windows opened ('winwidth' if:vertical was prepended).Buf/Win Enter/Leave autocommands are not executed for the newwindows here, that's only done when they are really entered.If autocommands change the window layout while this command isbusy an error will be given.E249
:[N]sa[rgument][!] [++opt] [+cmd] [N]:sa:sargumentShort for ":split | argument [N]": split window and go to Nthargument. But when there is no such argument, the window isnot split. Also see++opt and+cmd.
:[N]sn[ext][!] [++opt] [+cmd] [file ..]:sn:snextShort for ":split | [N]next": split window and go to Nth nextargument. But when there is no next file, the window is notsplit. Also see++opt and+cmd.
:[N]spr[evious][!] [++opt] [+cmd] [N]:spr:sprevious:[N]sN[ext][!] [++opt] [+cmd] [N]:sN:sNextShort for ":split | [N]Next": split window and go to Nthprevious argument. But when there is no previous file, thewindow is not split. Also see++opt and+cmd.
:sre:srewind:sre[wind][!] [++opt] [+cmd]Short for ":split | rewind": split window and go to firstargument. But when there is no argument list, the window isnot split. Also see++opt and+cmd.
:sfir:sfirst:sfir[st] [++opt] [+cmd]Same as ":srewind".
:sla:slast:sla[st][!] [++opt] [+cmd]Short for ":split | last": split window and go to lastargument. But when there is no argument list, the window isnot split. Also see++opt and+cmd.
:dr:drop:dr[op] [++opt] [+cmd]{file} ..Edit the first{file} in a window.
If the file is already open in a window change to that window.
If the file is not open in a window edit the file in the current window. If the current buffer can't beabandoned, the window is split first.
Windows that are not in the argument list or are not full width will be closed if possible.Theargument-list is set, like with the:next command.The purpose of this command is that it can be used from aprogram that wants Vim to edit another file, e.g., a debugger.When using the:tab modifier each argument is opened in atab page. The last window is used if it's empty.Also see++opt and+cmd.

8. Do a command in all buffers or windowslist-repeat

:windo
:[range]windo{cmd}Execute{cmd} in eachfocusable window, or only forwindows in a given [range] of window numbers. It workslike doing this:
CTRL-W t:{cmd}CTRL-W w:{cmd}etc.
This only operates in the current tab page.When an error is detected on one window, furtherwindows will not be visited.The last window (or where an error occurred) becomesthe current window.{cmd} can contain '|' to concatenate several commands.{cmd} must not open or close windows or reorder them.
Also see:tabdo,:argdo,:bufdo,:cdo,:ldo,:cfdo and:lfdo.
:bufdo
:[range]bufdo[!]{cmd}Execute{cmd} in each buffer in the buffer list or if[range] is given only for buffers for which theirbuffer number is in the [range]. It works like doingthis:
:bfirst:{cmd}:bnext:{cmd}etc.
When the current file can't beabandoned and the [!]is not present, the command fails.When an error is detected on one buffer, furtherbuffers will not be visited.Unlisted buffers are skipped.The last buffer (or where an error occurred) becomesthe current buffer.{cmd} can contain '|' to concatenate several commands.{cmd} must not delete buffers or add buffers to thebuffer list.Note: While this command is executing, the Syntaxautocommand event is disabled by adding it to'eventignore'. This considerably speeds up editingeach buffer.
Also see:tabdo,:argdo,:windo,:cdo,:ldo,:cfdo and:lfdo.
Examples:
:windo set nolist foldcolumn=0 | normal! zn
This resets the'list' option and disables folding in all windows.
:bufdo set fileencoding= | update
This resets the'fileencoding' in each buffer and writes it if this changedthe buffer. The result is that all buffers will use the'encoding' encoding(if conversion succeeds).

9. Tag or file name under the cursorwindow-tag

:sta:stag:sta[g][!] [tagname]Does ":tag[!] [tagname]" and splits the window for the foundtag. See also:tag.
CTRL-W ]CTRL-W_]CTRL-W_CTRL-]CTRL-WCTRL-]Split current window in two. Use identifier under cursor as atag and jump to it in the new upper window.In Visual mode uses the Visually selected text as a tag.Make new window N high.
CTRL-W_g]
CTRL-W g ]Split current window in two. Use identifier under cursor as atag and perform ":tselect" on it in the new upper window.In Visual mode uses the Visually selected text as a tag.Make new window N high.
CTRL-W_g_CTRL-]
CTRL-W gCTRL-]Split current window in two. Use identifier under cursor as atag and perform ":tjump" on it in the new upper window.In Visual mode uses the Visually selected text as a tag.Make new window N high.
CTRL-W fCTRL-W_fCTRL-W_CTRL-FCTRL-WCTRL-FSplit current window in two. Edit file name under cursor.Like ":split gf", but window isn't split if the file does notexist.Uses the'path' variable as a list of directory names where tolook for the file. Also the path for current file isused to search for the file name.If the name is a hypertext link that looks like"type://machine/path", only "/path" is used.If a count is given, the count'th matching file is edited.
CTRL-W FCTRL-W_F
Split current window in two. Edit file name under cursor andjump to the line number following the file name. SeegF fordetails on how the line number is obtained.
CTRL-W gfCTRL-W_gf
Open a new tab page and edit the file name under the cursor.Like "tab split" and "gf", but the new tab page isn't createdif the file does not exist.
CTRL-W gFCTRL-W_gF
Open a new tab page and edit the file name under the cursorand jump to the line number following the file name. Like"tab split" and "gF", but the new tab page isn't created ifthe file does not exist.
CTRL-W gtCTRL-W_gt
Go to next tab page, same asgt.
CTRL-W gTCTRL-W_gT
Go to previous tab page, same asgT.
Also seeCTRL-W_CTRL-I: open window for an included file that includesthe keyword under the cursor.

10. The preview windowpreview-window

The preview window is a special window to show (preview) another file. It isnormally a small window used to show an include file or definition of afunction.
There can be only one preview window (per tab page). It is created with oneof the commands below. The'previewheight' option can be set to specify theheight of the preview window when it's opened. The'previewwindow' option isset in the preview window to be able to recognize it. The'winfixheight'option is set to have it keep the same height when opening/closing otherwindows.
:pt:ptag:pt[ag][!] [tagname]Does ":tag[!] [tagname]" and shows the found tag in a"Preview" window without changing the current buffer or cursorposition. If a "Preview" window already exists, it is re-used(like a help window is). If a new one is opened,'previewheight' is used for the height of the window. Seealso:tag.See below for an example.CursorHold-exampleSmall difference from:tag: When [tagname] is equal to thealready displayed tag, the position in the matching tag listis not reset. This makes the CursorHold example work after a:ptnext.
CTRL-W zCTRL-W_z
CTRL-WCTRL-ZCTRL-W_CTRL-Z:pc:pclose:pc[lose][!]Close any "Preview" window currently open. When the'hidden'option is set, or when the buffer was changed and the [!] isused, the buffer becomes hidden (unless there is anotherwindow editing it). The command fails if any "Preview" buffercannot be closed. See also:close.
:pp:ppop:[count]pp[op][!]Does ":[count]pop[!]" in the preview window. See:pop and:ptag.
CTRL-W }CTRL-W_}
Use identifier under cursor as a tag and perform a :ptag onit. Make the new Preview window (if required) N high. If Nis not given,'previewheight' is used.
CTRL-W g }CTRL-W_g}
Use identifier under cursor as a tag and perform a :ptjump onit. Make the new Preview window (if required) N high. If Nis not given,'previewheight' is used.
:pb:pbuffer:[N]pb[uffer][!] [+cmd] [N]Edit buffer [N] from the buffer list in the preview window.If [N] is not given, the current buffer remains being edited.See:buffer-! for [!]. This will also edit a buffer that isnot in the buffer list, without setting the'buflisted' flag.Also see+cmd.
:ped:pedit:ped[it][!] [++opt] [+cmd]{file}Edit{file} in the preview window. The preview window isopened like with:ptag. The current window and cursorposition isn't changed. Useful example:
:pedit +/fputc /usr/include/stdio.h
Also see++opt and+cmd.
:ps:psearch:[range]ps[earch][!] [count] [/]pattern[/]Works like:ijump but shows the found match in the previewwindow. The preview window is opened like with:ptag. Thecurrent window and cursor position isn't changed. Usefulexample:
:psearch popen
Like with the:ptag command, you can use this toautomatically show information about the word under thecursor. This is less clever than using:ptag, but you don'tneed a tags file and it will also find matches in systeminclude files. Example:
:au! CursorHold *.[ch] ++nested exe "silent! psearch " .. expand("<cword>")
Warning: This can be slow.
ExampleCursorHold-example
:au! CursorHold *.[ch] ++nested exe "silent! ptag " .. expand("<cword>")
This will cause a ":ptag" to be executed for the keyword under the cursor,when the cursor hasn't moved for the time set with'updatetime'. "++nested"makes other autocommands be executed, so that syntax highlighting works in thepreview window. The "silent!" avoids an error message when the tag could notbe found. Also seeCursorHold. To disable this again:
:au! CursorHold
A nice addition is to highlight the found tag, avoid the ":ptag" when thereis no word under the cursor, and a few other things:
:au! CursorHold *.[ch] ++nested call PreviewWord():func PreviewWord():  if &previewwindow" don't do this in the preview window:    return:  endif:  let w = expand("<cword>")" get the word under cursor:  if w =~ '\a'" if the word contains a letter::    " Delete any existing highlight before showing another tag:    silent! wincmd P" jump to preview window:    if &previewwindow" if we really get there...:      match none" delete existing highlight:      wincmd p" back to old window:    endif::    " Try displaying a matching tag for the word under the cursor:    try:       exe "ptag " .. w:    catch:      return:    endtry::    silent! wincmd P" jump to preview window:    if &previewwindow" if we really get there...: if has("folding"):   silent! .foldopen" don't want a closed fold: endif: call search("$", "b")" to end of previous line: let w = substitute(w, '\\', '\\\\', ""): call search('\<\V' .. w .. '\>')" position cursor on match: " Add a match highlight to the word at this position:      hi previewWord term=bold ctermbg=green guibg=green: exe 'match previewWord "\%' .. line(".") .. 'l\%' .. col(".") .. 'c\k*"':      wincmd p" back to old window:    endif:  endif:endfun

11. Using hidden buffersbuffer-hidden

A hidden buffer is not displayed in a window, but is still loaded into memory.This makes it possible to jump from file to file, without the need to read orwrite the file every time you get another buffer in a window.
:buffer-!
If the option'hidden' ('hid') is set, abandoned buffers are kept for allcommands that start editing another file: ":edit", ":next", ":tag", etc. Thecommands that move through the buffer list sometimes make the current bufferhidden although the'hidden' option is not set. This happens when a buffer ismodified, but is forced (with '!') to be removed from a window, and'autowrite' is off or the buffer can't be written.
You can make a hidden buffer not hidden by starting to edit it with anycommand, or by deleting it with the ":bdelete" command.
The'hidden' is global, it is used for all buffers. The'bufhidden' optioncan be used to make an exception for a specific buffer. It can take thesevalues:<empty>Use the value of'hidden'.hideHide this buffer, also when'hidden' is not set.unloadDon't hide but unload this buffer, also when'hidden'is set.deleteDelete the buffer.
hidden-quit
When you try to quit Vim while there is a hidden, modified buffer, you willget an error message and Vim will make that buffer the current buffer. Youcan then decide to write this buffer (":wq") or quit without writing (":q!").Be careful: there may be more hidden, modified buffers!
A buffer can also be unlisted. This means it exists, but it is not in thelist of buffers.unlisted-buffer
:files[!] [flags]:files
:buffers[!] [flags]:buffers:ls:ls[!] [flags]Show all buffers. Example:
1 #h "/test/text"line 1
2u "asdf"line 0
3 %a + "version.c"line 1
When the [!] is included the list will show unlisted buffers(the term "unlisted" is a bit confusing then...).
Each buffer has a unique number. That number will not change,thus you can always go to a specific buffer with ":buffer N"or "NCTRL-^", where N is the buffer number.
For the file name these special values are used:"[Prompt]"prompt-buffer "[Scratch]"'buftype' is "nofile""[No Name]"no file name specified
Indicators (chars in the same column are mutually exclusive):uan unlisted buffer (only displayed when [!] is used)unlisted-buffer %the buffer in the current window #the alternate buffer for ":e #" andCTRL-^ aan active buffer: it is loaded and visible ha hidden buffer: It is loaded, but currently not displayed in a windowhidden-buffer- a buffer with'modifiable' off =a readonly buffer Ra terminal buffer with a running job Fa terminal buffer with a finished job ? a terminal buffer without a job::terminal NONE +a modified buffer x a buffer with read errors
[flags] can be a combination of the following characters,which restrict the buffers to be listed:+modified buffers- buffers with'modifiable' off=readonly buffersaactive buffersuunlisted buffers (overrides the "!")hhidden buffersxbuffers with a read error%current buffer#alternate bufferRterminal buffers with a running jobFterminal buffers with a finished jobtshow time last used and sort buffersCombining flags means they are "and"ed together, e.g.:h+hidden buffers which are modifieda+active buffers which are modified
When using:filter the pattern is matched against thedisplayed buffer name, e.g.:
filter /\.vim/ ls
:bad:badd:bad[d][+lnum]{fname}Add file name{fname} to the buffer list, without loading it,if it wasn't listed yet. If the buffer was previouslydeleted, not wiped, it will be made listed again.If "lnum" is specified, the cursor will be positioned at thatline when the buffer is first entered. Note that othercommands after the + will be ignored.
:balt
:balt [+lnum]{fname}Like:badd and also set the alternate file for the currentwindow to{fname}.
:[N]bd[elete][!]:bd:bdel:bdeleteE516:bd[elete][!] [N]Unload buffer [N] (default: current buffer) and delete it fromthe buffer list. If the buffer was changed, this fails,unless when [!] is specified, in which case changes are lost.The file remains unaffected. Any windows for this buffer areclosed. If buffer [N] is the current buffer, another bufferwill be displayed instead. This is the most recent entry inthe jump list that points into a loaded buffer.Actually, the buffer isn't completely deleted, it is removedfrom the buffer listunlisted-buffer and option values,variables and mappings/abbreviations for the buffer arecleared. Examples:
:.,$-bdelete    " delete buffers from the current one to                " last but one:%bdelete    " delete all buffers
:bd[elete][!]{bufname}E93E94Like ":bdelete[!] [N]", but buffer given by name, see{bufname}.
:bd[elete][!] N1 N2 ...Do ":bdelete[!]" for buffer N1, N2, etc. The arguments can bebuffer numbers or buffer names (but not buffer names that area number). Insert a backslash before a space in a buffername.
:N,Mbd[elete][!]Do ":bdelete[!]" for all buffers in the range N to Minclusive.
:[N]bw[ipeout][!]:bw:bwipe:bwipeoutE517:bw[ipeout][!]{bufname}:N,Mbw[ipeout][!]:bw[ipeout][!] N1 N2 ...Like:bdelete, but really delete the buffer. Everythingrelated to the buffer is lost. All marks in this bufferbecome invalid, option settings are lost, the jumplist andtagstack data will be purged, etc. Don't use thisunless you know what you are doing. Examples:
:.+,$bwipeout   " wipe out all buffers after the current                " one:%bwipeout    " wipe out all buffers
:[N]bun[load][!]:bun:bunloadE515:bun[load][!] [N]Unload buffer [N] (default: current buffer). The memoryallocated for this buffer will be freed. The buffer remainsin the buffer list.If the buffer was changed, this fails, unless when [!] isspecified, in which case the changes are lost.Any windows for this buffer are closed. If buffer [N] is thecurrent buffer, another buffer will be displayed instead.This is the most recent entry in the jump list that pointsinto a loaded buffer.
:bun[load][!]{bufname}Like ":bunload[!] [N]", but buffer given by name.Also see{bufname}.
:N,Mbun[load][!]Do ":bunload[!]" for all buffers in the range N to Minclusive.
:bun[load][!] N1 N2 ...Do ":bunload[!]" for buffer N1, N2, etc. The arguments can bebuffer numbers or buffer names (but not buffer names that area number). Insert a backslash before a space in a buffername.
:[N]b[uffer][!] [+cmd] [N]:b:bu:buf:bufferE86Edit buffer [N] from the buffer list. If [N] is not given,the current buffer remains being edited. See:buffer-! for[!]. This will also edit a buffer that is not in the bufferlist, without setting the'buflisted' flag.Also see+cmd.
:[N]b[uffer][!] [+cmd]{bufname}{bufname}
Edit buffer for{bufname} from the buffer list. A partialname also works, so long as it is unique in the list ofbuffers.Note that a buffer whose name is a number cannot be referencedby that name; use the buffer number instead. Same is true ifthe buffer name starts with a+, it will be interpreted asthe start of a+cmd.Insert a backslash before a space in a buffer name.See:buffer-! for [!].This will also edit a buffer that is not in the buffer list,without setting the'buflisted' flag.Also see+cmd.
:[N]sb[uffer] [+cmd] [N]:sb:sbufferSplit window and edit buffer [N] from the buffer list. If [N]is not given, the current buffer is edited. Respects the"useopen" setting of'switchbuf' when splitting. This willalso edit a buffer that is not in the buffer list, withoutsetting the'buflisted' flag.Also see+cmd.
:[N]sb[uffer] [+cmd]{bufname}Split window and edit buffer for{bufname} from the bufferlist. This will also edit a buffer that is not in the bufferlist, without setting the'buflisted' flag.Note: If what you want to do is split the buffer, make a copyunder another name, you can do it this way:
:w foobar | sp #
Also see+cmd.
:[N]bn[ext][!] [+cmd] [N]:bn:bnextE87Go to [N]th next buffer in buffer list. [N] defaults to one.Wraps around the end of the buffer list.See:buffer-! for [!].Also see+cmd.If you are in a help buffer, this takes you to the next helpbuffer (if there is one). Similarly, if you are in a normal(non-help) buffer, this takes you to the next normal buffer.This is so that if you have invoked help, it doesn't get inthe way when you're browsing code/text buffers. The nextthree commands also work like this.
]b
]bMapped to:bnext.default-mappings
:sbn:sbnext:[N]sbn[ext] [+cmd] [N]Split window and go to [N]th next buffer in buffer list.Wraps around the end of the buffer list. Uses'switchbuf'Also see+cmd.
:[N]bN[ext][!] [+cmd] [N]:bN:bNext:bp:bpreviousE88
[b
[bMapped to:bprevious.default-mappings
:[N]bp[revious][!] [+cmd] [N]Go to [N]th previous buffer in buffer list. [N] defaults toone. Wraps around the start of the buffer list.See:buffer-! for [!] and'switchbuf'.Also see+cmd.
:[N]sbN[ext] [+cmd] [N]:sbN:sbNext:sbp:sbprevious:[N]sbp[revious] [+cmd] [N]Split window and go to [N]th previous buffer in buffer list.Wraps around the start of the buffer list.Uses'switchbuf'.Also see+cmd.
:br[ewind][!] [+cmd]:br:bre:brewindGo to first buffer in buffer list. If the buffer list isempty, go to the first unlisted buffer.See:buffer-! for [!].
[B
[BMapped to:brewind.default-mappings
:bf[irst] [+cmd]:bf:bfirstSame as:brewind.Also see+cmd.
:sbr[ewind] [+cmd]:sbr:sbrewindSplit window and go to first buffer in buffer list. If thebuffer list is empty, go to the first unlisted buffer.Respects the'switchbuf' option.Also see+cmd.
:sbf[irst] [+cmd]:sbf:sbfirstSame as ":sbrewind".
:bl[ast][!] [+cmd]:bl:blastGo to last buffer in buffer list. If the buffer list isempty, go to the last unlisted buffer.See:buffer-! for [!].
]B
]BMapped to:blast.default-mappings
:sbl[ast] [+cmd]:sbl:sblastSplit window and go to last buffer in buffer list. If thebuffer list is empty, go to the last unlisted buffer.Respects'switchbuf' option.
:[N]bm[odified][!] [+cmd] [N]:bm:bmodifiedE84Go to [N]th next modified buffer. Note: this command alsofinds unlisted buffers. If there is no modified buffer thecommand fails.
:[N]sbm[odified] [+cmd] [N]:sbm:sbmodifiedSplit window and go to [N]th next modified buffer.Respects'switchbuf' option.Note: this command also finds buffers not in the buffer list.
:[N]unh[ide] [N]:unh:unhide:sun:sunhide:[N]sun[hide] [N]Rearrange the screen to open one window for each loaded bufferin the buffer list. When a count is given, this is themaximum number of windows to open.
:[N]ba[ll] [N]:ba:ball:sba:sball:[N]sba[ll] [N]Rearrange the screen to open one window for each buffer inthe buffer list. When a count is given, this is the maximumnumber of windows to open.'winheight' also limits the numberof windows opened ('winwidth' if:vertical was prepended).Buf/Win Enter/Leave autocommands are not executed for the newwindows here, that's only done when they are really entered.When the:tab modifier is used new windows are opened in anew tab, up to'tabpagemax'.
Note: All the commands above that start editing another buffer, keep the'readonly' flag as it was. This differs from the ":edit" command, which setsthe'readonly' flag each time the file is read.

12. Special kinds of buffersspecial-buffers

Instead of containing the text of a file, buffers can also be used for otherpurposes. A few options can be set to change the behavior of a buffer:'bufhidden'what happens when the buffer is no longer displayedin a window.'buftype'what kind of a buffer this is'swapfile'whether the buffer will have a swap file'buflisted'buffer shows up in the buffer list
A few useful kinds of a buffer:
quickfixUsed to contain the error list or the location list. See:cwindow and:lwindow. This command sets the'buftype'option to "quickfix". You are not supposed to change this!'swapfile' is off.
helpContains a help file. Will only be created with the:helpcommand. The flag that indicates a help buffer is internaland can't be changed. The'buflisted' option will be resetfor a help buffer.
terminalA terminal window buffer, seeterminal. The contents cannotbe read or changed until the job ends.
directoryDisplays directory contents. Can be used by a file explorerplugin. The buffer is created with these settings:
:setlocal buftype=nowrite:setlocal bufhidden=delete:setlocal noswapfile
The buffer name is the name of the directory and is adjustedwhen using the:cd command.
scratch-buffer
scratchContains text that can be discarded at any time. It is keptwhen closing the window, it must be deleted explicitly.Settings:
:setlocal buftype=nofile:setlocal bufhidden=hide:setlocal noswapfile
The buffer name can be used to identify the buffer, if yougive it a meaningful name.
unlisted-buffer
unlistedThe buffer is not in the buffer list. It is not used fornormal editing, but to show a help file, remember a file nameor marks. The ":bdelete" command will also set this option,thus it doesn't completely delete the buffer. Settings:
:setlocal nobuflisted
Main
Commands index
Quick reference

1. Introduction
2. Starting Vim
3. Opening and closing a window
Closing a window
4. Moving cursor to other windows
5. Moving windows around
6. Window resizing
7. Argument and buffer list commands
The argument list and multiple windows
8. Do a command in all buffers or windows
9. Tag or file name under the cursor
10. The preview window
11. Using hidden buffers
12. Special kinds of buffers

[8]ページ先頭

©2009-2025 Movatter.jp