Emacs: Split Windows Basics

By Xah Lee. Date: . Last updated: .
emacs split windows basics 2015
emacs split windows.
Emacs Split Window Commands
PurposeCommand NameKey
split top/bottomsplit-window-belowCtrl+x 2
split left/rightsplit-window-rightCtrl+x 3
unsplit alldelete-other-windowsCtrl+x 1
remove current panedelete-windowCtrl+x 0
move cursor to next paneother-windowCtrl+x o

Note: see the command delete-other-windows? It doesn't delete “windows”, but remove the other “panes”.

In emacs's manual,

Easy Keys for Split Window

Split/unsplit window panes are some of the most frequently used commands, because emacs often generates output in a splits window. [see Emacs's Command Frequency Statistics]

I recommend setting easy keys for them.

Put the following in your emacs init file.

;; easy keys for split windows
(global-set-key (kbd "M-3") 'delete-other-windows) ; 【Alt+3】 unsplit all
(global-set-key (kbd "M-4") 'split-window-below)
(global-set-key (kbd "M-$") 'split-window-right)
(global-set-key (kbd "M-RET") 'other-window) ; 【Alt+Return】 move cursor to next pane
(global-set-key (kbd "M-0") 'delete-window)  ; remove current pane

[see Emacs: How to Define Keys]

Note: I do not recommend keys like 【Alt+1】 or 【Ctrl+1】 , because that got me Repetitive Strain Injury. [see Programer Hand Health: vi Esc Key Syndrome]

Adjust 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
CommandKeyPurpose
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. Alt+x 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 easy key such as F8, so you can hold it to enlarge/shrink window size. [see Emacs: How to Define Keys]

Save Split Windows Configuration

Emacs: Save Split Windows Configuration

Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs