Over a year ago, I released a plugin called tmux-fzf-open-files-nvim — a small tool for developers who live in tmux and use neovim as their daily driver. Since then, it’s been tried, tested, and refined by myself and others in real-world workflows.
Video demos can be found in the readme: Github
What Does It Do?
If you’ve ever wanted to open a file (even with line number information!) directly from a terminal command’s output — a grep result, a test failure, a stack trace — you know the pain of copying the path manually in tmux copy mode and switching context to open it in neovim.
tmux-fzf-open-files-nvim solves this.
It allows you to pipe output into a fzf tmux picker that extracts and filters file paths, lets you choose one or several with the tab key, and opens it in a new (or existing) neovim instance in another tmux pane. If line number information is included in the file, it will open the file in neovim at that line number (row,col).
How It Works
This plugin uses native linux tools awk and sed to parse file paths from any arbitrary terminal output.
Pipes (|) link together all stages of the operation to ensure reduced memory footprint and parallel processing. Pipes avoid storing entire data blobs in variables and instead stream line-by-line.
Extending the plugin
The utility for parsing files and opening an fzf popup in tmux is encapsulated into one script found in utilities/fzf-files.sh
. That means if you would like to use this as a part of a different workflow (perhaps you want to write a telescope extension) you can do so by running `./utilities/fzf-files.sh' which will output the user selected files.
Modes
Capture the output visible in the current pane
The default keybinding of prefix + F
will search the visible content in the current tmux pane for file paths.
Capture the entire history of the current pane:
The default keybinding of prefix + H
will search the history of the current pain for file paths.
Capture the entire history of all panes in a window:
The default keybinding of prefix + G
will search the history of all panes in a tmux window for file paths.
Requirements
Installation
TPM
If you’re using TPM (Tmux Plugin Manager), add this to your .tmux.conf:
set -g @plugin 'Peter-McKinney/tmux-fzf-open-files-nvim'
Reload tmux environment
tmux source ~/.tmux.conf
Then press prefix + I (capital I) to install
Note: I have sometimes noticed I have to completely reload tmux after this step by exiting tmux and opening it once more.
No TPM?
Clone the repository:
git clone https://github.com/Peter-McKinney/tmux-fzf-open-files-nvim ~/.tmux/plugins/tmux-fzf-open-files-nvim
Add a binding in your .tmux.conf:
bind-key F run-shell '~/.tmux/plugins/tmux-fzf-open-files-nvim/scripts/tmux-fzf-open-files-nvim.sh'
Reload your .tmux.conf:
tmux source ~/.tmux.conf
Keybindings:
Variable Name | Description | Default Binding |
---|---|---|
@open-file-nvim-key | Parses the current visible pane output for filenames | prefix + F |
@open-file-nvim-all-key | Parses the entire available history in the current pane for filenames | prefix + H |
@open-file-nvim-all-history-key | Parses the entire history from all panes in a window | prefix + G |
If you have ideas, feedback, or improvements, feel free to open an issue or submit a PR!
Top comments (0)