91

Is there a way to zoom in and out (dynamically change the font size, quite smoothly) on emacs?

sawa
  • 165,429
  • 45
  • 277
  • 381

5 Answers5

145

Try C-x C-+ and C-x C--; that is, Control-x Control-Minus/Control-Plus.

After one combination (C-x C-+ or C-x C--), successives + or - increase or decrease the text scale without typing C-x C- again.

Addition by sawa

I looked up the function that was assigned to the keys mentioned, and found out that they are text-scale-increase and text-scale-decrease. I added the following to my configuration file so that I can do Ctrl+Scroll to zoom in/out. It is useful.

(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
elemakil
  • 3,681
  • 28
  • 53
  • Thanks, it helped. I will try to assign that to scroll wheel (maybe with Ctrl) on the mouse. – sawa Apr 04 '11 at 00:05
  • 2
    You can also call `(text-scale-set LEVEL)` if you know in advance what you want. For instance, I use this to reduce the font size in ibuffer by default: `(add-hook 'ibuffer-mode-hook 'my-ibuffer-mode-hook) (defun my-ibuffer-mode-hook () (text-scale-set -1))` – phils Apr 04 '11 at 04:38
  • For smoothly zooming in and out, I can use the functions that nvm let me know. For having different display modes, phils function maybe good. – sawa Apr 04 '11 at 07:12
  • 3
    Somehow Sawa's wheel up/down command doesn't work for me, but this one does: `(global-set-key (kbd "C-") 'text-scale-increase)` `(global-set-key (kbd "C-") 'text-scale-decrease)` – jule64 May 17 '17 at 09:27
  • It seems that the `minus` must be from the typewriter keys, not the numeric keypad. – Viesturs Apr 02 '18 at 09:57
  • But if you don't have a numeric keypad then you do not have the "-" (minus) key strictly speaking... and C-x C-maj- does not work .. how then do it ? And the same problem for '+' since no dedicated '+' key ! – SheppLogan Apr 14 '22 at 09:18
8

The -very nice- answer of user173973 is binding the functions to non-generic mouse events. That is to say that for example on my windows system, the binding command is not valid.

To use it on windows (or probably anywhere) you can use these generic bindings :

(global-set-key [C-mouse-wheel-up-event]  'text-scale-increase)
(global-set-key  [C-mouse-wheel-down-event] 'text-scale-decrease)
elemakil
  • 3,681
  • 28
  • 53
Peter
  • 47,963
  • 46
  • 132
  • 181
1

This config worked for me:

(global-set-key [C-wheel-up] 'text-scale-increase)
(global-set-key [C-wheel-down] 'text-scale-decrease)
Stacksys
  • 11
  • 2
  • The [C-wheel-up] event also worked for me. However, I found [C-S-wheel-up] more prudent as it's not already assigned by default. – rm -rf Jun 27 '19 at 17:51
1

In addition to sawa's accepted response, I prefer to use the keyboard exclusively. Here are some additions to my init.el file that meet that preference similarly to the short cuts found on Windows/MacOS desktops:

;; enable shortcuts (both keyboard and mouse) for zoom-in/zoom-out
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
(global-set-key [?\C-\+] 'text-scale-increase)
(global-set-key [?\C-\-] 'text-scale-decrease)
0

All windows

You'll often want to change your font size because you're showing something to others. Then you likely want all windows to zoom in (including mode-line). For this, default-text-scale is great.

I bind it as such:

(key-seq-define-global "q-" 'default-text-scale-decrease)
(key-seq-define-global "q+" 'default-text-scale-increase)

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

Quick single window, and back

For a really quick heavy (16x) zoom-in, you can use: C-u C-u C-x C-+

For going to single-window mode, say for a org presentation: C-x 1

Then you can undo the single-window and return to whatever layout you had before with winner-undo: C-c <left>

Whole desktop

Relatedly, for sharing over a video call, it might be easiest to just change (lower) your desktop resolution. On linux, I pop up arandr for this before starting a sharing session.

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54