@c This is part of the Emacs manual.@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001 Free Software Foundation, Inc.@c See file emacs.texi for copying conditions.@node Windows, Frames, Buffers, Top@chapter Multiple Windows@cindex windows in Emacs@cindex multiple windows in Emacs Emacs can split a frame into two or many windows. Multiple windowscan display parts of different buffers, or different parts of onebuffer. Multiple frames always imply multiple windows, because eachframe has its own set of windows. Each window belongs to one and onlyone frame.@menu* Basic Window:: Introduction to Emacs windows.* Split Window:: New windows are made by splitting existing windows.* Other Window:: Moving to another window or doing something to it.* Pop Up Window:: Finding a file or buffer in another window.* Force Same Window:: Forcing certain buffers to appear in the selected window rather than in another window.* Change Window:: Deleting windows and changing their sizes.* Window Convenience:: Convenience functions for window handling.@end menu@node Basic Window@section Concepts of Emacs Windows Each Emacs window displays one Emacs buffer at any time. A singlebuffer may appear in more than one window; if it does, any changes inits text are displayed in all the windows where it appears. But thewindows showing the same buffer can show different parts of it, becauseeach window has its own value of point.@cindex selected window At any time, one of the windows is the @dfn{selected window}; thebuffer this window is displaying is the current buffer. The terminal'scursor shows the location of point in this window. Each other windowhas a location of point as well, but since the terminal has only onecursor there is no way to show where those locations are. When multipleframes are visible in X, each frame has a cursor which appears in theframe's selected window. The cursor in the selected frame is solid; thecursor in other frames is a hollow box. Commands to move point affect the value of point for the selected Emacswindow only. They do not change the value of point in any other Emacswindow, even one showing the same buffer. The same is true for commandssuch as @kbd{C-x b} to change the current buffer in the selected window;they do not affect other windows at all. However, there are other commandssuch as @kbd{C-x 4 b} that select a different window and switch buffers init. Also, all commands that display information in a window, including(for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b}(@code{list-buffers}), work by switching buffers in a nonselected windowwithout affecting the selected window. When multiple windows show the same buffer, they can have differentregions, because they can have different values of point. However,they all have the same value for the mark, because each buffer hasonly one mark position. Each window has its own mode line, which displays the buffer name,modification status and major and minor modes of the buffer that isdisplayed in the window. @xref{Mode Line}, for full details on the modeline.@iftex@break@end iftex@node Split Window@section Splitting Windows@table @kbd@item C-x 2Split the selected window into two windows, one above the other(@code{split-window-vertically}).@item C-x 3Split the selected window into two windows positioned side by side(@code{split-window-horizontally}).@item C-Mouse-2In the mode line or scroll bar of a window, split that window.@end table@kindex C-x 2@findex split-window-vertically The command @kbd{C-x 2} (@code{split-window-vertically}) breaks theselected window into two windows, one above the other. Both windows startout displaying the same buffer, with the same value of point. By defaultthe two windows each get half the height of the window that was split; anumeric argument specifies how many lines to give to the top window.@kindex C-x 3@findex split-window-horizontally @kbd{C-x 3} (@code{split-window-horizontally}) breaks the selectedwindow into two side-by-side windows. A numeric argument specifies howmany columns to give the one on the left. A line of vertical barsseparates the two windows. Windows that are not the full width of thescreen have mode lines, but they are truncated. On terminals whereEmacs does not support highlighting, truncated mode lines sometimes donot appear in inverse video.@kindex C-Mouse-2 @r{(scroll bar)} You can split a window horizontally or vertically by clicking@kbd{C-Mouse-2} in the mode line or the scroll bar. (This does notwork in scroll bars implemented by X toolkits.) The line of splittinggoes through the place where you click: if you click on the mode line,the new scroll bar goes above the spot; if you click in the scrollbar, the mode line of the split window is side by side with yourclick.@vindex truncate-partial-width-windows When a window is less than the full width, text lines too long to fit arefrequent. Continuing all those lines might be confusing. The variable@code{truncate-partial-width-windows} can be set non-@code{nil} to forcetruncation in all windows less than the full width of the screen,independent of the buffer being displayed and its value for@code{truncate-lines}. @xref{Continuation Lines}.@refill Horizontal scrolling is often used in side-by-side windows.@xref{Display}.@vindex split-window-keep-point If @code{split-window-keep-point} is non-@code{nil}, the default,both of the windows resulting from @kbd{C-x 2} inherit the value ofpoint from the window that was split. This means that scrolling isinevitable. If this variable is @code{nil}, then @kbd{C-x 2} tries toavoid scrolling the text currently visible on the screen, by puttingpoint in each window at a position already visible in the window. Italso selects whichever window contain the screen line that the cursorwas previously on. Some users prefer the latter mode on slowterminals.@node Other Window@section Using Other Windows@table @kbd@item C-x oSelect another window (@code{other-window}). That is @kbd{o}, not zero.@item C-M-vScroll the next window (@code{scroll-other-window}).@item M-x compare-windowsFind next place where the text in the selected window does not matchthe text in the next window.@item Mouse-1@kbd{Mouse-1}, in a window's mode line, selects that windowbut does not move point in it (@code{mouse-select-window}).@end table@kindex C-x o@findex other-window To select a different window, click with @kbd{Mouse-1} on its modeline. With the keyboard, you can switch windows by typing @kbd{C-x o}(@code{other-window}). That is an @kbd{o}, for ``other,'' not a zero.When there are more than two windows, this command moves through all thewindows in a cyclic order, generally top to bottom and left to right.After the rightmost and bottommost window, it goes back to the one atthe upper left corner. A numeric argument means to move several stepsin the cyclic order of windows. A negative argument moves around thecycle in the opposite order. When the minibuffer is active, theminibuffer is the last window in the cycle; you can switch from theminibuffer window to one of the other windows, and later switch back andfinish supplying the minibuffer argument that is requested.@xref{Minibuffer Edit}.@kindex C-M-v@findex scroll-other-window The usual scrolling commands (@pxref{Display}) apply to the selectedwindow only, but there is one command to scroll the next window.@kbd{C-M-v} (@code{scroll-other-window}) scrolls the window that@kbd{C-x o} would select. It takes arguments, positive and negative,like @kbd{C-v}. (In the minibuffer, @kbd{C-M-v} scrolls the windowthat contains the minibuffer help display, if any, rather than thenext window in the standard cyclic order.) The command @kbd{M-x compare-windows} lets you compare two files orbuffers visible in two windows, by moving through them to the nextmismatch. @xref{Comparing Files}, for details.@node Pop Up Window@section Displaying in Another Window@cindex selecting buffers in other windows@kindex C-x 4 @kbd{C-x 4} is a prefix key for commands that select another window(splitting the window if there is only one) and select a buffer in thatwindow. Different @kbd{C-x 4} commands have different ways of finding thebuffer to select.@table @kbd@item C-x 4 b @var{bufname} @key{RET}Select buffer @var{bufname} in another window. This runs@code{switch-to-buffer-other-window}.@item C-x 4 C-o @var{bufname} @key{RET}Display buffer @var{bufname} in another window, butdon't select that buffer or that window. This runs@code{display-buffer}.@item C-x 4 f @var{filename} @key{RET}Visit file @var{filename} and select its buffer in another window. Thisruns @code{find-file-other-window}. @xref{Visiting}.@item C-x 4 d @var{directory} @key{RET}Select a Dired buffer for directory @var{directory} in another window.This runs @code{dired-other-window}. @xref{Dired}.@item C-x 4 mStart composing a mail message in another window. This runs@code{mail-other-window}; its same-window analogue is @kbd{C-x m}(@pxref{Sending Mail}).@item C-x 4 .Find a tag in the current tags table, in another window. This runs@code{find-tag-other-window}, the multiple-window variant of @kbd{M-.}(@pxref{Tags}).@item C-x 4 r @var{filename} @key{RET}Visit file @var{filename} read-only, and select its buffer in anotherwindow. This runs @code{find-file-read-only-other-window}.@xref{Visiting}.@end table@node Force Same Window@section Forcing Display in the Same Window Certain Emacs commands switch to a specific buffer with specialcontents. For example, @kbd{M-x shell} switches to a buffer named@samp{*Shell*}. By convention, all these commands are written to pop upthe buffer in a separate window. But you can specify that certain ofthese buffers should appear in the selected window.@vindex same-window-buffer-names If you add a buffer name to the list @code{same-window-buffer-names},the effect is that such commands display that particular buffer byswitching to it in the selected window. For example, if you add theelement @code{"*grep*"} to the list, the @code{grep} command willdisplay its output buffer in the selected window. The default value of @code{same-window-buffer-names} is not@code{nil}: it specifies buffer names @samp{*info*}, @samp{*mail*} and@samp{*shell*} (as well as others used by more obscure Emacs packages).This is why @kbd{M-x shell} normally switches to the @samp{*shell*}buffer in the selected window. If you delete this element from thevalue of @code{same-window-buffer-names}, the behavior of @kbd{M-xshell} will change---it will pop up the buffer in another windowinstead.@vindex same-window-regexps You can specify these buffers more generally with the variable@code{same-window-regexps}. Set it to a list of regular expressions;then any buffer whose name matches one of those regular expressions isdisplayed by switching to it in the selected window. (Once again, thisapplies only to buffers that normally get displayed for you in aseparate window.) The default value of this variable specifies Telnetand rlogin buffers. An analogous feature lets you specify buffers which should bedisplayed in their own individual frames. @xref{Special Buffer Frames}.@node Change Window@section Deleting and Rearranging Windows@table @kbd@item C-x 0Delete the selected window (@code{delete-window}). The last characterin this key sequence is a zero.@item C-x 1Delete all windows in the selected frame except the selected window(@code{delete-other-windows}).@item C-x 4 0Delete the selected window and kill the buffer that was showing in it(@code{kill-buffer-and-window}). The last character in this keysequence is a zero.@item C-x ^Make selected window taller (@code{enlarge-window}).@item C-x @}Make selected window wider (@code{enlarge-window-horizontally}).@item C-x @{Make selected window narrower (@code{shrink-window-horizontally}).@item C-x -Shrink this window if its buffer doesn't need so many lines(@code{shrink-window-if-larger-than-buffer}).@item C-x +Make all windows the same height (@code{balance-windows}).@item Drag-Mouse-1Dragging a window's mode line up or down with @kbd{Mouse-1} changeswindow heights.@item Mouse-2@kbd{Mouse-2} in a window's mode line deletes all other windows in the frame(@code{mouse-delete-other-windows}).@item Mouse-3@kbd{Mouse-3} in a window's mode line deletes that window(@code{mouse-delete-window}), unless the frame has only one window, inwhich case it buries the current buffer instead and switches to anotherbuffer.@end table@kindex C-x 0@findex delete-window To delete a window, type @kbd{C-x 0} (@code{delete-window}). (That isa zero.) The space occupied by the deleted window is given to anadjacent window (but not the minibuffer window, even if that is activeat the time). Once a window is deleted, its attributes are forgotten;only restoring a window configuration can bring it back. Deleting thewindow has no effect on the buffer it used to display; the buffercontinues to exist, and you can select it in any window with @kbd{C-xb}.@findex kill-buffer-and-window@kindex C-x 4 0 @kbd{C-x 4 0} (@code{kill-buffer-and-window}) is a stronger commandthan @kbd{C-x 0}; it kills the current buffer and then deletes theselected window.@kindex C-x 1@findex delete-other-windows @kbd{C-x 1} (@code{delete-other-windows}) is more powerful in adifferent way; it deletes all the windows except the selected one (andthe minibuffer); the selected window expands to use the whole frameexcept for the echo area. You can also delete a window by clicking on its mode line with@kbd{Mouse-2}, and delete all the windows in a frame except one windowby clicking on that window's mode line with @kbd{Mouse-3}. The easiest way to adjust window heights is with a mouse. If youpress @kbd{Mouse-1} on a mode line, you can drag that mode line up ordown, changing the heights of the windows above and below it.@kindex C-x ^@findex enlarge-window@kindex C-x @}@findex enlarge-window-horizontally@vindex window-min-height@vindex window-min-width To readjust the division of space among vertically adjacent windows,use @kbd{C-x ^} (@code{enlarge-window}). It makes the currentlyselected window get one line bigger, or as many lines as is specifiedwith a numeric argument. With a negative argument, it makes theselected window smaller. @kbd{C-x @}}(@code{enlarge-window-horizontally}) makes the selected window wider bythe specified number of columns. @kbd{C-x @{}(@code{shrink-window-horizontally}) makes the selected window narrowerby the specified number of columns. When you make a window bigger, the space comes from one of itsneighbors. If this makes any window too small, it is deleted and itsspace is given to an adjacent window. The minimum size is specified bythe variables @code{window-min-height} and @code{window-min-width}.@kindex C-x -@findex shrink-window-if-larger-than-buffer The command @kbd{C-x -} (@code{shrink-window-if-larger-than-buffer})reduces the height of the selected window, if it is taller thannecessary to show the whole text of the buffer it is displaying. Itgives the extra lines to other windows in the frame.@kindex C-x +@findex balance-windows You can also use @kbd{C-x +} (@code{balance-windows}) to even out theheights of all the windows in the selected frame.@node Window Convenience@section Window Handling Convenience Features and Customization@findex winner-mode@cindex Winner mode@cindex mode, Winner@cindex undoing window configuration changes@cindex window configuration changes, undoing @kbd{M-x winner-mode} is a global minor mode that records thechanges in the window configuration (i.e. how the frames arepartitioned into windows), so that you can ``undo'' them. To undo,use @kbd{C-x left} (@code{winner-undo}). If you change your mindwhile undoing, you can redo the changes you had undone using @kbd{C-xright} (@code{M-x winner-redo}). Another way to enable Winner mode isby customizing the variable @code{winner-mode}.@cindex Windmove package@cindex directional window selection@findex windmove-right@findex windmove-default-keybindings The Windmove commands move directionally between neighboring windows ina frame. @kbd{M-x windmove-right} selects the window immediately to theright of the currently selected one, and similarly for the ``left,'' ``up,''and ``down'' counterparts. @kbd{M-x windmove-default-keybindings} bindsthese commands to @kbd{S-right} etc. (Not all terminals support shiftedarrow keys, however.) Follow minor mode (@kbd{M-x follow-mode}) synchronizes severalwindows on the same buffer so that they always display adjacentsections of that buffer. @xref{Follow Mode}.@vindex scroll-all-mode@cindex scrolling windows together@cindex Scroll-all mode@cindex mode, Scroll-all @kbd{M-x scroll-all-mode} provides commands to scroll all visiblewindows together. You can also turn it on by customizing the variable@code{scroll-all-mode}. The commands provided are @kbd{M-xscroll-all-scroll-down-all}, @kbd{M-x scroll-all-page-down-all} andtheir corresponding ``up'' equivalents. To make this mode useful,you should bind these commands to appropriate keys.