Moving focus and buffer between Emacs window

  |   Source

Please read the excellent article Moving between Emacs windows for basic setup.

Here is my summary of that article:

  • you can use windmove.el (embedded in Emacs). Its hotkey is Shift+Arrow
  • switch-window.el is great. The default hot key is C-x o

I also use other packages which is more efficient.

window-numbering.el

window-numbering.el is great. It uses hot key M-number to switch window (for example, M-3 to select window with number 3). So I can press only one key to switch window. Besides, it has some extra features like M-0 to jump to the minibuffer.

Here is my configuration for window-numbering.el:

(require 'window-numbering)
;; highlight the window number in pink color
(custom-set-faces '(window-numbering-face ((t (:foreground "DeepPink" :underline "DeepPink" :weight bold)))))
(window-numbering-mode 1)

Evil

Evil is a vim-emulation. It use vim's keybindings C-w h/j/k/l to move. Please note C-w h is more efficient than C-x o. It's because w key is more close than x key and h/j/k/l is easy to press.

buffer-move.el

buffer-move.el moves the buffer instead of focus between windows. It can be installed through MELPA.

Here is my configuration:

(global-set-key (kbd "C-c C-b C-k") 'buf-move-up)
(global-set-key (kbd "C-c C-b C-j") 'buf-move-down)
(global-set-key (kbd "C-c C-b C-h") 'buf-move-left)
(global-set-key (kbd "C-c C-b C-l") 'buf-move-right)

Optimization

I use keyfreq to record all my key pressing for more than six months.

According to the data collected by keyfreq, more than 99 percent of my moving focus between windows is done through window-numbering.el.

So it's necessary to optimize window-numbering.el further. By default, window-numbering.el uses M-num key to select window which is already efficient. But as a geek, I have a tendency to push the efficiency to the extreme end.

Finally I use hotkey ,1, ,2, and ,3 to switch to the window numbering 1, 2, and 3.

Here is the code:

(define-key evil-normal-state-map ",1" 'select-window-1)
(define-key evil-normal-state-map ",2" 'select-window-2)
(define-key evil-normal-state-map ",3" 'select-window-3)
(define-key evil-normal-state-map ",4" 'select-window-4)

Check my setup at github.

Comments powered by Disqus