Integrating fzf into tmux for Efficient Navigation

Created Updated
4 min read 666 words

Integrating fzf into tmux for Efficient Navigation

When working within tmux, navigating between windows, sessions, or panes can become time-consuming, especially in large setups. To make this process quicker and more efficient, you can integrate fzf—a powerful fuzzy finder—into your tmux workflow.

In this guide, we will walk through how to integrate fzf into tmux and cover additional plugins that enhance file and URL selection with fzf.

Prerequisites

Before we begin, make sure you have the following tools installed:

  1. tmux – A terminal multiplexer that lets you switch between several programs in one terminal.
  2. fzf – A general-purpose fuzzy finder for the command line.
  3. fpp (PathPicker) – A tool for selecting files and directories from text output (e.g., git status or grep).

You can install these using your system’s package manager:

# For MacOS
brew install tmux fzf fpp

# For linux
sudo pacman -S tmux fzf fpp

Step 1: Install tmux-fzf Plugin

The easiest way to integrate fzf with tmux is by using the tmux-fzf plugin. If you’re using the tmux plugin manager (tpm) , you can install this plugin by adding the following line to your .tmux.conf:

set -g @plugin 'sainnhe/tmux-fzf'

Once you’ve added the line, reload the tmux configuration or restart your tmux session. Then, install the plugin using the command:

# Press prefix + I (uppercase i)

This will install the tmux-fzf plugin.

Step 2: Configure fzf Options

You can further customize the behavior of fzf within tmux by setting some options in your .tmux.conf. Here’s an example configuration to make fzf more user-friendly:

# FZF
TMUX_FZF_LAUNCH_KEY="F"  # Key to launch fzf
TMUX_FZF_OPTIONS="-p -w 80% -h 80% -m"  # Launch with a popup, 80% width and height
TMUX_FZF_ORDER="window|session|pane|command|keybinding|clipboard|process"  # Order of search results

These options define the key binding to launch fzf, display it in a popup window that takes up 80% of the screen, and specify the order of items you can search through, such as windows, sessions, panes, commands, and more.

Step 3: Override Default Keybindings for Window and Session Switching

By default, tmux uses the w key to list windows and the s key to list sessions. With fzf, you can override these defaults for an improved navigation experience. Add the following key bindings to your .tmux.conf:

bind-key w run-shell -b "~/.tmux/plugins/tmux-fzf/scripts/window.sh switch"
bind-key s run-shell -b "~/.tmux/plugins/tmux-fzf/scripts/session.sh switch"

Now, pressing prefix + w will trigger fzf for window switching, and prefix + s will trigger fzf for session switching.

Step 4: Open Files and URLs with fzf and fpp

To enhance your workflow further, you can add support for opening files and URLs directly from tmux using additional plugins. These plugins work with fzf and provide keybindings for more efficient file and URL management.

Add the following plugins to your .tmux.conf:

set -g @plugin 'tmux-plugins/tmux-fpp'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'wfxr/tmux-fzf-url'

After adding these lines, reload tmux and install the plugins using prefix + I.

With these plugins, you’ll have access to the following keybindings:

  • prefix + F – Open fzf to search for tmux commands.
  • prefix + w – Select windows using fzf.
  • prefix + s – Select sessions using fzf.
  • prefix + f – Open fpp and select a file to open with $EDITOR.
  • prefix + <C-f> – Select a filename using tmux-copycat.
  • prefix + u – Open fzf to search for a URL.
  • prefix + <C-u> – Select a URL using tmux-copycat.
  • o – Open a selected file or URL with tmux-open.

These keybindings streamline opening files, URLs, and searching through your tmux environment, allowing you to maintain your workflow’s efficiency.

Final Thoughts

With fzf integrated into tmux and additional plugins like fpp and tmux-open, you’ll experience faster navigation and easier file/URL handling, reducing time spent on manual searches. It’s a small but powerful productivity boost for any tmux user.

Add comment below...

Please refresh the page if commenting system is not visible.
Further reading