Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In screen, I can just type C-a :number 0 to move a window to the top of the window list and push all the other windows down one. What's the equivalent command sequence for tmux? I looked at the man page, but I'm finding it confusing on this point.

share|improve this question

migrated from stackoverflow.com Oct 6 '11 at 10:36

6 Answers

up vote 57 down vote accepted

The swap-window command is closest to what you want.

"Prefix :" (that is "Ctrl-B :" by default) brings you to the tmux-command prompt. There you enter:

swap-window -s 3 -t 1

to let window number 3 and window number 1 swap their positions.

To move the current window to the top, do:

move-window -t 0

(if base-index is 0, as it is by default).

You can bind that command to a key (T for "top" for example) by adding the following to your ~/.tmux.conf:

bind-key T swap-window -t 0
share|improve this answer
2  
Thanks for your edit, but move-window only works, if there is not another window at the given index. So in most cases, move-window -t 0 will not work, since usually there will be another window at that position already. – matlehmann Mar 21 at 15:32

The tmux equivalent to :number 42 is :move-window -t 42.

share|improve this answer
4  
This is bound to C-b . – vedang Jun 30 '11 at 12:59
1  
Thanks! This is much better than the accepted answer imo. – Arlen Feb 14 '12 at 22:27
2  
@ArlenCuss Actually both answers are good and useful. You see, using screen :number you could swap windows, using tmux's :move-window you can only relocate window if the target index is not in use. So, imo, both :swap-window and :move-window are necessary to grasp control over window locations :) – Victor Farazdagi Mar 20 '12 at 12:30
1  
+1 for getting an answer from a programming guru (also for being correct). This is the only way I could get it to work on an active window – engineerDave Jul 24 '12 at 13:37
1  
tmux's :move-window is not equivalent to screen's :number. :number swaps if the destination exists, :move-window fails in that case. You have to choose between :move-window and :swap-window – piec Jan 29 at 23:28

Adding to Gareth's answer, you can use the following key bindings

bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1

Pressing Ctrl+Shift+Left (will move the current window to the left. Similarly right. No need to use the modifier (C-b).

share|improve this answer

Using swap-window to move to any id: [closest to screen's :number]

# window movement / renumbering like in screen's :number
bind-key m command-prompt -p "move window to:"  "swap-window -t '%%'"

[m for move --> hit prefix-m and enter say 3 . .to renumber window to 3]

share|improve this answer
1  
This is already nice, but even better would be: do swap-window and if it fails, fall back to move-window – nisc Dec 26 '11 at 15:18

You can implement an equivalent to screen's number command using an external shell script that chooses between swap-window and move-window. You can bind it to a key that way:

bind < command-prompt -p index "run-shell '~/.tmux.number.sh %%'"

~/.tmux.number.sh:

#!/bin/bash
if [ $# -ne 1 -o -z "$1" ]; then
    exit 1
fi
if tmux list-windows | grep -q "^$1:"; then
    tmux swap-window -t $1
else
    tmux move-window -t $1
fi
share|improve this answer
2  
Very nice solution, working great! I just made minor edits to cleanup and removed the -F option which is not accepted by my tmux version. – haridsv Jan 23 at 9:33

I think you want to bind a new key combination to the 'choose-window' command.

I know you said you've already read the man page, but you should refer back to it. you need to modify your ~/.tmux.conf file to add a bind-key command.

Specifically, look at page 4 of the following.

tmux man page

share|improve this answer
choose-window doesn't seem to move the current window to a new position. – dan Feb 2 '11 at 20:20

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.