if I want to change windows in emacs I do C-x o and that's fine with me...but when I want to change window lots of times in a row C-x o is not so convenient...is there a way to change window with just one strike after first C-x o ? and in general...is there a (single) strike that would repeat my last shortcut?
4 Answers
I use C-tab to switch windows:
(global-set-key [C-tab] 'other-window)
Holding down the Control key, you can jump windows repeatedly just by hitting the tab key.
EDIT: my original answer contained the following
I don't think there's a built-in way to repeat last command for basic commands like this ...
This is no longer true. Emacs now contains repeat.el, which allows for exactly the behaviour rabidmachine9 asked for.
The following code will create a repeating other-window
, such that after pressing C-x o
the first time, pressing o
afterwards will continue moving to the next window.
(require 'repeat)
(defun make-repeatable-command (cmd)
"Returns a new command that is a repeatable version of CMD.
The new command is named CMD-repeat. CMD should be a quoted
command.
This allows you to bind the command to a compound keystroke and
repeat it with just the final key. For example:
(global-set-key (kbd \"C-c a\") (make-repeatable-command 'foo))
will create a new command called foo-repeat. Typing C-c a will
just invoke foo. Typing C-c a a a will invoke foo three times,
and so on.
See related discussion here:
http://batsov.com/articles/2012/03/08/emacs-tip-number-4-repeat-last-command/#comment-459843643
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/gnu.emacs.help/RHKP2gjx7I8"
(fset (intern (concat (symbol-name cmd) "-repeat"))
`(lambda ,(help-function-arglist cmd) ;; arg list
,(format "A repeatable version of `%s'." (symbol-name cmd)) ;; doc string
,(interactive-form cmd) ;; interactive form
;; see also repeat-message-function
(setq last-repeatable-command ',cmd)
(repeat nil)))
(intern (concat (symbol-name cmd) "-repeat")))
(global-set-key (kbd "C-x o") (make-repeatable-command 'other-window))
The function make-repeatable-command
than then be used to create other repeating commands, using the same template.

- 9,872
- 2
- 33
- 57
-
Thanks for the answer.Do I have to put the script in my .emacs ? – rabidmachine9 Feb 18 '11 at 21:25
-
1Yes, adding that line to your .emacs will set the key for every emacs session. To add it to your current session without restarting, just enter the line in the scratch buffer and type C-j afterwards. – Tyler Feb 18 '11 at 21:41
Check out windmove; it lets you just hold down a modifier key and press an arrow key to move to the window in that direction. I've been using it for years with the default modifier (shift) and strangely enough it doesn't interfere with my impulses to use shift-arrow text selection in other applications.
There's also an equivalent for frames, which I should really try...

- 43,532
- 6
- 101
- 124
-
1windmove and framemove are great. I used to have my own 'fast' key binding for `other-window`, but I abandoned it completely once I started using these packages. Switching windows by visual direction is so much more intuitive than cycling through them in whatever order they happen to be stored internally. – phils Feb 19 '11 at 01:25
Bit late to the party, but there is also window-numbering (known as 'window-number' in MELPA).
This includes a window number in the modeline -1-
, -2-
etc, and provides M-1
, M-2
etc key bindings to directly select them. Very quick.

- 1,320
- 9
- 9
You have, say, 10 windows in the frame, and you are doing M-x other-window
a lots of times in a row, I take it you mean to jump from, say window #2 to window #8 and then on to window #1 and so on. By doing lots of other-window
in a row, I would imagine you do nothing of importance until you reach the desired window.
See if universal-argument
bound to C-u
helps. In the 10 window frame, if you are in window #3 and want to go to window #9, you are hopping to the 6th next window. So you would do C-u 6 C-x o
. Or, you could as well do C-u -4 C-x o
and reach window #9 from window #3.

- 7,817
- 2
- 25
- 25