Efficient Switching Between Multiple Windows
Table of Contents
1. TL;DR
Switching between multiple windows with Alt + Tab grows more and more tiresome and error-prone when the number of windows increases. Using PowerToys Command Palette on Windows, or KRunner on KDE Plasma, we can filter out our target window by its title, which is a much more efficient and scalable method than Alt + Tab.
2. The Problem
If you works on a PC, having multiple windows opening at the same time, and you need to constantly switching between them, you may find yourself in the same situation as me: it is difficult to locate the window you want to switch to without moving your hand away from the keyboard.
I used to Alt + Tab through the list of windows, and it is really convenient when you have only two windows to switch between. Though combining with Alt + Shift + Tab, which iterates through the window list in reverse direction, this can handle multiple windows somehow, it still feels exhausted to me to check if the correct windows is selected. What is worse, sometimes I just press Tab too many times so I move pass my target window.
After feeling burned out from iterating through the window list and missing my target time and time again, I decided to find a better solution for this problem. I took inspiration from my experience with Emacs.
3. Way to the Solution
Switching betwen OS windows is quite similar to switching between buffers in Emacs. In Emacs, instead of iterating through a list of all existing buffers, I can use the name of the buffer to filter out candidate buffers.
I prefer working in this way for multiple reasons.
- It does not introduce a transient state which requires you to hold a key to maintain. Using Alt + (Shift) + Tab does require you hold shift before you confirm your target.
- It is not about where you are but only about where you are aiming at.
Using the filtering method, you can quickly narrow down the candidate list with few key strokes and get exactly what you want. With some familiarity, you do not even look at the list to make sure it produces your target, because you know it always does. Even in the rare cases when it does not, you do not have to worry about accidentally leaving the state by releasing the key for a moment. You can take your time and figure out how to locate your target with minimal key strokes, which significantly reduces the time required to locate it next time..
How can I do this to OS windows? Since I frequently work on both Linux and Windows, I have to figure it out on both platforms.
4. PowerToys on Windows
Searching on Google leads me to this discussion, and one of the users mentioned PowerToys. It is a collection of utility programs, much like packages in Emacs, that makes your life in Windows easier. I use it to toggle light/dark theme on Windows, so I have some confidence in it and glad to give it a try.
The feature that helps with selecting windows is called "Window Walker", which is an extension of PowerToys Command Palette. To use it, you need to activate PowerToys Command Palette with the default shortcut WIN + Alt + Space, then type "<" to enable the extension. Then a list of existing Windows is displayed. You can use arrows keys to navigate the list, but this does not differ from Alt-Tabbing much. A better solution is to narrow down the list by inputting the title of your target window. When there is only one choice left, you can press Enter to select it to bring the window to front and focus on it.
This is mostly the same process of selecting a buffer in Emacs, except that you have to type an extra "<" to actually start filtering Windows. Fortunately, Window Walker supports a direct short cut to start searching for windows directly, without typing the extra "<". I bind it to Alt + Space.
5. KRunner On KDE Plasma
KDE Plasma is the Desktop Environment I use for Linux, so I am only going to explain how to do this for KDE Plasma.
There is a program similar to PowerToys Command Palette on KDE Plasma, KRunner. It also implements windows searching as a plugin, and I think it is better integrated into KRunner. In KRunner, all searching results from multiple plugins are placed in one single list, and you can customize the order of placing them on the list. I place the windows at the very beginning. So, when there are matching windows, they will be placed as the front-most candidates, and when there are no such windows, results from other plugins are easily accessible.
KRunner is bound to Alt + Space by default, so I can use the same key bindings to perform the same operation on different operating systems. Good for building muscle memory.
6. After Thoughts
Gladly, I find a uniform, cross-platform solution, at least from the interactive perspective, for my problem. Thanks for all the developers of PowerToys and KRunner. My experience of using Emacs is indispensable for the general direction of the solution. Thus, I also need to thank Emacs developers who came up with the interact paradigm, which works much better for me than Alt + Tab.