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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I write some functions in .bashrc to make tmux easy to use:

# .bashrc

# vim            tmux
#-----  --------------------
tabc()  { tmux kill-window; }
tabe()  { tmux new-window; }
tabf()  { tmux find-window $@; }
tabn()  { tmux next-window; }
tabo()  { ; }                         # <-- How to `tabonly`?
tabp()  { tmux previous-window; }
qa()    { tmux kill-session; }
sp()    { tmux split-window; }
vsp()   { tmux split-window -h; }
on()    { tmux kill-pane -a; }

typeset -fx tab{c,e,f,n,o,p} {,v}sp qa on

I want to implement the tabonly command, but don't know how.

share|improve this question
up vote 4 down vote accepted

With the window you want to keep as the current window, just call next-window and kill-window repeatedly, until next-window fails:

while tmux next-window 2> /dev/null; do
    tmux kill-window
share|improve this answer
This command works great! Thanks. – kev May 28 '12 at 4:33
The next release of tmux (i.e. 1.7) will have kill-window -a to kill all windows except the current window. – Chris Johnsen May 28 '12 at 7:57

For easy copying, tmux >= 1.7:

tabo()  { tmux kill-window -a; }

Thanks Chris Johnsen.

share|improve this answer

Your Answer


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.