I ran across this thread on easier window switching within emacs using the windmove-xxx commands on gnu.emacs.help a few days ago. It’s always nice to find out about commands I didn’t know about… kinda like C-x M-c M-butterfly. I have always used C-x o and C-x b to move between windows and buffers, but my work monitor is large enough to allow me to split my frame into four windows. Using C-x o to move around has been somewhat of an annoyance. The windmove commands allow you to move up, down, left, and right between windows using a prefix key and the arrows on your keyboard. I have added the following to my .emacs:
(windmove-default-keybindings 'meta)
If you invoke the command without an argument then shift is used as the prefix. I also had to place this below the turning on of pc-selection-mode because it also sets the M-up, M-down, M-left, and M-right keys.
20 responses so far ↓
I was unable to get this to work on Mac OS X. I’m going to try Ubuntu when I get home. Any hints for Mac OS X? I’m new to it.
Ah… Nice trick…
@Luke – I am using carbon emacs on Mac OS X. What version are you using?
It works perfectly for me on the zenitani’s carbon emacs.
This is a nice one. Thanks a lot.
I’m an Emacs heretic, and defined a whole mess of CUA-style bindings (C-o for find-file, C-s for save-buffer, etc.), so my arrow keys are spoken for with things like M-left as backward-word.
But I’ve found C-n for other-window and C-b for switch-to-buffer to be quite nice in my 3 window setup.
Works like a champ in Aquamacs
Does this work in XEMACS
brilliant!
Great tip ! I tried the (windmove-default-keybindings ‘meta) and works fine on my Powerbook with 10.4.5 and CarbonEmacs
windmove is great stuff. This is just my personal preference, but I bind the movement to a first-person shooting game like “WASD” key layout: C-l {C-e, C-s, C-d, C-f}. (Yes, C-l is a prefix key for me.) This helps me on those remoted ssh sessions to linux emacs. (well, okay, Meta/Alt Arrow-Key seems to be going through, but Control or Shift Arrow-Key doesn’t).
If you use GNU screen, you can also do this directional window movement tip (e.g. ‘bind “^d” focus down’).
Coming back to emacs: I use winner-mode in combination with windmove to give me more control with the windows. winner-mode is like a “browser back button” for your ever-changing windows configurations.
In my Linux, I bind keys the following way:
Alt+Up = previous frame
Alt+Down = next frame
Ctrl+Shift+Right = next file
Ctrl+Shift+Left = prev file
Ctrl+Shift+Up = next file (including special buffers *)
Ctrl+Shift+Down = prev special file
Ctrl+Tab = buffer switch
The idea is that this way you can easily go next/prev file without need to ‘cycle’.
My exact emacs config can be found here:
http://public.halogen-dg.com/browser/alex-emacs-settings/dotemacs-alex-common.el
That one was very nice.. I was about to give up.
tks!
Works well, Thanks!
This was very helpful! Thanks!
windmove does not work on XEmacs without some help. First, be sure and get an older version of windmove.el that does not call the function ‘window-inside-edges’. I downloaded windmove.el Version: 0.93 (beta) from here:
http://hovav.net/elisp/windmove-0.93.el
Next, you need to put some code in your init.el file that sits in the folder .xemacs/ (found in your home directory on *nix machines). The first line just loads the windmove code. After that is code was written by Hovav Shacham, the author of windmove.el, so that windmove will work on XEmacs:
good luck -rdb
This:
(windmove-default-keybindings ‘meta)
works great in standard windowed emacs, but it doesn’t work in console emacs (i.e. ‘emacs -nw’). To make it work in console mode, I have to use:
But this doesn’t work in standard (windowed) emacs. Does anyone know a good way to switch configuration based on whether I’m running emacs in non-windowed mode or not?
To answer my own question – here’s how to get it to work in X or console mode:
As a side comment, I took a look at what commands I use most often using command-frequency.el over a few weeks’ time. I then looked at the default keybindings for C- and found that I never used C-t (among other single letter keybindings).
Therefore, I bound the other-window function (C-x o) to C-t, and haven’t looked back. It’s easy to get to any window just by holding down Control and hitting ‘t’ until I get there. I will try this out to see if I like it better though.
Thanks.
Hey,
thank you so much E Jones ! that’s really powerfull, and that’s exactly what I was looking for.
Looking forward to learning new tips like this.
Thanks
Leave a Comment