切换窗口分割方向,最快的方法


16

假设您有两个这样打开的缓冲区:

------------------------------------
            |                      |
  buffer 1  |        buffer 2      |       
            |                      |
------------------------------------

切换缓冲区以使您获得此最快的方法是什么:

------------------------------------
           buffer 1                |
                                   |
------------------------------------
            buffer 2               |
                                   |
------------------------------------

stackoverflow.com/a/10546694。转置框架库。免责声明-尚未尝试。
Faheem Mitha 2014年

有一个与此主题相关的Wiki页面:emacswiki.org/emacs/ToggleWindowSplit
Chris Martin

参见emacs.stackexchange.com/q/5371 ; 特别是transpose-frame关于MELPA的一个答案。
TooTone

Answers:


15

这是一个defun,可以满足您的需求:

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

(从Magnars .emacs.d无耻地复制)

另外,如果再次调用它,它将以原始垂直方向重新分割窗口。


如果可以保留两个窗口的相对大小关系,那就太好了。我经常在底部保留一个不平坦的“短”窗口,来回切换时,保持此相对大小会有所帮助。尽管狭窄的垂直窗口可能不太有用。
2014年

1
我不能告诉你我使用了多少次。很有帮助
Edgar Aroutiounian 2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.