9

I want to be able to name my tmux windows and select them using fuzzy matching (similar to LustyJuggler or Ctrl-P in vim).

Is this possible with tmux?

5 Answers 5

4

Default tmux has almost exactly what you want:

C-b, Rename current window

C-b' (single quote) Prompt for window index to select

Note this 'window index' wording is a little misleading. This prompt actually accepts target-window which is quite powerful and includes:

  1. The start of a window name, such as `mysession:mywin'.
  2. As an fnmatch(3) pattern matched against the window name.

Not quite fuzzy matching but pretty close to it. So if you have your named windows

  • foo
  • bar
  • buz

you can jump between them very quickly:

  • C-b'fEnter
  • C-b'baEnter
  • C-b'buEnter
1
  • Nice! is there a way to make this case insensitive ?
    – Hritik
    Sep 23, 2023 at 7:11
3

Here are links to scripts that use fzf to fuzzy search and select a pane:

https://github.com/junegunn/fzf/wiki/Examples-(tmux)#select-pane

https://github.com/junegunn/fzf/wiki/Examples#tmux

I guess it won't be too hard to adjust those for fuzzy searching windows.

EDIT:

Change this line:

panes=$(tmux list-panes -s -F '#I:#P - #{pane_current_path} #{pane_current_command}')

To:

panes=$(tmux list-panes -s -F '#I:#P #W - #{pane_current_path} #{pane_current_command}')

(I added the #W which also prints the window name)

1

Tmux can't do that by default.

Google doesn't return many results and this question is number two or three depending on the query but these zsh scripts might be interesting.

0

I don't think that's necessary.

You can see the index of every window at the status line, then a PREFIX+number will bring you anywhere you want, much quicker than any search.

If you have so much windows to need a search, maybe they are too much.

1
  • 1
    I think you can not easily judge what's necessary for the OP... For example, I do not use multiple tmux windows, but separate terminal windows - about 20, often - on 16 virtual screens. My firefox has about 100 tabs open normally - do you think that's too much? I don't (Ok, sometimes...). Mar 25, 2016 at 6:43
0

You can name windows in tmux with the default keybinding prefix + , or by executing:

tmux rename-window "<the-name>"

I made a shell function to fuzzy find a tmux window by name (using fzf) and then switching to it:

tmux_fzf_window() {
    window_list=$(tmux list-windows -F '#{window_index} #{window_name}')
    window_index=$(echo "$window_list" | fzf | awk '{ print $1 }')
    tmux select-window -t $window_index
}

And I use it in my tmux.conf like this:

bind-key f run "tmux split-window -l 12 'bash -ci tmux_fzf_window'"

Then when you press prefix + F, a tmux pane appears at the bottom with a list of windows, that you can fuzzy filter and select to switch to that window.

Note: this overrides the default prefix + F keybinding which is set to "Find window", which works somewhat similar but less fuzzy and interactive.

Inspired by https://github.com/junegunn/fzf/wiki/Examples#tmux

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .