1@c This is part of the Emacs manual.
2@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
3@c   2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4@c See file emacs.texi for copying conditions.
5@node Windows, Frames, Buffers, Top
6@chapter Multiple Windows
7@cindex windows in Emacs
8@cindex multiple windows in Emacs
9
10  Emacs can split a frame into two or many windows.  Multiple windows
11can display parts of different buffers, or different parts of one
12buffer.  Multiple frames always imply multiple windows, because each
13frame has its own set of windows.  Each window belongs to one and only
14one frame.
15
16@menu
17* Basic Window::        Introduction to Emacs windows.
18* Split Window::        New windows are made by splitting existing windows.
19* Other Window::        Moving to another window or doing something to it.
20* Pop Up Window::       Finding a file or buffer in another window.
21* Force Same Window::   Forcing certain buffers to appear in the selected
22                          window rather than in another window.
23* Change Window::       Deleting windows and changing their sizes.
24* Window Convenience::  Convenience functions for window handling.
25@end menu
26
27@node Basic Window
28@section Concepts of Emacs Windows
29
30  Each Emacs window displays one Emacs buffer at any time.  A single
31buffer may appear in more than one window; if it does, any changes in
32its text are displayed in all the windows where it appears.  But these
33windows can show different parts of the buffer, because each window
34has its own value of point.
35
36@cindex selected window
37  At any time, one Emacs window is the @dfn{selected window}; the
38buffer this window is displaying is the current buffer.  The terminal's
39cursor shows the location of point in this window.  Each other window
40has a location of point as well.  On text-only terminals, there is no
41way to show where those locations are, since the terminal has only one
42cursor.  On a graphical display, the location of point in a
43non-selected window is indicated by a hollow box; the cursor in the
44selected window is blinking or solid.
45
46  Commands to move point affect the value of point for the selected Emacs
47window only.  They do not change the value of point in other Emacs
48windows, even those showing the same buffer.  The same is true for commands
49such as @kbd{C-x b} to switch buffers in the selected window;
50they do not affect other windows at all.  However, there are other commands
51such as @kbd{C-x 4 b} that select a different window and switch buffers in
52it.  Also, all commands that display information in a window, including
53(for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b}
54(@code{list-buffers}), work by switching buffers in a nonselected window
55without affecting the selected window.
56
57  When multiple windows show the same buffer, they can have different
58regions, because they can have different values of point.  However,
59they all have the same value for the mark, because each buffer has
60only one mark position.
61
62  Each window has its own mode line, which displays the buffer name,
63modification status and major and minor modes of the buffer that is
64displayed in the window.  The selected window's mode line appears in a
65different color.  @xref{Mode Line}, for full details on the mode line.
66
67@node Split Window
68@section Splitting Windows
69
70@table @kbd
71@item C-x 2
72Split the selected window into two windows, one above the other
73(@code{split-window-vertically}).
74@item C-x 3
75Split the selected window into two windows positioned side by side
76(@code{split-window-horizontally}).
77@item C-Mouse-2
78In the mode line or scroll bar of a window, split that window.
79@end table
80
81@kindex C-x 2
82@findex split-window-vertically
83  The command @kbd{C-x 2} (@code{split-window-vertically}) breaks the
84selected window into two windows, one above the other.  Both windows start
85out displaying the same buffer, with the same value of point.  By default
86the two windows each get half the height of the window that was split; a
87numeric argument specifies how many lines to give to the top window.
88
89@kindex C-x 3
90@findex split-window-horizontally
91  @kbd{C-x 3} (@code{split-window-horizontally}) breaks the selected
92window into two side-by-side windows.  A numeric argument specifies how
93many columns to give the one on the left.  If you are not using
94scrollbars, a vertical line separates the two windows.
95You can customize its color with the face @code{vertical-border}.
96Windows that are not the full width of the screen have mode lines, but
97they are truncated.  On terminals where Emacs does not support
98highlighting, truncated mode lines sometimes do not appear in inverse
99video.
100
101@kindex C-Mouse-2 @r{(scroll bar)}
102  You can split a window horizontally or vertically by clicking
103@kbd{C-Mouse-2} in the mode line or the scroll bar.  The line of
104splitting goes through the place where you click: if you click on the
105mode line, the new scroll bar goes above the spot; if you click in the
106scroll bar, the mode line of the split window is side by side with
107your click.
108
109@vindex truncate-partial-width-windows
110  When a window is less than the full width, text lines too long to
111fit are frequent.  Continuing all those lines might be confusing, so
112if the variable @code{truncate-partial-width-windows} is
113non-@code{nil}, that forces truncation in all windows less than the
114full width of the screen, independent of the buffer being displayed
115and its value for @code{truncate-lines}.  @xref{Line Truncation}.
116
117  Horizontal scrolling is often used in side-by-side windows.
118@xref{Horizontal Scrolling}.
119
120@vindex split-window-keep-point
121  If @code{split-window-keep-point} is non-@code{nil}, the default,
122both of the windows resulting from @kbd{C-x 2} inherit the value of
123point from the window that was split.  This means that scrolling is
124inevitable.  If this variable is @code{nil}, then @kbd{C-x 2} tries to
125avoid scrolling the text currently visible on the screen, by putting
126point in each window at a position already visible in the window.  It
127also selects whichever window contains the screen line that the cursor
128was previously on.  Some users prefer that mode on slow terminals.
129
130@node Other Window
131@section Using Other Windows
132
133@table @kbd
134@item C-x o
135Select another window (@code{other-window}).  That is @kbd{o}, not zero.
136@item C-M-v
137Scroll the next window (@code{scroll-other-window}).
138@item M-x compare-windows
139Find next place where the text in the selected window does not match
140the text in the next window.
141@item Mouse-1
142@kbd{Mouse-1}, in a window's mode line, selects that window
143but does not move point in it (@code{mouse-select-window}).
144@end table
145
146@kindex C-x o
147@findex other-window
148  To select a different window, click with @kbd{Mouse-1} on its mode
149line.  With the keyboard, you can switch windows by typing @kbd{C-x o}
150(@code{other-window}).  That is an @kbd{o}, for ``other,'' not a zero.
151When there are more than two windows, this command moves through all the
152windows in a cyclic order, generally top to bottom and left to right.
153After the rightmost and bottommost window, it goes back to the one at
154the upper left corner.  A numeric argument means to move several steps
155in the cyclic order of windows.  A negative argument moves around the
156cycle in the opposite order.  When the minibuffer is active, the
157minibuffer is the last window in the cycle; you can switch from the
158minibuffer window to one of the other windows, and later switch back and
159finish supplying the minibuffer argument that is requested.
160@xref{Minibuffer Edit}.
161
162@kindex C-M-v
163@findex scroll-other-window
164  The usual scrolling commands (@pxref{Display}) apply to the selected
165window only, but there is one command to scroll the next window.
166@kbd{C-M-v} (@code{scroll-other-window}) scrolls the window that
167@kbd{C-x o} would select.  It takes arguments, positive and negative,
168like @kbd{C-v}.  (In the minibuffer, @kbd{C-M-v} scrolls the window
169that contains the minibuffer help display, if any, rather than the
170next window in the standard cyclic order.)
171
172  The command @kbd{M-x compare-windows} lets you compare two files or
173buffers visible in two windows, by moving through them to the next
174mismatch.  @xref{Comparing Files}, for details.
175
176@vindex mouse-autoselect-window
177  If you set @code{mouse-autoselect-window} to a non-@code{nil} value,
178moving the mouse into a different window selects that window.  This
179feature is off by default.
180
181@node Pop Up Window
182@section Displaying in Another Window
183
184@cindex selecting buffers in other windows
185@kindex C-x 4
186  @kbd{C-x 4} is a prefix key for commands that select another window
187(splitting the window if there is only one) and select a buffer in that
188window.  Different @kbd{C-x 4} commands have different ways of finding the
189buffer to select.
190
191@table @kbd
192@item C-x 4 b @var{bufname} @key{RET}
193Select buffer @var{bufname} in another window.  This runs
194@code{switch-to-buffer-other-window}.
195@item C-x 4 C-o @var{bufname} @key{RET}
196Display buffer @var{bufname} in another window, but
197don't select that buffer or that window.  This runs
198@code{display-buffer}.
199@item C-x 4 f @var{filename} @key{RET}
200Visit file @var{filename} and select its buffer in another window.  This
201runs @code{find-file-other-window}.  @xref{Visiting}.
202@item C-x 4 d @var{directory} @key{RET}
203Select a Dired buffer for directory @var{directory} in another window.
204This runs @code{dired-other-window}.  @xref{Dired}.
205@item C-x 4 m
206Start composing a mail message in another window.  This runs
207@code{mail-other-window}; its same-window analogue is @kbd{C-x m}
208(@pxref{Sending Mail}).
209@item C-x 4 .
210Find a tag in the current tags table, in another window.  This runs
211@code{find-tag-other-window}, the multiple-window variant of @kbd{M-.}
212(@pxref{Tags}).
213@item C-x 4 r @var{filename} @key{RET}
214Visit file @var{filename} read-only, and select its buffer in another
215window.  This runs @code{find-file-read-only-other-window}.
216@xref{Visiting}.
217@end table
218
219@node Force Same Window
220@section Forcing Display in the Same Window
221
222  Certain Emacs commands switch to a specific buffer with special
223contents.  For example, @kbd{M-x shell} switches to a buffer named
224@samp{*shell*}.  By convention, all these commands are written to pop up
225the buffer in a separate window.  But you can specify that certain of
226these buffers should appear in the selected window.
227
228@vindex same-window-buffer-names
229  If you add a buffer name to the list @code{same-window-buffer-names},
230the effect is that such commands display that particular buffer by
231switching to it in the selected window.  For example, if you add the
232element @code{"*grep*"} to the list, the @code{grep} command will
233display its output buffer in the selected window.
234
235  The default value of @code{same-window-buffer-names} is not
236@code{nil}: it specifies buffer names @samp{*info*}, @samp{*mail*} and
237@samp{*shell*} (as well as others used by more obscure Emacs packages).
238This is why @kbd{M-x shell} normally switches to the @samp{*shell*}
239buffer in the selected window.  If you delete this element from the
240value of @code{same-window-buffer-names}, the behavior of @kbd{M-x
241shell} will change---it will pop up the buffer in another window
242instead.
243
244@vindex same-window-regexps
245  You can specify these buffers more generally with the variable
246@code{same-window-regexps}.  Set it to a list of regular expressions;
247then any buffer whose name matches one of those regular expressions is
248displayed by switching to it in the selected window.  (Once again, this
249applies only to buffers that normally get displayed for you in a
250separate window.)  The default value of this variable specifies Telnet
251and rlogin buffers.
252
253  An analogous feature lets you specify buffers which should be
254displayed in their own individual frames.  @xref{Special Buffer Frames}.
255
256@node Change Window
257@section Deleting and Rearranging Windows
258
259@table @kbd
260@item C-x 0
261Delete the selected window (@code{delete-window}).  The last character
262in this key sequence is a zero.
263@item C-x 1
264Delete all windows in the selected frame except the selected window
265(@code{delete-other-windows}).
266@item C-x 4 0
267Delete the selected window and kill the buffer that was showing in it
268(@code{kill-buffer-and-window}).  The last character in this key
269sequence is a zero.
270@item C-x ^
271Make selected window taller (@code{enlarge-window}).
272@item C-x @}
273Make selected window wider (@code{enlarge-window-horizontally}).
274@item C-x @{
275Make selected window narrower (@code{shrink-window-horizontally}).
276@item C-x -
277Shrink this window if its buffer doesn't need so many lines
278(@code{shrink-window-if-larger-than-buffer}).
279@item C-x +
280Make all windows the same height (@code{balance-windows}).
281@end table
282
283@kindex C-x 0
284@findex delete-window
285  To delete a window, type @kbd{C-x 0} (@code{delete-window}).  (That is
286a zero.)  The space occupied by the deleted window is given to an
287adjacent window (but not the minibuffer window, even if that is active
288at the time).  Once a window is deleted, its attributes are forgotten;
289only restoring a window configuration can bring it back.  Deleting the
290window has no effect on the buffer it used to display; the buffer
291continues to exist, and you can select it in any window with @kbd{C-x
292b}.
293
294@findex kill-buffer-and-window
295@kindex C-x 4 0
296  @kbd{C-x 4 0} (@code{kill-buffer-and-window}) is a stronger command
297than @kbd{C-x 0}; it kills the current buffer and then deletes the
298selected window.
299
300@kindex C-x 1
301@findex delete-other-windows
302  @kbd{C-x 1} (@code{delete-other-windows}) is more powerful in a
303different way; it deletes all the windows except the selected one (and
304the minibuffer); the selected window expands to use the whole frame
305except for the echo area.
306
307@kindex C-x ^
308@findex enlarge-window
309@kindex C-x @}
310@findex enlarge-window-horizontally
311@vindex window-min-height
312@vindex window-min-width
313  To readjust the division of space among vertically adjacent windows,
314use @kbd{C-x ^} (@code{enlarge-window}).  It makes the currently
315selected window one line bigger, or as many lines as is specified
316with a numeric argument.  With a negative argument, it makes the
317selected window smaller.  @kbd{C-x @}}
318(@code{enlarge-window-horizontally}) makes the selected window wider by
319the specified number of columns.  @kbd{C-x @{}
320(@code{shrink-window-horizontally}) makes the selected window narrower
321by the specified number of columns.
322
323  When you make a window bigger, the space comes from its peers.  If
324this makes any window too small, it is deleted and its space is given
325to an adjacent window.  The minimum size is specified by the variables
326@code{window-min-height} and @code{window-min-width}.
327
328@kindex C-x -
329@findex shrink-window-if-larger-than-buffer
330  The command @kbd{C-x -} (@code{shrink-window-if-larger-than-buffer})
331reduces the height of the selected window, if it is taller than
332necessary to show the whole text of the buffer it is displaying.  It
333gives the extra lines to other windows in the frame.
334
335@kindex C-x +
336@findex balance-windows
337  You can also use @kbd{C-x +} (@code{balance-windows}) to even out the
338heights of all the windows in the selected frame.
339
340  Mouse clicks on the mode line provide another way to change window
341heights and to delete windows.  @xref{Mode Line Mouse}.
342
343@node Window Convenience
344@section Window Handling Convenience Features and Customization
345
346@findex winner-mode
347@cindex Winner mode
348@cindex mode, Winner
349@cindex undoing window configuration changes
350@cindex window configuration changes, undoing
351  @kbd{M-x winner-mode} is a global minor mode that records the
352changes in the window configuration (i.e. how the frames are
353partitioned into windows), so that you can ``undo'' them.  To undo,
354use @kbd{C-c left} (@code{winner-undo}).  If you change your mind
355while undoing, you can redo the changes you had undone using @kbd{C-c
356right} (@code{M-x winner-redo}).  Another way to enable Winner mode is
357by customizing the variable @code{winner-mode}.
358
359@cindex Windmove package
360@cindex directional window selection
361@findex windmove-right
362@findex windmove-default-keybindings
363  The Windmove commands move directionally between neighboring windows in
364a frame.  @kbd{M-x windmove-right} selects the window immediately to the
365right of the currently selected one, and similarly for the ``left,'' ``up,''
366and ``down'' counterparts.  @kbd{M-x windmove-default-keybindings} binds
367these commands to @kbd{S-right} etc.  (Not all terminals support shifted
368arrow keys, however.)
369
370  Follow minor mode (@kbd{M-x follow-mode}) synchronizes several
371windows on the same buffer so that they always display adjacent
372sections of that buffer.  @xref{Follow Mode}.
373
374@vindex scroll-all-mode
375@cindex scrolling windows together
376@cindex Scroll-all mode
377@cindex mode, Scroll-all
378  @kbd{M-x scroll-all-mode} provides commands to scroll all visible
379windows together.  You can also turn it on by customizing the variable
380@code{scroll-all-mode}.  The commands provided are @kbd{M-x
381scroll-all-scroll-down-all}, @kbd{M-x scroll-all-page-down-all} and
382their corresponding ``up'' equivalents.  To make this mode useful,
383you should bind these commands to appropriate keys.
384
385@ignore
386   arch-tag: 8bea7453-d4b1-49b1-9bf4-cfe4383e1113
387@end ignore
388