31

有时我使用 2 个文件从命令行启动 emacs,如下所示:

emacs foo.txt bar.txt

这将打开 emacs 窗口,垂直拆分:

foo.txt
-------
bar.txt

如何编辑我的 .emacs 文件,以便它们并排显示,像这样?:

        |
foo.txt | bar.txt
        |

编辑:澄清一下,我知道如何在 emacs 启动实现这一点(Mx 0,Mx 3,然后在右侧窗口中重新访问 bar.txt)。我只希望emacs在我启动它时默认并排拆分,所以我不必这样做。

4

7 回答 7

20

这是一个将一对垂直窗口更改为一对水平窗口的函数:

(defun 2-windows-vertical-to-horizontal ()
  (let ((buffers (mapcar 'window-buffer (window-list))))
    (when (= 2 (length buffers))
      (delete-other-windows)
      (set-window-buffer (split-window-horizontally) (cadr buffers)))))

要在启动时自动执行此操作,请将此功能添加到emacs-startup-hook

(add-hook 'emacs-startup-hook '2-windows-vertical-to-horizontal)
于 2011-07-14T18:14:51.927 回答
17

以下(添加到您的 .emacs 中)使窗口拆分默认结果在并排缓冲区中(而不是一个在另一个之上):

(setq split-height-threshold nil) 
(setq split-width-threshold 0) 

当您运行诸如find-file-other-window( Ctrlx4f) 之类的命令时,此默认设置也将适用。

(另一方面,要手动拆分窗口以获得两个并排的缓冲区,请考虑这个答案)。

于 2011-07-14T18:12:10.860 回答
6

这对我来说效果很好。使用命令行中的 -f function-name 让它根据需要设置您的 emacs 分屏工作区。这为我提供了一个 2 x 2 的财务文件网格,我每天都会更新这些文件,并将光标设置在最后的相应窗口上。我将它作为别名保存到 .bashrc,以便我可以使用一个命令 (doc_financial) 将其拉起。

alias doc_financial='emacs -nw financial_accounts.txt -f split-window-horizontally financial_budget.txt -f split-window-vertically financial_taxes.txt -f other-window -f split-window-vertically financial_tasks.txt -f other-window -f other-window -f other-window'
于 2012-06-29T17:52:23.367 回答
5

使用M-x split-window-horizontallyCtrl-x 3

于 2011-07-14T17:37:46.587 回答
0
;; 15-Oct-20  open first file in left window
(defun my-startup-layout ()
  (let ((buffers (mapcar 'window-buffer (window-list))))
    (when (= 2 (length buffers))
      (delete-other-windows)
      (set-window-buffer (split-window-horizontally) (cadr buffers))))
)

(add-hook 'emacs-startup-hook 'my-startup-layout)
(add-hook 'emacs-startup-hook 'next-multiframe-window)
;; end of customization to open first file on left
;;
于 2020-10-15T20:46:39.280 回答
-1

使用水平分割窗口。

于 2011-07-14T17:37:36.073 回答
-1

Ctrl -x 2 拆分窗口,上下

缓冲区 1(上)
缓冲区 2(下)

Ctrl -x 3 拆分窗口,并排

缓冲区 1(左) | 缓冲区 2(右)

CMv 滚动其他窗口

于 2015-11-25T14:40:51.090 回答