那么在Emacs中,哪个键盘宏可以带我到上一个窗口呢?
您可能还想尝试使用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)
C-x z
来重复上一个命令,快速切换窗口。 - Joseph Tesfaye个人而言,我更喜欢使用 window-number.el
。
要选择不同的窗口,请使用 Ctrl-x, Ctrl-j n
其中,n 是窗口的编号,每个窗口的模型行都会显示它的编号,如截图所示。
只需下载window-number.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
,它在窗口中显示大号数字...(按下数字可以切换窗口并恢复显示。)
(来源:tapoueh.org)
C-x C-j
,因为如果你(require 'dired-x)
,那就是dired-jump
的默认绑定。(如果你想覆盖它,请参阅M-x customize-group RET dired-keys RET
。) - philsswitch-window.el
,它使用 C-x o
,当只有两个窗口处于活动状态时,它会选择另一个窗口。我认为最明智的做法是将 C-x o
重新绑定到执行 window-number
技巧上,你对 dired-jump
的看法是正确的。个人而言,我不太喜欢频繁切换窗口,更喜欢使用 C-x b
,但增强版的 C-x o
也很令人愉悦。 - ocodo(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)
(global-set-key (kbd "C-x p") 'previous-window-any-frame)
可以正常工作。 - David C. Norris;; 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时,例如尝试从底部框架移动时,会选择框架中最顶部的窗口,这可能更符合你的直觉行为。
M-n
和 M-p
在终端(gdb、python、ielm 等)中已经被占用,因此您将不得不切换回另一种方法来跳出终端缓冲区。 - mihai参考Nate的答案,我将使用传统的p
键代替箭头键
向上
移动,使用n
键向下
移动,使用f
键向右
移动,使用b
键向左
移动。 我还将使用Super
键代替Ctrl
键,因为C-p,C-n,C-f和C-b
是默认移动键。 结合使用M
键,这些键可以让您跳过字符和行,而不是在每次按键后逐个进行。 因此,Super
键是最好的选择,可以使其成为易于绑定的键。 现在,您无需再将手从Home Row上拿开了!
(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)))
altj和altk可以循环浏览您可见的缓冲区,确切地说是向前和向后。
(windmove-default-keybindings)
将这些函数绑定到SHIFT +上/下/左/右键,我认为这比您的C-x
绑定更方便(它会与previous-buffer
和next-buffer
的默认绑定发生冲突)。lkahtz:(kbd)
函数可以让你使用字符串表示法指定按键,这种更可读的语法在Emacs中使用C-h k
或C-h c
来描述绑定时也被使用。 - philswindmove-default-keybindings
,以指定与箭头键一起使用的不同修饰符,因此该函数仍然对使用shift-selection-mode的人很有用。 - phils