0

Sometimes I want to kill all windows besides the current one (or the one selected using -t).

Instead of killing each window using kill-window -t <window> how can I invert the selection, so that I kill every window except the current one (or the one selected using -t)?

I've tried kill-window -t[!1] or kill-window -t!(1) to kill all windows except window 1, but it fails.

1 Answer 1

1

You can write a key binding to do this:

  • new-session -d -s foo creates a new session
  • move-window -t foo: moves the current window to the new session
  • rename-session old give this session the name old so we can kill it later
  • switch-client -t foo: switch to the new session
  • kill-window -t 1 kill the first window that was created by default
  • kill-session -t old: kills the old session (and all remaining windows)
8
  • Thank you. Do you know the approaches I have tried failed? man tmux says it should support fnmatch(3), and [!1] is a glob(7) matching anything but 1 Commented Mar 11, 2021 at 18:40
  • Is there any reason you append a “:” to sessions as in -t old:? Wouldn’t -t old work just as fine? Commented Mar 11, 2021 at 18:42
  • Do you have any ideas on how to automatically rename the new session like the old one? Indeed, I need a variable holding the old name for this to work. Commented Mar 11, 2021 at 18:44
  • Just because it could match more than one window does not mean that it will operate on more than one. AFAIK the target is always for one session/window/pane. Commented Mar 11, 2021 at 18:54
  • Do you know whether it is possible to save the session name in a variable during a key binding? Commented Mar 12, 2021 at 5:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.