Hacking with fd, fzf, tmux, and neovim!


August 23, 2022

Reading time
2 min read

In the above quick 1-minute video, I progressively use fd and fzf to find and open a file in neovim. I slowly build up the command and create a zsh alias at the end. A special thanks to @joshmedeski for the idea and inspiration of the video.

First let's start by installing fd with brew (or whatever package manager you use)…

brew install fd

If we run fd it will list all files and folders from that directory


NOTE: A simple, fast and user-friendly alternative to find

Adding --type f will only show the files

fd --type f

Let's show the hidden files with --hidden

fd --type f --hidden

And remove the git files by adding --exclude .git

fd --type f --hidden --exclude .git

So, let's next install fzf with brew

brew install fzf

NOTE: fzf is a general-purpose command-line fuzzy finder.

Then we'll pull up our previous command and pipe the results through fzf, which will prompt us to search through the results.

fd --type f --hidden --exclude .git | fzf

Then we can pipe that through xargs nvim to open the selected file in Neovim

fd --type f --hidden --exclude .git | fzf | xargs nvim

NOTE: See the above video for the complete interaction.

We can also use fzf-tmux which will open a tmux pane at the bottom of the window

fd --type f --hidden --exclude .git | fzf-tmux | xargs nvim

However if you use -p it'll use a popup window instead

fd --type f --hidden --exclude .git | fzf-tmux -p | xargs nvim

And if you pass --reverse it'll flip the popup so the search is on top

fd --type f --hidden --exclude .git | fzf-tmux -p --reverse | xargs nvim

Now let's add that long command to our .zshrc file as an alias so we don't have to type that again.

alias v='fd --type f --hidden --exclude .git | fzf-tmux -p --reverse | xargs nvim'

Now source our config file, and now we have it!

Web Mentions

Tweet about this post and have it show up here!