[英]Bind key to increase / decrease font size in emacs
In my terminal (I have terminator ) I can use the key combinations Ctrl + and Ctrl - to increase / decrease the font size. 在我的终端(我有终结器 )我可以使用组合键Ctrl +和Ctrl -来增加/减少字体大小。
In emacs I can do the following to set the font-height: 在emacs中,我可以执行以下操作来设置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? 我怎样才能轻松将其添加到我的emacs配置中?
我想你想要Cx C-+
或Cx C--
。
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. 虽然@Stefan提到的默认键绑定可以完成这项工作,但我也喜欢使用更常见的键绑定。 Btw, Cx C-= increases the font size as well and Cx C-0 restores the default font size. 顺便说一句, Cx C- =也增加了字体大小, Cx C-0恢复了默认的字体大小。
Cx C-+
and Cx C--
gives you only part of the answer: text scaling a buffer. Cx C-+
和Cx C--
只给出部分答案:缩放缓冲区的文本。
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 Cx C-+
and Cx C--
give you. 后者称为文本缩放 ,它是香草Emacs Cx C-+
和Cx C--
给你的。
Library zoom-frm.el
gives you both kinds of zooming with the same command. 库zoom-frm.el
使用相同的命令为您提供两种缩放。 Bind the same command, zoom-in/out
, to both Cx C--
and Cx C-+
. 将相同的命令( zoom-in/out
绑定到Cx C--
和Cx C-+
。 It zooms either the frame or the buffer, in and out. 它可以放大或缩小帧或缓冲区。 A plain prefix arg toggles between zooming frames and zooming buffers. 简单前缀arg在缩放帧和缩放缓冲区之间切换。 Bind it also to mouse keys (I use S-mouse-1
(in) and CS-mouse-1
(out) and to the mouse wheel (in/out). 将它绑定到鼠标键(我使用S-mouse-1
(in)和CS-mouse-1
(out)和鼠标滚轮(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. 库face-remap+.el
修复了文本缩放,以便窗口大小缩小或增大以适应不断变化的文本大小,这可以释放屏幕空间。
This EmacsWiki page has more info about this frequently asked question. 此EmacsWiki页面提供了有关此常见问题的更多信息。
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)))
检查赛尔公司.emacs.d和他的字体utils的 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.