Skip to main content

Command Palette

Search for a command to run...

Search, Preview and Edit with Nvim

Published
2 min read

When working on the console, every millisecond counts; regardless of the tools used, the pursuit of efficiency is paramount. As a source of satisfaction, finding the best way to combine individual tools to achieve results leads us to explore new ways of working.

This small function was born from that impulse. The pattern is familiar: you search for something with ripgrep, scan through a wall of file:line:match output, copy a path, open it, jump to the line. Each step is trivial, but the repetition adds up. It breaks the flow.

So I connected three tools into a single gesture.

https://gist.github.com/millancore/20d26e7befdc58c7386e2060c9a07383

The flow

vrg <pattern> sends your search through ripgrep, then hands the results to fzf for interactive filtering. As you move through the list, bat renders a syntax-highlighted preview of each file, with the matching line marked. When you find what you are looking for, you press enter and neovim opens exactly where you need to be. If nothing is relevant, escape and move on. Nothing opens, nothing changes.

The whole loop, from thought to cursor on the right line, collapses into a few keystrokes.

Setup

Drop the function into your .bashrc or .zshrc and make sure the four dependencies are installed: ripgrep, fzf, bat, and neovim.

If you prefer a different editor, replace nvim "+\({line}" "\){file}" with the equivalent command. Most editors accept a +line or :line flag.