2013-02-14 107 views
20

我經常發現自己從emacs中的兩個窗口的水平視圖切換到垂直視圖。這需要我先做C-x 1,然後C-x 3,然後C-x o,然後C-x b <RET>切換到另一個緩衝區或類似的東西。我只想輸入C-x |(類似於在Ediff中如何打|來切換分割視圖)。Emacs快捷鍵從一個水平分割切換到一個垂直分割?

我發現這在Emacs的維基網站: http://www.emacswiki.org/emacs/ToggleWindowSplit

但是我怎麼映射,要我想要的組合鍵?或者是否有更簡單的方法來執行此操作(減少.emacs空間)。

回答

19

最後一行是定義組合鍵的地方。它應該是(global-set-key (kbd "C-x |") 'toggle-window-split)

+0

感謝這個工作! – 2013-02-14 18:28:31

13

使其成爲其他人也正好在看的劇本更容易(在此鏈接:http://www.emacswiki.org/emacs/ToggleWindowSplit),已經與對方回答的鍵綁定修改:

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