Changing window faster in Emacs (or repeating last shortcut with a single strike)

若如初见. 提交于 2019-11-30 20:44:06

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...

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!