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

tmux has the "move-window" command with which you can move a window to a specified empty index like so:

move-window -t 3

However, if index 3 is already taken you will not be able to move your current window to position 3.

I'm looking for an option that will allow me to move (insert) my window at position 3 even if it is already taken and then increase the window numbers for the other subsequent windows (for example the one that was originally at 3 will now be 4, the following will be 5 etc.)

share|improve this question

1 Answer

up vote 1 down vote accepted

The script below will allow you to do what you want. You can run it from a shell prompt or you can do:

:run "ins-move 2 5"

That example moves window two to the position before window five.

#!/bin/bash
for ((i=$1; i<$2-1; i++))
do
    tmux swap-window -s :$i -t :$((i+1))
done
share|improve this answer
Thanks! Works great - though I will have to adapt it to work even for cases like "5 2". At least now I know how it's done. – user67834 Feb 18 '11 at 22:02
@Andrei: I'm glad I was able to get you started. Please don't forget to mark answers accepted and to upvote when you feel it's appropriate. – Dennis Williamson Feb 18 '11 at 22:06
I upvoted your answer just now. Couldn't do it before because I just now got enough reputation points. – user67834 Feb 18 '11 at 22:33

Your Answer

 
discard

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