Fast window switching without Alt-Tab or Command-Tab?

Note: latest version of this article can be found here.


Switching to most frequently used applications is best done by keyboard shortcuts. Here is how I do it on each of the three major platforms.

GNU/Linux

I use GNOME as the desktop environment. Avoiding the use of mouse in areas where the same function can be carried out much faster using the keyboard is highly recommended for the added productivity it offers.

For example, if you are using an external monitor configured using TwinView, it takes a while to move the mouse pointer from a window in your laptop display to a window in the external monitor. If your monitor resolution is high, then it takes even more time.

What follows is a list of functions which are usually done using the mouse, but have an equivalent keyboard-centric approach as documented here.

Switching to a particular window

Let's say that you have about 10 windows open and want to switch to a particular window. 80/20 rule applies here - most window switches you do are for a small subset of all possible windows. In my case, I more often switch to three applications: Emacs, Firefox and Terminal. It is thus more useful to bind predefined keys to these windows.

The following key combination, when pressed will activate the corresponding window.

ctrl + alt + u: Firefox
ctrl + alt + k: Emacs
ctrl + alt + j: Terminal

These are the most convenient shortcuts for me, but you can assign different keys as you wish.

The only question that remains is how do we do this? If you are using Sawfish, for instance, this is a no brainer task. But for other underpowered window managers like Metacity (default in Ubuntu), there is a solution: wmctrl. On Ubuntu, you can use apt-get to install wmctrl. After installing, try running the following commands:

$ wmctrl -a Firefox
$ wmctrl -a emacs
$ wmctrl -a Terminal

The -a option activates the window whose title matches with the argument given. To map the keys, we use xbindkeys. Install xbindkeys using apt-get and start writing the config file ~/.xbindkeysrc. The following is my configuration:

"wmctrl -a Firefox"
  m:0xc + c:30
  Control+Alt + u

"wmctrl -a Terminal"
  m:0xc + c:44
  Control+Alt + j

"wmctrl -a emacs"
  m:0xc + c:45
  Control+Alt + k

I usually use the xbindkeys -k command to come up with all those numeric codes you see above. For example, m:0xc corresponds to the Control+Alt key combination. You can also use xbindkeys-config, a graphical configuration utility, to create ~/.xbindkeysrc.

You may also consider adding xbindkeys to GNOME Session Preferences to ensure automatic startup on every boot.

Switching to a particular Firefox tab

Mouseless tab switching in Firefox can be done in several ways:

  1. Press Alt+n where n is the tab number. For example, press Alt+2 to switch to the second tab. Apart from switching to the first, second or third tab, this is usually not a very useful.

  2. Ubiquity's tab command. You press Ctrl+space and then type 'tab gmai' to switch to your Gmail tab. This is indeed useful especially when you have a lot of tabs opened. If the tab command is more frequently used than other commands beginning with t, then you can simply type 't gmai' instead of 'tab gmai'. Switching to a particular Emacs buffer

Emacs has the excellent ido mode that enables you to interactively fuzzy match buffer names when switching buffers. Normally, one presses C-x b in order to bring up the minibuffer and then types the buffer name manually with tab completion. With ido mode, typing 'ny', for example, will match the buffer main.py; and it does that interactively without you having to press Enter key. Use the following elisp code in your .emacs after adding ido.el to your path:

;; Buffer switching
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)

(global-set-key (kbd "M-i") 'ido-switch-buffer)

Now press Alt+i to switch buffers interactively.

The latest version of my own .xbindkeysrc can be found here.

Microsoft Windows

The same can also be done on Microsoft Windows using a program called AutoHotkey.

Here's the AutoHotKey script I use on my Windows-based laptop:

; match window title anywhere
SetTitleMatchMode 2

^!u::WinActivate Opera
^!j::WinActivate ActiveState Komodo
^!k::WinActivate sridharr@double
^!h::WinActivate Mozilla Thunderbird

Apple Mac OS X

On Mac, there is no Unixy way to assign global keyboard shortcuts (eg: xbindkeys) .. but there are several workarounds. Thanks to this serverfault post, I found Quicksilver to be a good enough way to assign keyboard shortcuts to activate specific applications.

For detailed instructions on assigning global keyboard shortcuts, follow this post. As the settings will be saved to the file ~/Library/Application Support/Quicksilver/Triggers.plist, you can easily move it around or symlink it to your Dropbox directory.


VistaSwitcher is an elegant and powerful task management utility for Windows OS. Once installed, it replaces the default Windows Alt-Tab dialog with a nice box that shows a list of all running tasks, with their names and preview snapshots, and enables the user to take actions on them using the mouse and keyboard shortcuts. With just one click, you can switch tasks, minimize, maximize, restore the main window, or close the process.

alt text

VistaSwitcher is freeware (like it predecessor Taskswitch XP)


Switcher for Windows Vista is extremely handy for this, especially when you always have at least 10+ windows open like me.

It has a feature where you can search the title names of all your open windows to find it faster (may be hard to see, check top right corner):

enter image description here