Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Using FZF to Preview Text Files on the Command Line and within Vim

blog/cards/using-fzf-to-preview-text-files-on-the-command-line-and-within-vim.jpg

Here's a video going over how to set up a Shell alias to preview files. It also works out of the box with Vim using the fzf.vim plugin.

Quick Jump: Demo

FZF is extremely useful on the command line to reverse search your history with CTRL+r. I’ve made a video about that a few years ago, but FZF can also fuzzy find files using CTRL+t.

You can take this one step further to have FZF recursively find all files in a directory and then you can quickly preview them with paging support . You can also set up an alias to make it easy to access and even get syntax highlighting if you use the bat tool.

Demo

Alias

alias pf="fzf --preview='less {}' --bind shift-up:preview-page-up,shift-down:preview-page-down"

Timestamps

  • 0:08 – I’ve made videos in the past about reverse searching your history with FZF
  • 0:18 – Running the FZF command on its own
  • 0:37 – Using the built in CTRL+t bind with FZF to fuzzy search files on the command line
  • 0:57 – Previewing files on the command line with FZF using less
  • 1:59 – Using different commands to preview files, such as head for the first 30 lines
  • 2:24 – Using bat to get syntax highlighting in your previewed files
  • 4:06 – Creating custom FZF binds to page through results and setting up a Shell alias
  • 5:59 – You can preview files with the FZF Vim plugin by default too
  • 7:08 – Recap and any questions?

What types of files are you going to preview using this method? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments