27

If I have Emacs split horizontally and on top I'm editing elisp code and on the bottom I am in the shell. By default, Emacs makes the two windows equal in size, but I'd like the shell buffer smaller. I was wondering how I could do that.

Original question asked by Steve on SO: How to Change size of split screen emacs windows?

programking
  • 7,064
  • 9
  • 41
  • 62

5 Answers5

50

C-x- (shrink-window-if-larger-than-buffer) to shrink a window to fit its content.

C-x+ (balance-windows) to make windows the same heights and widths.

C-x^ (enlarge-window) to increase height by 1 line, or the prefix arg value. A negative arg shrinks the window. Example: C-u - 3 C-x ^

C-x{ (shrink-window-horizontally)

C-x} (enlarge-window-horizontally)

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
Nsukami _
  • 6,341
  • 2
  • 22
  • 35
  • 1
    **+1** for the shrinking command. I was looking for the way to shrink by a single line. What is `C-u`? – Vass Sep 18 '16 at 22:28
  • 4
    @Vass `C-u` begin a numeric argument for the following command. If you want to increase 5 times, instead of typing, 5 times, the same command, you type `C-u 5` `C-x ^` – Nsukami _ Sep 20 '16 at 07:01
  • 2
    It's also worth noting that `C-u` default value is 4, meaning that `C-u C-x ^` will do the same as `C-u 4 C-x ^`. – ramnes Aug 01 '19 at 08:27
12

I would also recommend checking out either the windresize package from ELPA, or the windsize package from MELPA.

With windresize, you can do M-x windresize and then use the arrow keys to move window borders easily, hitting ENTER when you're done.

Lee H
  • 2,697
  • 1
  • 16
  • 31
4

You can use C-x^ (enlarge-window) in the upper window to make it larger (and thus make the lower window smaller).

Using the mouse, you can also drag the modeline of the upper window to resize it.

François Févotte
  • 5,917
  • 1
  • 24
  • 37
0

I've ever written a simple minor-mode (for my personal usage) to interactively resize-frame. I think this should be convenient.

https://gist.github.com/kuanyui/65a408d393871048771c

M-x resize-frameto enable the resize-frame minor-mode:

  1. Press arrow keys to adjust size horizontally/vertically.
  2. Press any other keys to disable.
kuanyui
  • 1,020
  • 6
  • 16
0

Also note that just like in a window system, you can use the mouse with xterm-mouse-mode to drag the window divider.

Note that this seems to sometimes depend a bit on the actual xterm or xterm-like program, and iirc in older Emacsen it wasn't reliable past about the 100th column unless you played with the TERM environment variable a bit, but in my Emacs 24.2.1 it works fine with emacs -nw -q (ie. totally ignoring my .emacs and manually enabling xterm-mouse-mode with M-x xterm-mouse-mode)

Update: FYI for completeness I'll point out this also works for vertical dividers (ie. when you have split with C-x 3)

Mark
  • 1,409
  • 1
  • 15
  • 20