Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I frequently end up with more than ten windows in tmux. Later on, I close some of my older ones. Is there a way to renumber, say window 15, to window 3 (which doesn't exist anymore)? Or to pack them all up again, so that there are no empty slots? I'd like to do this because it is difficult to jump to higher numbered windows, because you can't do Ctrl+B, 15. I have to use Ctrl+B, w to list the windows and then type the letter corresponding to the window I want to open.

I know that I can swap windows. For example, I could create a new window (Ctrl+B, c) which would open in the empty slot 3. I can then swapw window 15 and window 3 and then close window 15. Obviously, this is a tedious approach.

How do you manage many windows in tmux?

share|improve this question
add comment

3 Answers 3

up vote 21 down vote accepted

Looks like you need this:

 move-window [-dk] [-s src-window] [-t dst-window]
               (alias: movew)
         This is similar to link-window, except the window at src-window
         is moved to dst-window.

Calling movew without parameters moves current window to first free position.

share|improve this answer
add comment

I often find myself in a situation where I have gaps in between window numbers, for example a session with windows:

1 3 4 8 9 13

I wrote a tmux script to reorder them without changing their respective order nor activating the 'renumbering-windows' option. The result:

1 2 3 4 5 6

Put the following in your .tmux.conf:

bind R                                      \
    set -g renumber-windows on\;            \
    new-window\; kill-window\;              \
    set -g renumber-windows off\;           \
    display-message "Windows reordered..."

Hit [PREFIX]-R to reorder windows (or change the binding). ps: i'm currently running tmux 1.9a.

share|improve this answer
add comment

tmux 1.7 has a couple of features that can help establish and maintain gapless/packed window numbers:

  • The move-window command learned a new -r option that will renumber all the windows in a session (either the current session, or one specified with the -t option).

    If you have a set of windows like { 1:A, 4:B, 15:C }, then you can run move-window -r to renumber them to { 1:A, 2:B, 3:C } (they will start with your base-index; 1 in this example).

  • When the renumber-windows session option is enabled, tmux will automatically renumber the windows of a session (as with move-window -r) after any window is closed.

    If you like this behavior, you can turn it on in the global value so that all sessions that to not override it will automatically have it enabled:

    set-option -g renumber-windows on
    
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.