" /> " /> " />

首页 / 知识

Emacs,切换到上一个窗口

2023-04-17 01:26:00

Emacs, switch to previous window

在Emacs中,C-x o将我带到下一个窗口。

哪个键盘宏将我带到Emacs中的上一个窗口?


您可能还想尝试使用windmove,它可以让您基于几何导航到您选择的窗口。我的.emacs文件中包含以下内容,用于使用C-x箭头键更改窗口。

1
2
3
4
(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-- C-x o

换句话说,C-x o的参数为-1。您可以通过在C-u和命令之间插入数字参数来指定要移动的窗口数量,如C-u 2 C-x o一样。 (C--C-u-1的快捷方式)


我个人更喜欢使用window-number.el

要选择其他窗口,请使用Ctrl-xCtrl-j n

其中n是窗口的编号,每个窗口的modeline都会显示其编号,如屏幕截图所示。

>
</p>
<p>
只需下载window-number.el,将其放在您的emacs加载路径中,然后在<wyn>.emacs</wyn>中使用以下内容
</p>
<div class=

1
2
3
4
5
 (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,可以在窗口中显示大量数字...(按数字可切换窗口并还原显示。)

><br />
<sub>(来源:tapoueh.org)</ sub>
</p>

<hr>
<p>
如果您经常使用多个emacs窗口(> 3),并且要保存一些击键,请将其添加到您的init文件中,这样会更好:
</p>
<div class=

1
2
3
4
5
6
(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在窗户上快速循环


这里有一些非常完整的答案,但是要以简约的方式回答:

1
2
3
4
5
 (defun prev-window ()
   (interactive)
   (other-window -1))

 (define-key global-map (kbd"C-x p") 'prev-window)

M-nM-p对我来说最有意义,因为它们类似于C-n(下一行)和C-p(上一行):

1
2
(define-key global-map (kbd"M-p") 'previous-multiframe-window)
(define-key global-map (kbd"M-n") 'other-window)

(受此启发)


只是添加到@ Nate,@ aspirin和@Troydm的答案中,如果您决定将windmove命令绑定到您选择的任何按键组合,我发现这对添加非常有用:

1
(setq windmove-wrap-around t)

使用默认配置,当您尝试移动到不存在的窗口时会出现错误,一段时间后会变得有些烦人。但是,当设置了windmove-wrap-around时,例如尝试移出框架的底部将改为选择框架中最顶部的窗口。这对您来说可能是更直观的行为。


基于@Nate的想法,但略作修改以支持窗口之间的向后循环

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
;; 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)

1
2
3
4
(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)))

altjaltk将在可见缓冲区中循环。确切地说,向前和向后。


参考Nate的答案,我替换了arrow keys来使用传统的p来进行upn来进行downf来进行rightb来进行。我还用Super键替换了Ctrl,因为C-p, C-n, C-f and C-b是默认的移动键。与M的此组合使您可以跳字符和换行,而不必在每次击键之后仅一步一步地进行操作。因此,Super密钥是保持简单的密钥绑定的最佳选择。而且,现在您不必再将手从本垒打了!

1
2
3
4
(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)

希望能帮助到你!


已经有一个软件包,可让您使用M-切换窗口。检查这个网站。将此添加到您的初始化文件:

1
2
(require 'windmove)
(windmove-default-keybindings 'meta) ;; or use 'super to use windows key instead alt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(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"


键盘文件导航选择

最新内容

相关内容

猜你喜欢