Emacs快捷方式可以在一次移动中从水平分割切换到垂直分割?

时间:2013-02-14 17:52:21

标签: emacs

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

我在emacs wiki网站上发现了这个: http://www.emacswiki.org/emacs/ToggleWindowSplit

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

2 个答案:

答案 0 :(得分:21)

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

答案 1 :(得分:20)

让正在寻找脚本(在this link中)的其他人更容易,已经使用其他答案的键绑定进行了修改:

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