题
在 Emacs 中, C-x o 带我到下一个窗口。
哪个键盘宏将我带到 Emacs 中的上一个窗口?
解决方案
那就是 C--C-x o
换句话说, C-x o 参数为-1。您可以通过在之间插入数字参数来指定要移动的窗口数 铜-u 和命令,如 C-u 2 C-x o. (C - 是一个快捷方式 C-u-1)
其他提示
您可能还想尝试使用 Windmove,它可以让您根据几何图形导航到您选择的窗口。我的 .emacs 文件中有以下内容,可以使用 C-x 箭头键更改窗口。
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
我个人更喜欢使用 window-number.el
要选择不同的窗口,请使用 控制键-X, 控制键-j n
在哪里 n 是窗口的编号,每个窗口的模型线显示它的编号,如屏幕截图所示。
只需下载 窗口号.el, ,将其放入您的 emacs 加载路径中并在您的 .emacs
(autoload 'window-number-mode "window-number"
"A global minor mode that enables selection of windows according to
numbers with the C-x C-j prefix. Another mode,
`window-number-meta-mode' enables the use of the M- prefix."
t)
还有另一种类似的模式称为 switch-window.el
这会在窗口中给你很大的数字......(按数字切换窗口并恢复显示。)
如果您经常使用多个 emacs 窗口 (>3) 并且您想要保存一些击键,请将其添加到您的 init 文件中,您会更好:
(defun frame-bck()
(interactive)
(other-window-or-frame -1)
)
(define-key (current-global-map) (kbd "M-o") 'other-window-or-frame)
(define-key (current-global-map) (kbd "M-O") 'frame-bck)
现在只需使用 M-o 快速循环穿过窗口
这里有一些非常好的和完整的答案,但以极简的方式回答这个问题:
(defun prev-window ()
(interactive)
(other-window -1))
(define-key global-map (kbd "C-x p") 'prev-window)
基于 @Nate 的想法,但稍加修改以支持窗口之间的向后循环
;; Windows Cycling
(defun windmove-up-cycle()
(interactive)
(condition-case nil (windmove-up)
(error (condition-case nil (windmove-down)
(error (condition-case nil (windmove-right) (error (condition-case nil (windmove-left) (error (windmove-up))))))))))
(defun windmove-down-cycle()
(interactive)
(condition-case nil (windmove-down)
(error (condition-case nil (windmove-up)
(error (condition-case nil (windmove-left) (error (condition-case nil (windmove-right) (error (windmove-down))))))))))
(defun windmove-right-cycle()
(interactive)
(condition-case nil (windmove-right)
(error (condition-case nil (windmove-left)
(error (condition-case nil (windmove-up) (error (condition-case nil (windmove-down) (error (windmove-right))))))))))
(defun windmove-left-cycle()
(interactive)
(condition-case nil (windmove-left)
(error (condition-case nil (windmove-right)
(error (condition-case nil (windmove-down) (error (condition-case nil (windmove-up) (error (windmove-left))))))))))
(global-set-key (kbd "C-x <up>") 'windmove-up-cycle)
(global-set-key (kbd "C-x <down>") 'windmove-down-cycle)
(global-set-key (kbd "C-x <right>") 'windmove-right-cycle)
(global-set-key (kbd "C-x <left>") 'windmove-left-cycle)
只是为了添加@Nate、@aspirin 和@Troydm 的答案,如果您决定将windmove 命令绑定到您选择的任何组合键,我发现这是一个非常有用的补充:
(setq windmove-wrap-around t)
使用默认配置,当您尝试移动到不存在的窗口时,您会收到错误消息,这在一段时间后会变得有点烦人。然而,当设置了windmove-wrap-around 时,例如尝试离开框架底部时将选择框架中最上面的窗口。这对您来说可能是更直观的行为。
参考内特的回答,我替换了 arrow keys
使用传统的 p
去 up
, n
去 down
, f
去 right
和 b
去 left
. 。我也更换了 Ctrl
和 Super
键为 C-p, C-n, C-f and C-b
是默认的移动键。这种组合与 M
让您可以跳跃字符和行,而不是每次击键后都逐一浏览。因此 Super
key 感觉是保持简单按键绑定的最佳选择。而且,现在您不必再将手从主排移开!
(global-set-key (kbd "s-p") `windmove-up)
(global-set-key (kbd "s-n") `windmove-down)
(global-set-key (kbd "s-f") `windmove-right)
(global-set-key (kbd "s-b") `windmove-left)
希望能帮助到你!
(global-unset-key (kbd "M-j"))
(global-unset-key (kbd "M-k"))
(global-set-key (kbd "M-j") (lambda () (interactive) (other-window 1)))
(global-set-key (kbd "M-k") (lambda () (interactive) (other-window -1)))
替代j 和 替代k 将循环浏览您的可见缓冲区。准确地说,是向前和向后。
已经有一个软件包可以让您使用 M- 切换窗口。 检查这个网站. 。将其添加到您的初始化文件中:
(require 'windmove)
(windmove-default-keybindings 'meta) ;; or use 'super to use windows key instead alt
(global-set-key (kbd "C-x a") 'ace-swap-window)
(global-set-key (kbd "C-x q") 'ace-select-window)
download ace-window from the melpa repo if you don't know how to do that
put this in your .emacs file if you don't have one create it
(package-initialize)
(require 'package)
(add-to-list 'package-archives '("melpa" , "http://melpa.org/packages/"))
(package-initialize)
then "m-x list-packages"