[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O. Multiple Windows

Emacs can split a frame into two or many windows. Multiple windows can display parts of different buffers, or different parts of one buffer. Multiple frames always imply multiple windows, because each frame has its own set of windows. Each window belongs to one and only one frame.

O.1 Concepts of Emacs Windows  Introduction to Emacs windows.
O.2 Splitting Windows  New windows are made by splitting existing windows.
O.3 Using Other Windows  Moving to another window or doing something to it.
O.4 Displaying in Another Window  Finding a file or buffer in another window.
O.5 Forcing Display in the Same Window  Forcing certain buffers to appear in the selected window rather than in another window.
O.6 Deleting and Rearranging Windows  Deleting windows and changing their sizes.
O.7 Window Handling Convenience Features and Customization  Convenience functions for window handling.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.1 Concepts of Emacs Windows

Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears. But the windows showing the same buffer can show different parts of it, because each window has its own value of point.

At any time, one of the windows is the selected window; the buffer this window is displaying is the current buffer. The terminal's cursor shows the location of point in this window. Each other window has a location of point as well, but since the terminal has only one cursor there is no way to show where those locations are. When multiple frames are visible in X, each frame has a cursor which appears in the frame's selected window. The cursor in the selected frame is solid; the cursor in other frames is a hollow box.

Commands to move point affect the value of point for the selected Emacs window only. They do not change the value of point in any other Emacs window, even one showing the same buffer. The same is true for commands such as C-x b to change the current buffer in the selected window; they do not affect other windows at all. However, there are other commands such as C-x 4 b that select a different window and switch buffers in it. Also, all commands that display information in a window, including (for example) C-h f (describe-function) and C-x C-b (list-buffers), work by switching buffers in a nonselected window without affecting the selected window.

When multiple windows show the same buffer, they can have different regions, because they can have different values of point. However, they all have the same value for the mark, because each buffer has only 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 is displayed in the window. See section B.3 The Mode Line, for full details on the mode line.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.2 Splitting Windows

C-x 2
Split the selected window into two windows, one above the other (split-window-vertically).
C-x 3
Split the selected window into two windows positioned side by side (split-window-horizontally).
C-Mouse-2
In the mode line or scroll bar of a window, split that window.

The command C-x 2 (split-window-vertically) breaks the selected window into two windows, one above the other. Both windows start out displaying the same buffer, with the same value of point. By default the two windows each get half the height of the window that was split; a numeric argument specifies how many lines to give to the top window.

C-x 3 (split-window-horizontally) breaks the selected window into two side-by-side windows. A numeric argument specifies how many columns to give the one on the left. A line of vertical bars separates the two windows. Windows that are not the full width of the screen have mode lines, but they are truncated. On terminals where Emacs does not support highlighting, truncated mode lines sometimes do not appear in inverse video.

You can split a window horizontally or vertically by clicking C-Mouse-2 in the mode line or the scroll bar. (This does not work in scroll bars implemented by X toolkits.) The line of splitting goes 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 scroll bar, the mode line of the split window is side by side with your click.

When a window is less than the full width, text lines too long to fit are frequent. Continuing all those lines might be confusing. The variable truncate-partial-width-windows can be set non-nil to force truncation in all windows less than the full width of the screen, independent of the buffer being displayed and its value for truncate-lines. See section D.8 Continuation Lines.

Horizontal scrolling is often used in side-by-side windows. See section J. Controlling the Display.

If split-window-keep-point is non-nil, the default, both of the windows resulting from C-x 2 inherit the value of point from the window that was split. This means that scrolling is inevitable. If this variable is nil, then C-x 2 tries to avoid scrolling the text currently visible on the screen, by putting point in each window at a position already visible in the window. It also selects whichever window contain the screen line that the cursor was previously on. Some users prefer the latter mode on slow terminals.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.3 Using Other Windows

C-x o
Select another window (other-window). That is o, not zero.
C-M-v
Scroll the next window (scroll-other-window).
M-x compare-windows
Find next place where the text in the selected window does not match the text in the next window.
Mouse-1
Mouse-1, in a window's mode line, selects that window but does not move point in it (mouse-select-window).

To select a different window, click with Mouse-1 on its mode line. With the keyboard, you can switch windows by typing C-x o (other-window). That is an o, for "other," not a zero. When there are more than two windows, this command moves through all the windows in a cyclic order, generally top to bottom and left to right. After the rightmost and bottommost window, it goes back to the one at the upper left corner. A numeric argument means to move several steps in the cyclic order of windows. A negative argument moves around the cycle in the opposite order. When the minibuffer is active, the minibuffer is the last window in the cycle; you can switch from the minibuffer window to one of the other windows, and later switch back and finish supplying the minibuffer argument that is requested. See section E.2 Editing in the Minibuffer.

The usual scrolling commands (see section J. Controlling the Display) apply to the selected window only, but there is one command to scroll the next window. C-M-v (scroll-other-window) scrolls the window that C-x o would select. It takes arguments, positive and negative, like C-v. (In the minibuffer, C-M-v scrolls the window that contains the minibuffer help display, if any, rather than the next window in the standard cyclic order.)

The command M-x compare-windows lets you compare two files or buffers visible in two windows, by moving through them to the next mismatch. See section M.9 Comparing Files, for details.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.4 Displaying in Another Window

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 that window. Different C-x 4 commands have different ways of finding the buffer to select.

C-x 4 b bufname RET
Select buffer bufname in another window. This runs switch-to-buffer-other-window.
C-x 4 C-o bufname RET
Display buffer bufname in another window, but don't select that buffer or that window. This runs display-buffer.
C-x 4 f filename RET
Visit file filename and select its buffer in another window. This runs find-file-other-window. See section M.2 Visiting Files.
C-x 4 d directory RET
Select a Dired buffer for directory directory in another window. This runs dired-other-window. See section AB. Dired, the Directory Editor.
C-x 4 m
Start composing a mail message in another window. This runs mail-other-window; its same-window analogue is C-x m (see section Z. Sending Mail).
C-x 4 .
Find a tag in the current tags table, in another window. This runs find-tag-other-window, the multiple-window variant of M-. (see section W.2 Tags Tables).
C-x 4 r filename RET
Visit file filename read-only, and select its buffer in another window. This runs find-file-read-only-other-window. See section M.2 Visiting Files.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.5 Forcing Display in the Same Window

Certain Emacs commands switch to a specific buffer with special contents. For example, M-x shell switches to a buffer named `*Shell*'. By convention, all these commands are written to pop up the buffer in a separate window. But you can specify that certain of these buffers should appear in the selected window.

If you add a buffer name to the list same-window-buffer-names, the effect is that such commands display that particular buffer by switching to it in the selected window. For example, if you add the element "*grep*" to the list, the grep command will display its output buffer in the selected window.

The default value of same-window-buffer-names is not nil: it specifies buffer names `*info*', `*mail*' and `*shell*' (as well as others used by more obscure Emacs packages). This is why M-x shell normally switches to the `*shell*' buffer in the selected window. If you delete this element from the value of same-window-buffer-names, the behavior of M-x shell will change--it will pop up the buffer in another window instead.

You can specify these buffers more generally with the variable same-window-regexps. Set it to a list of regular expressions; then any buffer whose name matches one of those regular expressions is displayed by switching to it in the selected window. (Once again, this applies only to buffers that normally get displayed for you in a separate window.) The default value of this variable specifies Telnet and rlogin buffers.

An analogous feature lets you specify buffers which should be displayed in their own individual frames. See section P.11 Special Buffer Frames.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.6 Deleting and Rearranging Windows

C-x 0
Delete the selected window (delete-window). The last character in this key sequence is a zero.
C-x 1
Delete all windows in the selected frame except the selected window (delete-other-windows).
C-x 4 0
Delete the selected window and kill the buffer that was showing in it (kill-buffer-and-window). The last character in this key sequence is a zero.
C-x ^
Make selected window taller (enlarge-window).
C-x }
Make selected window wider (enlarge-window-horizontally).
C-x {
Make selected window narrower (shrink-window-horizontally).
C-x -
Shrink this window if its buffer doesn't need so many lines (shrink-window-if-larger-than-buffer).
C-x +
Make all windows the same height (balance-windows).
Drag-Mouse-1
Dragging a window's mode line up or down with Mouse-1 changes window heights.
Mouse-2
Mouse-2 in a window's mode line deletes all other windows in the frame (mouse-delete-other-windows).
Mouse-3
Mouse-3 in a window's mode line deletes that window (mouse-delete-window), unless the frame has only one window, in which case it buries the current buffer instead and switches to another buffer.

To delete a window, type C-x 0 (delete-window). (That is a zero.) The space occupied by the deleted window is given to an adjacent window (but not the minibuffer window, even if that is active at the time). Once a window is deleted, its attributes are forgotten; only restoring a window configuration can bring it back. Deleting the window has no effect on the buffer it used to display; the buffer continues to exist, and you can select it in any window with C-x b.

C-x 4 0 (kill-buffer-and-window) is a stronger command than C-x 0; it kills the current buffer and then deletes the selected window.

C-x 1 (delete-other-windows) is more powerful in a different way; it deletes all the windows except the selected one (and the minibuffer); the selected window expands to use the whole frame except for the echo area.

You can also delete a window by clicking on its mode line with Mouse-2, and delete all the windows in a frame except one window by clicking on that window's mode line with Mouse-3.

The easiest way to adjust window heights is with a mouse. If you press Mouse-1 on a mode line, you can drag that mode line up or down, changing the heights of the windows above and below it.

To readjust the division of space among vertically adjacent windows, use C-x ^ (enlarge-window). It makes the currently selected window get one line bigger, or as many lines as is specified with a numeric argument. With a negative argument, it makes the selected window smaller. C-x } (enlarge-window-horizontally) makes the selected window wider by the specified number of columns. C-x { (shrink-window-horizontally) makes the selected window narrower by the specified number of columns.

When you make a window bigger, the space comes from one of its neighbors. If this makes any window too small, it is deleted and its space is given to an adjacent window. The minimum size is specified by the variables window-min-height and window-min-width.

The command C-x - (shrink-window-if-larger-than-buffer) reduces the height of the selected window, if it is taller than necessary to show the whole text of the buffer it is displaying. It gives the extra lines to other windows in the frame.

You can also use C-x + (balance-windows) to even out the heights of all the windows in the selected frame.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

O.7 Window Handling Convenience Features and Customization

M-x winner-mode is a global minor mode that records the changes in the window configuration (i.e. how the frames are partitioned into windows), so that you can "undo" them. To undo, use C-x left (winner-undo). If you change your mind while undoing, you can redo the changes you had undone using C-x right (M-x winner-redo). Another way to enable Winner mode is by customizing the variable winner-mode.

The Windmove commands move directionally between neighboring windows in a frame. M-x windmove-right selects the window immediately to the right of the currently selected one, and similarly for the "left," "up," and "down" counterparts. M-x windmove-default-keybindings binds these commands to S-right etc. (Not all terminals support shifted arrow keys, however.)

Follow minor mode (M-x follow-mode) synchronizes several windows on the same buffer so that they always display adjacent sections of that buffer. See section J.8 Follow Mode.

M-x scroll-all-mode provides commands to scroll all visible windows together. You can also turn it on by customizing the variable scroll-all-mode. The commands provided are M-x scroll-all-scroll-down-all, M-x scroll-all-page-down-all and their corresponding "up" equivalents. To make this mode useful, you should bind these commands to appropriate keys.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Dohn Arms on March, 6 2005 using texi2html