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