fantasticsid
fantasticsid

Reputation: 707

Better window navigation in Emacs?

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?

Upvotes: 21

Views: 7496

Answers (5)

Damien Pollet
Damien Pollet

Reputation: 6598

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

Upvotes: 2

Drew
Drew

Reputation: 30708

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

Upvotes: 1

Daniel Gallagher
Daniel Gallagher

Reputation: 7125

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!

Upvotes: 2

swdev
swdev

Reputation: 5157

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

Upvotes: 0

Trey Jackson
Trey Jackson

Reputation: 74470

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)

Upvotes: 31

Related Questions