Emacs: Save Split Windows Configuration

By Xah Lee. Date: . Last updated: .

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

If you don't know how to split windows, see Emacs: Split Windows

Save Split-window Config for Current Session

winner-mode

winner-mode lets you revert to a previous pane configuration. (in emacs 23.2 [see Emacs 23.2 Features (released 2010-05)])

Example use:

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

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

;; restore split pane config, winner-undo, winner-redo
(winner-mode 1) ; in GNU emacs 23.2

Using Register to 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.

[see Emacs: Restore Opened Files, Windows Config]

[see Emacs 24.4 New Features (released 2014-10)]

Move Cursor to Different Panes by Arrow

By default, you can move cursor to the next pane by Alt+x 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.

(progn
  (require 'windmove)
  ;; use Shift+arrow_keys to move cursor around split panes
  (windmove-default-keybindings)
  ;; when cursor is on edge, move to the other side, as in a torus space
  (setq windmove-wrap-around t )
)

Thanks to Mark Hepburn and John D Cook.

Manage Windows Topic

  1. Emacs: Split Windows
  2. Emacs: Save Split Windows Configuration
  3. Emacs: Effective Windows Management
  4. Emacs: Make Buffer Flow Side-by-Side
  5. Emacs: Restore Opened Files, Windows Config
  6. Emacs: Set Default Window Size
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.