61

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?

nbro
  • 15,395
  • 32
  • 113
  • 196
George Mauer
  • 117,483
  • 131
  • 382
  • 612

5 Answers5

86

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

Describe key: C-h k.

nbro
  • 15,395
  • 32
  • 113
  • 196
Rozuur
  • 4,115
  • 25
  • 31
  • 2
    you need to wait a bit after C-x, when it appears in the line, hit o – Timofey Jan 16 '13 at 22:08
  • 11
    The above comment is not correct: you do not need to wait for C-x to appear. – nguthrie Dec 30 '13 at 17:28
  • Excellent. What are the proper terms for these two entities? Are they buffers? Frames? Windows? – MadPhysicist Oct 10 '17 at 01:36
  • 1
    for emacs newbies, it is helpful to explain the meaning of "C-x o": hold CTRL, press x, let go of CTRL, press o – Abhishek Anand Jan 05 '19 at 00:41
  • 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. – nomad Sep 12 '20 at 05:37
30

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.

CodyChan
  • 1,776
  • 22
  • 35
  • 1
    Note that by default C-x and C-x are used to switch between active **buffers** –  May 09 '16 at 13:09
  • 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 May 11 '17 at 19:29
  • @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. – krc Jun 30 '17 at 17:49
  • 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.. – Kartikey Tanna Jun 16 '18 at 14:45
  • or `M-x windmove-` – nomad Sep 12 '20 at 05:38
11

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

jlf
  • 3,461
  • 2
  • 18
  • 14
  • 1
    Yes, and it's now built-in, so you just need to add `(windmove-default-keybindings)` to your init file. – TooTone Feb 09 '15 at 21:59
10

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.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • 1
    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. – George Mauer Jan 12 '11 at 23:40
0

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?

Community
  • 1
  • 1
Drew
  • 29,895
  • 7
  • 74
  • 104