在emacs中打开2个文件时,如何让它们并排显示?

发布于 2024-11-24 02:02:16 字数 389 浏览 0 评论 0原文

有时我从命令行启动带有 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 在启动时默认并排拆分,所以我不必这样做。

Sometimes I launch emacs from the command line with 2 files, as follows:

emacs foo.txt bar.txt

This opens the emacs window, split vertically:

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

How can I edit my .emacs file so that they show up side-by-side, like this?:

        |
foo.txt | bar.txt
        |

EDIT: To clarify, I know how to make this happen after emacs has launched (M-x 0, M-x 3, then re-visit bar.txt in the right window). I just want emacs to split side-by-side by default when I launch it, so I don't have to.

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

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

发布评论

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

评论(7

口干舌燥 2024-12-01 02:02:16

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

(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)

Here's a function that will change a pair of vertical windows to a pair of horizontal windows:

(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)))))

To do this automatically on startup, add this function to emacs-startup-hook:

(add-hook 'emacs-startup-hook '2-windows-vertical-to-horizontal)
过期情话 2024-12-01 02:02:16

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

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

当您运行诸如 find-file 之类的命令时,此默认值也将适用-其他窗口Ctrlx4f)。

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

The following (to add to your .emacs) makes the window splitting default result in side-by-side buffers (rather than one above the other):

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

This default will also apply when you run a command such as find-file-other-window (Ctrlx4f).

(On the other hand, to manually split your window to get two side-by-side buffers, consider this answer).

说不完的你爱 2024-12-01 02:02:16

这对我来说效果很好。使用命令行中的 -f 函数名称,让它根据您的喜好设置您的 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'

This has worked well for me. Use the -f function-name from the command-line to have it set up your emacs split-screen workspace as you like. This gives me a 2 x 2 grid of my financial files that I update every day and sets the cursor on the appropriate window at the end. I save this to .bashrc as an alias so I can pull it up with one command (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'
木落 2024-12-01 02:02:16

使用Mx split-window-horizo​​ntallyCtrl-x 3

Use M-x split-window-horizontally or Ctrl-x 3.

千寻… 2024-12-01 02:02:16

Ctrl -x 2
分割窗口,

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

Ctrl -x 3
分割窗口,并排

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

CMv
滚动其他窗口

Ctrl -x 2
Split window, above and below

Buffer 1 (above)
Buffer 2 (Below)

Ctrl -x 3
Split window, Side by Side

Buffer 1(left) | Buffer 2 (right)

C-M-v
Scroll other window

铁轨上的流浪者 2024-12-01 02:02:16
;; 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
;;
;; 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
;;
凡间太子 2024-12-01 02:02:16

使用水平分割窗口。

Use split-window-horizontally.

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