32

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?

7
  • 4
    Are we intentionally duplicating questions from SO? stackoverflow.com/questions/4987760/… Commented Oct 1, 2014 at 22:07
  • @phils, No I was not. But I will make a link to the post. Thank you for the insight. Commented Oct 1, 2014 at 22:08
  • beyond that, that one was a little bit too easy :) Commented Oct 1, 2014 at 22:17
  • 1
    Gee, great edit @King. Now this question has become really different from the one you copied... Commented Oct 1, 2014 at 22:32
  • 2
    it make me think that, the emacs related questions on SO should be migrated. It will have avoided the (tiny) uproar Commented Oct 2, 2014 at 0:12

6 Answers 6

67

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)

4
  • 1
    +1 for the shrinking command. I was looking for the way to shrink by a single line. What is C-u? Commented Sep 18, 2016 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 ^ Commented Sep 20, 2016 at 7: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 ^. Commented Aug 1, 2019 at 8:27
  • See @amit-tendulkar suggestion for repeating commands conveniently: emacs.stackexchange.com/a/82713/9311 Commented Jan 29 at 6:55
13

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.

5

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.

1
  • great idea to make another window smaller by enlarging the one above it! Commented Sep 18, 2016 at 22:29
2

A late addition to the above question but I think this is useful.

In addition to what @Nsukami has written, a nice trick after issuing any of the windows resize commands is the repeat command that can be initiated using C-x z.

After that, keep on pressing z to resize in the same direction further.

This is very useful to keep on resizing till the window reaches the size you want.

Interested folks can go through this answer for more tips: https://stackoverflow.com/a/4988206/8813473

1
  • 1
    That is golden! I'm surprised this suggestion hasn't received more votes. Commented Jan 29 at 6:53
1

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)

1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.