32

我经常发现自己从 emacs 中两个窗口的水平视图切换到垂直视图。这需要我先做C-x 1,然后C-x 3再切换C-x oC-x b <RET>另一个缓冲区或类似的东西。我只想输入C-x |(类似于在 Ediff 中您点击|切换拆分视图的方式)。

我在 emacs wiki 站点中找到了这个: http ://www.emacswiki.org/emacs/ToggleWindowSplit

但是我如何将它映射到我想要的组合键?或者是否有更简单的方法(占用更少的 .emacs 空间)。

4

2 回答 2

27

让其他碰巧也在寻找脚本(在此链接中)的人更容易,已经使用其他答案的键绑定进行了修改:

(defun toggle-window-split ()
  (interactive)
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
         (next-win-buffer (window-buffer (next-window)))
         (this-win-edges (window-edges (selected-window)))
         (next-win-edges (window-edges (next-window)))
         (this-win-2nd (not (and (<= (car this-win-edges)
                     (car next-win-edges))
                     (<= (cadr this-win-edges)
                     (cadr next-win-edges)))))
         (splitter
          (if (= (car this-win-edges)
             (car (window-edges (next-window))))
          'split-window-horizontally
        'split-window-vertically)))
    (delete-other-windows)
    (let ((first-win (selected-window)))
      (funcall splitter)
      (if this-win-2nd (other-window 1))
      (set-window-buffer (selected-window) this-win-buffer)
      (set-window-buffer (next-window) next-win-buffer)
      (select-window first-win)
      (if this-win-2nd (other-window 1))))))

(global-set-key (kbd "C-x |") 'toggle-window-split)
于 2015-10-31T21:04:25.930 回答
23

最后一行是定义组合键的地方。它应该是(global-set-key (kbd "C-x |") 'toggle-window-split)

于 2013-02-14T18:06:49.223 回答