如何更改分屏 emacs 窗口的大小?

发布于 2024-10-17 09:01:18 字数 114 浏览 2 评论 0原文

我将 emacs 水平分割 - 在顶部我正在编辑 Perl 代码,底部是 shell。默认情况下,emacs 使两个窗口大小相等,但我希望 shell 缓冲区更小(也许是一半大小?)。我想知道我怎样才能做到这一点。

I have emacs split horizontally - on top I'm editing Perl code, the bottom is the shell. By default emacs makes the two windows equal in size, but I'd like the shell buffer smaller (maybe half the size?). I was wondering how I could do that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

清欢 2024-10-24 09:01:18

使用鼠标,您可以拖动窗口大小。

单击模式线上非“活动”的任意位置(缓冲区名称是安全的,或右侧任何未使用的区域),然后可以向上或向下拖动。

左右拖动需要非常精确地单击两条模式线的连接点。

Cx - (shr​​ink-window-if-larger-than-buffer) 将缩小窗口以适应其内容。

Cx + (balance-windows) 将使窗口具有相同的高度和宽度。

Cx ^ (enlarge-window) 将高度增加 1 行或前缀 arg 值。负参数会缩小窗口。例如C-- C-1 C-6 Cx ^ 缩小 16 行,Cu 也是如此  - 1  6  Cx ^

shr​​ink-window 没有默认绑定。)

Cx }enlarge-window-horizo​​ntally ) 水平方向同样如此。
Cx { (shr​​ink-window-horizo​​ntally) 也默认绑定。

使用repeat执行这些命令之一(Cx z启动,只需z继续重复)可以很容易地获得您想要的确切尺寸。

如果您经常想要使用特定值执行此操作,您可以录制键盘宏来执行此操作,或使用类似
(global-set-key (kbd "Cc v") (kbd "Cu - 1 6 Cx ^"))

或者这样:
(global-set-key (kbd "Cc v") (kbd "Cx o Cx 2 Cx 0 Cu - 1 Cx o"))

这是一个小黑客,所以这会更好:

(defun halve-other-window-height ()
  "Expand current window to use half of the other window's lines."
  (interactive)
  (enlarge-window (/ (window-height (next-window)) 2)))

(global-set-key (kbd "C-c v") 'halve-other-window-height)

切向,我也喜欢 winner-mode,它可以让您使用 Cc 反复“撤消”对窗口配置的任何更改 left(无论更改是窗口的大小/数量/排列,或者只是显示哪个缓冲区)。 抄送 返回到最新的配置。使用(winner-mode 1)进行全局设置

With the mouse, you can drag the window sizes around.

Click anywhere on the mode line that is not otherwise 'active' (the buffer name is safe, or any unused area to the right hand side), and you can drag up or down.

Side-to-side dragging requires a very precise click on the spot where the two mode lines join.

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

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

C-x ^ (enlarge-window) increases the height by 1 line, or the prefix arg value. A negative arg shrinks the window. e.g. C-- C-1 C-6 C-x ^ shrinks by 16 rows, as does C-u - 1 6 C-x ^.

(There is no default binding for shrink-window.)

C-x } (enlarge-window-horizontally) does likewise, horizontally.
C-x { (shrink-window-horizontally) is also bound by default.

Following one of these commands with repeat (C-x z to initiate, and just z for continued repetition) makes it pretty easy to get to the exact size you want.

If you regularly want to do this with a specific value, you could record a keyboard macro to do it, or use something like
(global-set-key (kbd "C-c v") (kbd "C-u - 1 6 C-x ^"))

Or this:
(global-set-key (kbd "C-c v") (kbd "C-x o C-x 2 C-x 0 C-u - 1 C-x o"))

Which is a smidgen hacky, so this would be better:

(defun halve-other-window-height ()
  "Expand current window to use half of the other window's lines."
  (interactive)
  (enlarge-window (/ (window-height (next-window)) 2)))

(global-set-key (kbd "C-c v") 'halve-other-window-height)

Tangentially, I also love winner-mode which lets you repeatedly 'undo' any changes to window configurations with C-c left (whether the change is the size/number/arrangement of the windows, or just which buffer is displayed). C-c right returns you to the most recent configuration. Set it globally with (winner-mode 1)

心意如水 2024-10-24 09:01:18

我将这些放入我的 .emacs 中:

(global-set-key (kbd "<C-up>") 'shrink-window)
(global-set-key (kbd "<C-down>") 'enlarge-window)
(global-set-key (kbd "<C-left>") 'shrink-window-horizontally)
(global-set-key (kbd "<C-right>") 'enlarge-window-horizontally)

I put these in my .emacs:

(global-set-key (kbd "<C-up>") 'shrink-window)
(global-set-key (kbd "<C-down>") 'enlarge-window)
(global-set-key (kbd "<C-left>") 'shrink-window-horizontally)
(global-set-key (kbd "<C-right>") 'enlarge-window-horizontally)
¢蛋碎的人ぎ生 2024-10-24 09:01:18

让我们尝试使用 emacs 帮助文档。

Ch a

然后输入“放大”或“窗口”

您会找到您想要的内容。

享受!

let's try to use emacs help document.

C-h a

Then type "enlarge" or "window"

You will find what you want.

Enjoy!

拧巴小姐 2024-10-24 09:01:18

Cx o 到您想要扩大其大小的窗口。从那里,Cx ^ 展开它。

C-x o to the window whose size you want expanded. From there, C-x ^ to expand it.

維他命╮ 2024-10-24 09:01:18

Cx ^ 接受正数负数值参数。特别是,如果您想将光标当前所在的窗口缩小四行,可以按 Cu -4 Cx ^

C-x ^ takes positive and negative numerical arguments. In particular, if you would like to shrink the window where your cursor currently is by four lines, you can press C-u -4 C-x ^.

睡美人的小仙女 2024-10-24 09:01:18

这不是您正在寻找的确切答案,但我在查找 spacemacs 中的功能时偶然发现了这个问题,因此为了完整起见,我将写下我的答案。

该选项是使用 + w + .(适用于普通 spacemacs)

这会打开一个瞬态窗口,您可以在其中使用 []{} 在粒度级别上调整大小。

不需要 Cx 或鼠标...

窗口操作瞬态

This is not the exact answer you're looking for, but I stumbled upon this question when looking out for the functionality in spacemacs, so I'll write my answer just for completeness' sake.

The option is to use <SPC> + w + . (it works in vanilla spacemacs)

This opens up a transient window where one can use []{} to resize at a granular level.

There's no need for C-x or Mouse...

Window manipulation transient state

妥活 2024-10-24 09:01:18

我也有同样的问题。这是我的解决方案。
首先我定义一个新函数:

(defun buffer-resize ()
  (delete-other-windows)
  (split-window-vertically (floor (* 0.68 (window-height))))
  (other-window 1)
  (switch-to-buffer buf)
  (other-window 1))

例如,我想在缓冲区中运行方案,所以我重写它。
这是定义,其中包含前面定义的函数:

(defun run-scheme-here ()
  "Run a new scheme process at the directory of the current buffer.
   If a process is already running, switch to its buffer."
  (interactive)
  (let* ((proc (format "scheme: %s" default-directory))
         (buf (format "*%s*" proc)))
    (unless (comint-check-proc buf)
      (let ((cmd (split-string scheme-program-name)))
        (set-buffer
         (apply 'make-comint-in-buffer proc buf (car cmd) nil (cdr cmd)))
        (inferior-scheme-mode)
        (buffer-resize)))
    (pop-to-buffer buf)))

所以现在当我输入:Mx run-scheme-here 时,缓冲区大小被调整!
这是我的配置文件,希望这会有所帮助。 https://github.com/judevc/dotfiles/ blob/master/.emacs.d/scheme-conf.el

I got the same question. Here is my solution.
First I define a new function:

(defun buffer-resize ()
  (delete-other-windows)
  (split-window-vertically (floor (* 0.68 (window-height))))
  (other-window 1)
  (switch-to-buffer buf)
  (other-window 1))

For example, I want to run-scheme in a buffer, So I rewrite it.
And here is the definition, with the function defined earlier:

(defun run-scheme-here ()
  "Run a new scheme process at the directory of the current buffer.
   If a process is already running, switch to its buffer."
  (interactive)
  (let* ((proc (format "scheme: %s" default-directory))
         (buf (format "*%s*" proc)))
    (unless (comint-check-proc buf)
      (let ((cmd (split-string scheme-program-name)))
        (set-buffer
         (apply 'make-comint-in-buffer proc buf (car cmd) nil (cdr cmd)))
        (inferior-scheme-mode)
        (buffer-resize)))
    (pop-to-buffer buf)))

So now when I enter: M-x run-scheme-here, the buffer is resized!
And here is my config file, hoping this will help. https://github.com/judevc/dotfiles/blob/master/.emacs.d/scheme-conf.el

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文