Emacs 快捷方式一键从水平拆分切换到垂直拆分?
Posted
技术标签:
【中文标题】Emacs 快捷方式一键从水平拆分切换到垂直拆分?【英文标题】:Emacs shortcut to switch from a horizontal split to a vertical split in one move? 【发布时间】:2013-02-14 17:52:20 【问题描述】:我经常发现自己从 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 空间)。
【问题讨论】:
【参考方案1】:让其他碰巧也在寻找脚本(在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)
【讨论】:
【参考方案2】:最后一行是定义组合键的地方。应该是(global-set-key (kbd "C-x |") 'toggle-window-split)
【讨论】:
以上是关于Emacs 快捷方式一键从水平拆分切换到垂直拆分?的主要内容,如果未能解决你的问题,请参考以下文章