How to switch to next window in tmux?

Quick Answer

To switch to the next window in tmux, press Ctrl+b n. For the previous window, use Ctrl+b p. You can also jump directly to a specific window with Ctrl+b 0-9 or select from a list with Ctrl+b w.

Ctrl+b n

Detailed Explanation

Windows in tmux are similar to tabs in a browser, allowing you to organize multiple workspaces within a single session. Efficiently navigating between these windows is a core part of a productive tmux workflow.

Sequential Window Navigation

# Move to the next window
Ctrl+b n

# Move to the previous window
Ctrl+b p

# Move to the last active window
Ctrl+b l

These commands cycle through windows sequentially based on their index numbers. They wrap around, so moving "next" from the last window takes you to window 0.

Direct Window Selection by Number

# Jump directly to window 0-9
Ctrl+b 0  # Jump to window 0
Ctrl+b 1  # Jump to window 1
...
Ctrl+b 9  # Jump to window 9

This is the fastest way to navigate when you know the window index. Tmux windows are zero-indexed, so your first window is window 0. Note that this method only works for windows 0-9; for windows with higher indexes, you'll need to use another method.

Interactive Window Selection

# Show window list for selection
Ctrl+b w

This opens an interactive list of all windows in all sessions. Navigate with arrow keys and press Enter to select. This is particularly useful when you have windows with descriptive names or when you want to see all available windows across all sessions.

Finding Windows by Name

# Search for a window by name
Ctrl+b f

When you have many windows, you can search for one by name. This is especially useful if you consistently name your windows based on their function or the project you're working on.

Using the Command Prompt

# Using the command prompt to select windows
Ctrl+b :select-window -t :0  # Select window 0
Ctrl+b :select-window -t :+  # Select next window
Ctrl+b :select-window -t :-  # Select previous window
Ctrl+b :select-window -t :name  # Select window by name

The command prompt approach gives you more flexibility, including the ability to select windows by name or use relative references like "next" (+) and "previous" (-).

Custom Key Bindings for Window Navigation

Add these to your ~/.tmux.conf for more convenient navigation:

# Use Alt+arrow keys to switch windows without prefix
bind -n M-Left previous-window
bind -n M-Right next-window

# Use Shift+arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window

# Use Alt+number for direct window selection without prefix
bind -n M-1 select-window -t 1
bind -n M-2 select-window -t 2
# And so on...

These custom bindings let you navigate windows without pressing the prefix key first, making window switching much faster.

Pro Tip

Rename your windows to make them easier to identify:

# Rename current window
Ctrl+b ,

Additionally, set automatic window renaming based on the running command:

# In ~/.tmux.conf
set-window-option -g automatic-rename on

Or disable it if you prefer manually named windows:

set-window-option -g automatic-rename off

Visual Window Navigation

Create a visually distinctive status bar to make window navigation easier:

# Add to ~/.tmux.conf
set-window-option -g window-status-current-style bg=red,fg=white,bold
set-window-option -g window-status-style bg=black,fg=white

This makes your current window stand out clearly in the status bar, helping you keep track of your position when rapidly switching between windows.