This page is a tutorial on managing split windows in emacs.
First, know the basics:
| Purpose | Command Name | Key |
|---|---|---|
| split pane top/bottom | split-window-below | 【Ctrl+x 2】 |
| split pane left/right | split-window-right | 【Ctrl+x 3】 |
| un-split all | delete-other-windows | 【Ctrl+x 1】 |
| remove current pane | delete-window | 【Ctrl+x 0】 |
| cycle cursor to next pane | other-window | 【Ctrl+x o】 |
Note: in emacs, a “window” is technically called a “frame”, while a pane in a split window is called “window”.
You can adjust the split pane size by dragging on the mode line bar in the middle. For windows split left/right, drag the bar at the split point.
Or, you can use keys. Here's the commands:
| Command | Key | Purpose |
|---|---|---|
enlarge-window | 【Ctrl+x ^】 | increase height |
shrink-window | ◇ | decrease height |
enlarge-window-horizontally | 【Ctrl+x }】 | increase width |
shrink-window-horizontally | 【Ctrl+x {】 | decrease width |
shrink-window-if-larger-than-buffer | 【Ctrl+x -】 | shrink a window to fit its content. |
balance-windows | 【Ctrl+x +】 | make all windows same width/height |
Most of these commands also take a argument. You can call universal-argument 【Ctrl+u】 first then type a number. If you use these commands often, you probably want to give them a easier key. 〔☛ Emacs: How to Define Keys〕
winner-mode lets you revert to a previous pane configuration.
(in emacs 23.2 (2010) or later)
Example use:
winner-mode to turn it on.split-window-vertically.split-window-horizontally.delete-other-windows.winner-undo 【Ctrl+c ←】. There's also winner-redo 【Ctrl+c →】.If you want this functionality always, put in your emacs init file:
;; ability to revert split pane config. Call winner-undo 【Ctrl+c ←】 and winner-redo 【Ctrl+c →】 (winner-mode 1) ; in GNU emacs 23.2
You can save split-window config to register, like this:
window-configuration-to-register 【Ctrl+x r w】 (then give it a letter or digit as name).jump-to-register 【Ctrl+x r j】 to restore a previously saved configuration.Note: this doesn't work when you restart emacs, even if you have desktop-save-mode on.
Use 〔revive.el〕 by HIROSE Yuuji. It's in emacs MELPA package repository. 〔☛ A Guide on Emacs 24 Package System〕
First, install it. Then, call save-current-configuration. It'll generate a file at 〔~/.revive.el〕.
To restore, call resume.
If you want to swap buffers among your current split panes, install 〔buffer-move.el〕 by Lucas Bonnet. It's in emacs package repository MELPA 〔☛ A Guide on Emacs 24 Package System〕
(thx to Mark Hepburn and John D Cook)
See: Emacs: You Have Widescreen? Have Screen Flow Side by Side
By default, you can move cursor to the next pane by calling other-window 【Ctrl+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 (windmove-default-keybindings) ;; when cursor is on edge, move to the other side, as in a toroidal space (setq windmove-wrap-around t )
alternatively, you can put the following in your emacs init file:
(defun move-cursor-next-pane () "Move cursor to the next pane." (interactive) (other-window 1)) (defun move-cursor-previous-pane () "Move cursor to the previous pane." (interactive) (other-window -1))
You can give them easy keys, such as {【Ctrl+3】, 【Ctrl+4】}. 〔☛ Emacs: How to Define Keys〕