43

In my terminal (I have terminator) I can use the key combinations Ctrl + and Ctrl - to increase / decrease the font size.

In emacs I can do the following to set the font-height:

(set-face-attribute 'default nil :height 70)

But I do not know how to increase / decrease it. How could I easily add this to my emacs configuration?

Drew
  • 29,895
  • 7
  • 74
  • 104
blueFast
  • 41,341
  • 63
  • 198
  • 344
  • possible duplicate of [Emacs font sizing](http://stackoverflow.com/q/2091881/729907). – Drew Feb 04 '14 at 15:02
  • possible duplicate of [Emacs zoom in/zoom out](http://stackoverflow.com/q/5533110/729907) – Drew Feb 04 '14 at 15:04
  • 1
    possible duplicate of [Emacs zoom in/out globally](http://stackoverflow.com/q/18783227/729907). – Drew Feb 04 '14 at 15:06

5 Answers5

116

I think you want C-x C-+ or C-x C--.

Stefan
  • 27,908
  • 4
  • 53
  • 82
18

I'd suggest:

(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)

While the default keybindings mentioned by @Stefan do the job, I like to have the more commonly established keybindings as well. Btw, C-x C-= increases the font size as well and C-x C-0 restores the default font size.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
  • 3
    FWIW: That removes the possibility of using `C--` as a negative prefix arg, something that most people use very often. – Drew Feb 04 '14 at 14:34
  • There's always `M--` (which is arguably easier to press as it involves the use of just one pinky). – Bozhidar Batsov Feb 04 '14 at 14:52
16

C-x C-+ and C-x C-- gives you only part of the answer: text scaling a buffer.

You can change the font size for a given frame (across all windows/buffers in that frame), or you can change the (apparent) font size for a given buffer (across all windows/frames). The latter is called text scaling, and it is what vanilla Emacs C-x C-+ and C-x C-- give you.

Library zoom-frm.el gives you both kinds of zooming with the same command. Bind the same command, zoom-in/out, to both C-x C-- and C-x C-+. It zooms either the frame or the buffer, in and out. A plain prefix arg toggles between zooming frames and zooming buffers. Bind it also to mouse keys (I use S-mouse-1 (in) and C-S-mouse-1 (out) and to the mouse wheel (in/out).

Library face-remap+.el fixes text scaling so that the window size shrinks or grows to accommodate the changing text size, which can free up screen real estate.

This EmacsWiki page has more info about this frequently asked question.

Matt
  • 7
  • 1
  • 4
Drew
  • 29,895
  • 7
  • 74
  • 104
6

Check purcell's .emacs.d and his font utils.

Saddle Point
  • 3,074
  • 4
  • 23
  • 33
  • 1
    Steve Purcell has factored his text scale utilities into a nice little minor mode: [purcell/default-text-scale](https://github.com/purcell/default-text-scale). It's available in Melpa. – mgalgs Dec 12 '15 at 23:33
6

And for mouse wheel changes with control key pressed:

(global-set-key [C-mouse-4] '(lambda () (interactive) (text-scale-increase 1)))
(global-set-key [C-mouse-5] '(lambda () (interactive) (text-scale-decrease 1)))

That works okay, but it's buffer local. The following code changes the frame font height for all buffers with control + mouse wheel/trackpad:

(defun change-font-height (delta)
  (set-face-attribute 'default 
                      (selected-frame)
                      :height (+ (face-attribute 'default :height) delta)))
(global-set-key [C-mouse-4] '(lambda () (interactive) (change-font-height +4)))
(global-set-key [C-mouse-5] '(lambda () (interactive) (change-font-height -4)))
Reece
  • 7,616
  • 4
  • 30
  • 46