ChatGPT解决这个技术问题 Extra ChatGPT

如何在emacs中的可见缓冲区之间切换?

If I am in split-screen viewing 2 different buffers on Emacs and the cursor is on the top buffer, what's a quick way to move the cursor to the bottom buffer?

Bonus question: if I know a command, is there an easy way to identify what key-combo it's bound to, if any?


n
nbro

To switch to other buffer use: C-x o.

Describe key: C-h k.


you need to wait a bit after C-x, when it appears in the line, hit o
The above comment is not correct: you do not need to wait for C-x to appear.
Excellent. What are the proper terms for these two entities? Are they buffers? Frames? Windows?
for emacs newbies, it is helpful to explain the meaning of "C-x o": hold CTRL, press x, let go of CTRL, press o
To clarify what Timofey and nguthrie are talking about, you have to wait a bit for C-x to show up on the mode line (the bar at the bottom which acts as feedback). But you can hit o immediately.
C
CodyChan

Here is a better solution when you open more than two windows(buffers) in one frame:

(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)

Now, you can use C-x UP/DOWN/LEFT/RIGHT to go to the above/nether/left/right buffer when you have three or more in one frame, they are more precise than 'other-window and you don't need to install any package.

You even CAN make it to cycle the buffers in the direction(vertically/horizontally) with one of the above shortkeys with configuration in .emacs/init.el file, but I don't recommend it(besides I don't remember it anymore, you can google it if you want).

Of course, you can use other shortkeys other than the ones I use in my .emacs.


Note that by default C-x and C-x are used to switch between active buffers
Note that this doesn't work if you've run bash in one of your panes, these commands are snagged by bash instead of emacs using them. Probably applies to other programs run via emacs. You can move between panes until the bash pane is active and then you are stuck. C-x o doesn't work either.
@LawfulEvil do 'C-c C-x o' to escape the bash plane capture. 'C-c' tells the window you are entering emacs commands not terminal ones.
The best way I have found, for EVIL mode users, to use vim like key bindings to move around e.g. (global-set-key (kbd "C-k") 'windmove-up) and so on..
or M-x windmove-<direction>
j
jlf

You may also be interested in WindMove, which enables "directional" window navigation with <S-up>, <S-right> etc.


Yes, and it's now built-in, so you just need to add (windmove-default-keybindings) to your init file.
T
Trey Jackson

With respect to the bonus question, if you know the command (other-window), and you invoke it with M-x other-window, Emacs will show a brief message in the minibuffer stating: "You can run the command `other-window' with C-x n".

There is also M-x where-is which prompts for a command and gives you the current bindings that result in that command (if any).

There is a tutorial that's shipped with Emacs. It actually has the answer to your question (see the section MULTIPLE WINDOWS about 80% into the tutorial). The tutorial can be accessed via C-h t, or M-x help-with-tutorial. There's also a link to the tutorial on the initial splash screen of Emacs. Right below the link to the tutorial is a link to the on-line Emacs Guided Tour. The tutorial walks you through basic editing/movement commands, the guided tour is more of an introduction to what Emacs has to offer.


Thanks Trey, In true coder fashion I followed along for the first 75% of the tutorial, said "yeah, I pretty much got it" and wandered off to coding.
C
Community

If you want to navigate among only buffers that are currently displayed, then you really want to navigate among the windows they are displayed in. This gives you a way to do that, using window/frame names that are the same as the buffers:

See Better window navigation in Emacs?