Emacs: Manage Split Windows

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

This page is a tutorial on managing split windows in emacs.

emacs split windows basics 2015
Emacs: Split Windows Basics

Adjusting Split Pane Size

You can adjust the split pane size by mouse dragging the mode line (status bar). For windows split left/right, drag the split position on the horizontal mode line.

Or, you can use keys. Here's the commands:

Emacs Pane Size Adjustment Commands
enlarge-windowCtrl+x ^increase height
shrink-windowdecrease height
enlarge-window-horizontallyCtrl+x }increase width
shrink-window-horizontallyCtrl+x {decrease width
shrink-window-if-larger-than-bufferCtrl+x -shrink a window to fit its content.
balance-windowsCtrl+x + make all panes same width/height

Most of these commands also take a argument. Call universal-argumentCtrl+u】 first then type a number, then, call the command that adjust window size.

If you use these commands often, you probably want to give them a easier key. 〔➤ Emacs: How to Define Keys

Save Split-window Config for Current Session


winner-mode lets you revert to a previous pane configuration. (in emacs 23.2 〔➤ Emacs 23.2 Features (released 2010-05)〕)

Example use:

  1. Call winner-mode to turn it on.
  2. Call split-window-below.
  3. Call split-window-right.
  4. Now, remove all split panes by calling delete-other-windows.
  5. Now, you can go back to previous split pane config by calling winner-undoCtrl+c 】. There's also winner-redoCtrl+c 】.

If you want this functionality always, put in your emacs init file:

;; feature for revert split pane config. Call winner-undo 【Ctrl+c ←】 and winner-redo 【Ctrl+c →】
(winner-mode 1) ; in GNU emacs 23.2

Save Split-Window Config

You can save split-window config to register, like this:

Note: this doesn't work when you restart emacs, even if you have desktop-save-mode on.

Save Split-window Config Across Sessions

In Emacs 24.4, if you restart emacs, previous session's windows and split-panes are automatically restored. This is done by desktop-save-mode. 〔➤ Emacs: Save/Restore Opened Files, Windows Configuration: desktop-mode〕 〔➤ Emacs 24.4 New Features (released 2014-10)

Flow Buffer Side-by-Side

See: Emacs: Widescreen? Have Screen Flow Side by Side

Move Cursor to Different Panes by Arrow

By default, you can move cursor to the next pane by calling other-windowCtrl+x o】. The default key is hard to use. Also, there's no key to move cursor to previous pane.

You can put the following in your emacs init file. It'll let you move cursor by {【⇧ Shift+】, 【⇧ Shift+】, 【⇧ Shift+】, 【⇧ Shift+】}.

However, you'll lose shift select.

;; use Shift+arrow_keys to move cursor around split panes

;; when cursor is on edge, move to the other side, as in a torus space
(setq windmove-wrap-around t )

Workflow Tip: Full-Screen vs Multiple Window

It is often problematic trying to keep your split pane config, because emacs constantly pop-up new panes in help results or search results.

One simple solution is to not rely on split pane config within 1 big emacs window. Instead, use a workflow with 2 or 3 separate windows.


Thanks to Mark Hepburn and John D Cook.

Like it? Buy Xah Emacs Tutorial.
blog comments powered by Disqus