21

When I split window in emacs several times (under terminal) the whole screen is divided into several parts with hierarchical arrangement. In vim it is easy to switch between windows intuitively with Control-w + (h,j,k,l), but in Emacs I can only use Control-x + o to switch to "the other window", which probably would require several iterations to finally get to the window I intend. I wonder if there is a better way similar to that in Vim to easily navigate between windows?

fantasticsid
  • 707
  • 8
  • 16

5 Answers5

31

Have you tried WindMove? It comes bundled with Emacs 21+. You move around with Shift-up, Shift-down, Shift-left, and Shift-right, though you can change the modifier. From the docs:

;; Installation:
;;
;; Put the following line in your `.emacs' file:
;;
;;     (windmove-default-keybindings)         ; shifted arrow keys
;;
;; or
;;
;;     (windmove-default-keybindings 'hyper)  ; etc.
;;
;; to use another modifier key.
;;
;;
;; If you wish to enable wrap-around, also add a line like:
;;
;;    (setq windmove-wrap-around t)
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • 4
    I highly recommend adding Trey's FrameMove library as well. WindMove and FrameMove combined make window navigation an absolute breeze. http://trey-jackson.blogspot.com/2010/02/emacs-tip-35-framemove.html – phils Feb 01 '11 at 06:43
  • For Mac OS X Mavericks terminal, `Shift-up|down` donot work. Try this: http://zurktech.blogspot.ch/2014/01/emacs-windmove-and-mavericks-terminalapp.html – randomor Mar 22 '14 at 16:21
  • to use along `org-mode` have a look to : http://orgmode.org/manual/Conflicts.html, windmove section – AdrieanKhisbe Aug 26 '14 at 13:56
2

I find the default binding for other-window to be really tedious, too. I've defined the following in my .emacs:

(global-set-key [(control ?,)] (lambda () (interactive) (other-window -1)))
(global-set-key [(control ?.)] (lambda () (interactive) (other-window 1)))

Just find some easy-to-reach keybindings (I use a Dvorak layout, so C-, and C-. may not be as easy for you to reach), preferably right next to each other, to bind to those lambdas.

Also, I found the Emacs wiki a few months ago. Nifty Tricks has a nice list of ways to make Emacs easier to use!

Daniel Gallagher
  • 6,915
  • 25
  • 31
1

See switch-window. It will number windows to let you switch directly to the one you want.

jarib
  • 6,028
  • 1
  • 24
  • 27
Damien Pollet
  • 6,488
  • 3
  • 27
  • 28
  • I vote for this solution. WinMove conflicts with Evil Mode and reaching the arrow keys seems slower to me anyway than C-x o [number] (maybe it's just psychological) – Felix D. Oct 31 '14 at 01:10
1

In Icicles, by default C-x o is bound to the multi-command icicle-other-window-or-frame, which works this way:

  • With no prefix arg or a non-zero numeric prefix arg: If the selected frame has multiple windows, then this is other-window. Otherwise, it is other-frame.

  • With a zero prefix arg (e.g. C-0): If the selected frame has multiple windows, then this is icicle-select-window with windows in the frame as candidates. Otherwise (single-window frame), this is icicle-select-frame.

  • With plain C-u: If the selected frame has multiple windows, then this is icicle-select-window with windows from all visible frames as candidates. Otherwise, this is icicle-select-frame.

Well then, what are icicle-select-window and icicle-select-frame?

They are multi-commands that let you choose a window or frame to select by name. (You can bind them separately, if you want -- they each change their behavior based on their own prefix args.)

Window and frame names are taken from their displayed buffers, with [N] (N=1,2,...) appended if needed for a unique name if the same buffer is displayed in more than one window/frame.

Being multi-commands, you can choose by completing and/or cycling. Completion can be prefix, substring, regexp, or fuzzy.

http://www.emacswiki.org/emacs/Icicles_-_Multi-Commands

Drew
  • 29,895
  • 7
  • 74
  • 104
0

That was also my first experience with emacs. But, using windmove, I can suite it, they way I want it. I use this as the modifier for windmove :

(windmove-default-keybindings 'meta)

I use ALT for the navigation of windmove

swdev
  • 4,997
  • 8
  • 64
  • 106