Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 38 ยท Editing and Buffers

Windows and Frames

Split the Emacs screen into windows with C-x 2 and C-x 3, switch with C-x o, resize and balance, scroll the other window, open new frames, and undo layouts with winner-mode.

You often want to see two things at once: code and its tests, a manual and your notes, a file and a shell. Emacs does this by splitting a frame into windows. Each window shows one buffer, and you can show the same buffer in several windows to look at different parts of it. For more space, or several monitors, you open another frame.

Splitting and closing windows

Keys Command Effect
C-x 2 split-window-below Split into top and bottom
C-x 3 split-window-right Split into left and right
C-x o other-window Move the cursor to the next window (cycles)
C-x 1 delete-other-windows Keep only this window
C-x 0 delete-window Close this window
C-x 4 0 kill-buffer-and-window Kill the buffer and close its window
C-x 4 4 other-window-prefix The next command shows its buffer in another window (Emacs 28+)
C-x 4 b, C-x 4 f Switch buffer / find file in the other window

Remember the numbers: 1 is "just this one", 0 is "get rid of this", 2 is a horizontal divide and 3 a vertical divide. Splitting does not copy anything: both windows show the same buffer at first, and you pick another with C-x b.

Dividing lines: when you split in a very small window, Emacs refuses (the variables split-height-threshold and split-width-threshold decide). You can also click the mode line with the mouse and drag it to resize.

flowchart LR
  A["One window"] -->|"C-x 3"| B["Left | Right"]
  B -->|"C-x 2 in right"| C["Left | Top-right / Bottom-right"]
  C -->|"C-x 1"| A

Splitting a window creates a tree of windows inside one frame.

Resizing

Keys Effect
C-x ^ Make the window taller
C-x { / C-x } Narrower / wider
C-x - Shrink the window if it is larger than its text
C-x + Balance all windows to equal size

Each of the resize commands takes a prefix argument: C-u 5 C-x ^ adds five lines. After you press C-x ^ once, the repeat-mode feature lets you press ^ repeatedly.

JS Stand-in: a window layout tree

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Working with the other window

When two windows show different buffers, you often read in one and edit in the other. C-M-v scrolls the other window down and C-M-S-v (or C-M-- C-M-v) scrolls it up, without moving the cursor. C-x 4 C-f opens a file there, and a prefix such as C-x 4 4 before a command sends its output to the other window.

Many commands that produce lists, such as grep, compile, help and Occur, pop up their results in a window and reuse it. Press q in such a window to close it. C-x 1 brings back full screen.

Moving without C-x o

If you have more than two windows, C-x o cycles through all of them, which can be slow. Enable windmove to move with Shift and the arrow keys: (windmove-default-keybindings) in your init file. Another approach is the package ace-window, which labels each window with a number.

Undoing layout changes: winner-mode

M-x winner-mode records every layout. Then C-c <left> goes back to the previous layout and C-c <right> forwards. When a temporary window such as *Help* pushes your windows around, winner restores everything. It ships with Emacs and costs nothing to keep on: (winner-mode 1).

JS Stand-in: winner-mode history of layouts

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Frames

A frame is an operating-system window (or a full terminal screen). Use frames for multiple monitors or to keep separate tasks apart.

Keys Command Effect
C-x 5 2 make-frame-command Create a new frame
C-x 5 0 delete-frame Close this frame
C-x 5 o other-frame Select another frame
C-x 5 1 delete-other-frames Close all other frames
C-x 5 f find-file-other-frame Open a file in a new frame

Newer Emacs versions also provide tab bar mode (M-x tab-bar-mode, with C-x t 2 to create a tab and C-x t o to switch). Tabs store a window layout each, so you can switch between whole "workspaces" in one frame, a lightweight alternative to many frames.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which key splits the window into left and right halves?

    C-x 3 splits side by side; C-x 2 splits top and bottom.
  2. 2. Which key keeps only the current window?

    C-x 1 is delete-other-windows; C-x 0 deletes only this window.
  3. 3. What does C-M-v do?

    It scrolls the other window without moving your cursor.
  4. 4. What does winner-mode provide?

    C-c <left> and C-c <right> move through earlier and later window configurations.

Summary

  • A frame (OS window) holds a tree of windows; C-x 2 and C-x 3 split, C-x o moves, C-x 1 and C-x 0 close.
  • C-M-v scrolls the other window; C-x 4 commands target it.
  • winner-mode undoes layout changes; windmove and tabs add faster movement.
  • C-x 5 commands manage frames.

Next: Rectangles, Registers and Keyboard Macros