Emacs, switch to previous window

后端 未结 13 1104
你的背包
你的背包 2020-12-04 07:12

In Emacs, C-x o takes me to the next window.

What keyboard macro takes me to the previous window in Emacs?

相关标签:
13条回答
  • 2020-12-04 07:46

    There is already a package that lets you switch windows by using M-. check this website. Add this to your init file:

    (require 'windmove)
    (windmove-default-keybindings 'meta) ;; or use 'super to use windows key instead alt
    
    0 讨论(0)
  • 2020-12-04 07:48

    Just to add to @Nate, @aspirin and @Troydm's answer I find this to be a very helpful addition if you decide to bind the windmove commands to whatever key combination you choose:

    (setq windmove-wrap-around t)
    

    With the default configuration you will get an error when you get to attempt to move to a window that doesn't exist which becomes kind of annoying after a while. However when windmove-wrap-around is set then attempting to move off the bottom of the frame for example will instead select the topmost window in the frame. This may be a more intuitive behaviour for you.

    0 讨论(0)
  • 2020-12-04 07:49
    (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"
    
    0 讨论(0)
  • 2020-12-04 07:50

    That'd be C-- C-x o

    In other words, C-x o with an argument of -1. You can specify how many windows to move by inserting a numeric argument between C-u and the command, as in C-u 2 C-x o. (C-- is a shortcut for C-u - 1)

    0 讨论(0)
  • 2020-12-04 07:50

    In reference to Nate's answer, I replaced the arrow keys to use the traditional p for going up, n for going down, f for going right and b for going left. I also replaced the Ctrl with Super key as C-p, C-n, C-f and C-b are the default movement keys. This combination with M lets you jump characters and lines instead of going through just one by one after each keystroke. Thus Super key felt the best choice to keep it an easy key binding. Also, now you don't have to take your hand off the home row any more!

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

    Hope it helps!

    0 讨论(0)
  • 2020-12-04 07:52

    M-n and M-p makes the most sense to me, since they are analogous to C-n (next-line) and C-p (previous-line):

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

    (inspired by to this and that)

    0 讨论(0)
提交回复
热议问题