8

I'm new to Emacs. I'm confused about the C-x o command. This command will move the focus to the other window. If I have many windows, which window will be selected as the target? What's the quickest way to do this?

Thanks

Just a learner
  • 26,690
  • 50
  • 155
  • 234

4 Answers4

16

"When there are more than two windows, this command moves through all the windows in a cyclic order, generally top to bottom and left to right." - Emacs Manual

http://www.gnu.org/software/libtool/manual/emacs/Other-Window.html

C-x o is as quick as any other if you just have two windows. When you have more than 2 windows though, it can be a pain getting to the one you want using C-x o.

The quickest way to move to a particular window to the left/right/top/bottom of the current window is Wind Move. It comes with Emacs 21 and above. You can use Shift + arrow key to move to a window.

http://www.emacswiki.org/emacs/WindMove

sgmonda
  • 2,615
  • 1
  • 19
  • 29
spk
  • 584
  • 5
  • 6
  • 3
    `M-x windmove-default-keybindings` flag had to be flipped for me to start using `shift+[direction]` – yurisich Jun 27 '12 at 12:36
  • Shift + arrow key is actually bound to mark setting stuff – Welgriv Aug 06 '20 at 14:28
  • windmove pre-dates shift selection, so the latter (if you have it enabled) introduces a conflict with the default windmove modifier -- but you can trivially customize windmove to use something other than Shift. – phils Aug 10 '20 at 23:20
10

First you've got to notice that "window" in Emacs slang means not what you may think it means. What is normally called a window is called "frame" in Emacs. What Emacs calls "window" is a split window inside a frame.

The easiest way to understand what C-x o does is by trying it out yourself.

In a running Emacs instance, first type C-x 2. Now the frame is split vertically into two windows. The cursor ("point") is in the upper of the two windows. Now type C-x 3 and you will have split the upper window horizontally again. All in all you've got three windows now.

Now type C-x o repeatedly to cycle through the different windows. That's it.

Once you've gotten used to the order in which the windows are cycled through, you can do multiple hops at once, thereby skipping some windows, by using the key combination together with a prefix argument. So say, you want to skip one window and thus jump two at once, type C-2 C-x o. This way you can quickly jump to the window you want.

(To return to a single window, type C-x 1.)

Thomas
  • 17,016
  • 4
  • 46
  • 70
0

In case such people like me brows the web with research engines to simplify the switching between more than one window I suggest this bindings key configuration (to put in your init file):

(global-set-key [s-left]  'windmove-left)
(global-set-key [s-right]  'windmove-right)
(global-set-key [s-up]  'windmove-up)
(global-set-key [s-down]  'windmove-down)

It bind windows direction switching to super (windows key) + arrows key direction. These case should come unbound.

EDIT

(windmove-default-keybindings 'super) is simpler code thanks to @phils comment below.

BTW if you work with gnome these keys might be bound to some windows moves so you'll have to change it.

Welgriv
  • 714
  • 9
  • 24
0

C-x o cycles though your opend windows in current frame. If you often have many opend windows, have a try of dim switch window. It displays window index visually and you can switch to a window using its index.

Ian Yang
  • 1,091
  • 8
  • 20