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