A Neovim fuzzy finder that updates on every keystroke.
FzfxLiveGrep-v6-1080p.mp4
Search
require("fzfx
with rg's-g *spec.lua -F
option.
- Features
- Requirements
- Install
- Usage
- Recommended Key Mappings
- Configuration
- Known Issues
- Alternatives
- Development
- Contribute
- Colors/icons, Windows and modern Neovim features support.
- Updates on every keystroke of user query and selection.
- Multiple variants to avoid manual input:
- Search by visual select.
- Search by cursor word.
- Search by yank text.
- Search by resume last search.
- Multiple data sources to avoid restart search flow:
- Exclude or include hiddens/ignores when searching files.
- Local or remote when searching git branches.
- Whole workspace or current buffer only when searching diagnostics.
- ...
- And a lot more.
Please see Demo for more use cases.
Note
This plugins supports latest stable and (possibly) nightly Neovim version.
- Neovim β₯ 0.10.
- fzf (mandatory).
- nerd-fonts (optional for icons).
- curl (optional for preview window label).
- rg (optional for live grep, by default use grep).
- fd (optional for find files, by default use find).
- bat (optional for preview files, by default use cat).
- git (mandatory for all git commands).
- delta (optional for preview git diff, show, blame).
- lsd/eza (optional for file explorer, by default use ls).
Besides those rust-written commands mentioned above (rg
/fd
/bat
), Windows users will have to install the linux shell environment and core utils, since basic shell commands such as echo
, mkdir
are internally required.
Click here to see how to install linux commands
There're many ways to install portable linux shell and core utils on Windows, personally I would recommend below two methods:
Install with the below 3 options:
-
In Select Components, select Associate .sh files to be run with Bash.
-
In Adjusting your PATH environment, select Use Git and optional Unix tools from the Command Prompt.
-
In Configuring the terminal emulator to use with Git Bash, select Use Windows's default console window.
After this step, git.exe and builtin linux commands(such as echo.exe, ls.exe, curl.exe) will be available in %PATH%
.
Run below powershell commands:
# scoop
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex
scoop bucket add extras
scoop install git # git, bash, sh
scoop install mingw # echo, grep, find, curl, ls, cat
scoop install coreutils # echo, grep, find, curl, ls, cat
Windows actually already provide some builtin commands (find.exe
, bash.exe
) in C:\Windows\System32
(or %SystemRoot%\system32
), but they are not the linux commands they are named after, while could override above installations. To fix it, we need to prioritize (move up) the git or scoop environment variables in %PATH%
.
With lazy.nvim
require("lazy").setup({
-- Optional for icons.
{ "nvim-tree/nvim-web-devicons" },
-- Optional for 'fzf' command.
{
"junegunn/fzf",
build = function()
vim.fn["fzf#install"]()
end,
},
{
"linrongbin16/fzfx.nvim",
-- Optional to avoid break changes between major versions.
version = "v8.*",
dependencies = { "nvim-tree/nvim-web-devicons", 'junegunn/fzf' },
config = function()
require("fzfx").setup()
end,
},
})
With packer.nvim
return require("packer").startup(function(use)
-- Optional for icons.
use({ "nvim-tree/nvim-web-devicons" })
-- Optional for 'fzf' command.
use({
"junegunn/fzf",
run = function()
vim.fn["fzf#install"]()
end,
})
use({
"linrongbin16/fzfx.nvim",
-- Optional to avoid break changes between major versions.
tag = "v8.0.0",
config = function()
require("fzfx").setup()
end,
})
end)
With vim-plug
call plug#begin()
" Optional for icons.
Plug 'nvim-tree/nvim-web-devicons'
" Optional for 'fzf' command.
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
" Optional to avoid break changes between major versions.
Plug 'linrongbin16/fzfx.nvim', { 'tag': 'v8.0.0' }
call plug#end()
lua require('fzfx').setup()
There're multiple commands provided, named with prefix Fzfx
. The sub commands indicates the user query's input method, (i.e. the variants) named with below conventions:
- Basic variant is named with
args
, accepts the following arguments as query content. For example search a file named "README.md" with:FzfxFiles args readme<CR>
, search a word "fzfx" with:FzfxLiveGrep args fzfx<CR>
. - Visual select variant is named with
visual
, uses visual selection as query content. - Cursor word variant is named with
cword
, uses the word text under cursor as query content. - Put (i.e. yank text) variant is named with
put
(just like press thep
key), uses the yank text as query content. - Resume last search variant is named with
resume
, uses the last search content as query content.
Note
The args
sub command can be omitted if there is no query text, e.g. :FzfxFiles<CR>
is equivalent to :FzfxFiles args<CR>
.
The visual select variant is the only variant that works in visual mode, other variants work in normal mode.
Below keys are binded by default:
- Exit keys (fzf
--expect
option)esc
: quit.double-click
/enter
: open/jump to file (or other behaviors for some specific commands).ctrl-q
: send lines to quickfix window.
- Preview keys
ctrl-]
: toggle preview.ctrl-f
: preview half page down.ctrl-b
: preview half page up.
- Select keys
ctrl-e
: toggle select.ctrl-a
: toggle select all.
FzfxFiles
(Find files)
-
Unrestricted variant is added and named with
unres_
prefix, all variants are:(unres_)args
(unres_)visual
(unres_)cword
(unres_)put
(unres_)resume
FzfxBuffers
(Find buffers)
FzfxGFiles
(Find git files)
-
Current directory only variant is added and named with
cwd_
prefix, all variants are:(cwd_)args
(cwd_)visual
(cwd_)cword
(cwd_)put
(cwd_)resume
FzfxLiveGrep
(Live grep)
-
Use
--
flag to pass raw options to search command (rg
/grep
). -
Unrestricted variant is added and named with
unres_
prefix. Current buffer only variant is added and named withbuf_
prefix. All variants are:(unres_/buf_)args
(unres_/buf_)visual
(unres_/buf_)cword
(unres_/buf_)put
(unres_/buf_)resume
FzfxBufLiveGrep
(Live grep only on current buffer)
-
This command is almost the same with the
FzfxLiveGrep
's current buffer only variant (buf_
), except the file name is removed for better user view. -
Use
--
flag to pass raw options to search command (rg
/grep
).
FzfxGLiveGrep
(Live grep via git grep
)
-
Use
--
flag to pass raw options to search command (git grep
).
FzfxGStatus
(Search git status, i.e. changed git files)
-
Current directory only variant is added and named with
cwd_
prefix. All variants are:(cwd_)args
(cwd_)visual
(cwd_)cword
(cwd_)put
(cwd_)resume
FzfxGBranches
(Search git branches)
- Press
enter
to checkout branch. - Select keys is disabled (since it is not allowed to checkout multiple branches).
-
Remote branch variant is added and named with
remote_
prefix. All variants are:(remote_)args
(remote_)visual
(remote_)cword
(remote_)put
(remote_)resume
FzfxGCommits
(Search git commits)
- Press
enter
to copy git commit SHA. - Select keys is disabled (since it is not allowed to copy multiple commits SHA).
-
Current buffer only variant is added and named with
buf_
prefix. All variants are:(buf_)args
(buf_)visual
(buf_)cword
(buf_)put
(buf_)resume
FzfxGBlame
(Search git blame)
- Press
enter
to copy git commit SHA. - Select keys is disabled (since it is not allowed to copy multiple commits SHA).
FzfxLspDefinitions
(Search lsp definitions)
-
There's only 1
args
variant, while it behaves likecword
, i.e. it always use cursor word as query content (instead of arguments). Because this command is to navigate lsp symbols, i.e. go to definitions. - Internal lsp protocol textDocument/definition.
FzfxLspTypeDefinitions
(Search lsp type definitions)
-
There's only 1
args
variant, while it behaves likecword
, i.e. it always use cursor word as query content (instead of arguments). Because this command is to navigate lsp symbols, i.e. go to type definitions. - Internal lsp protocol textDocument/typeDefinition.
FzfxLspImplementations
(Search lsp implementations)
-
There's only 1
args
variant, while it behaves likecword
, i.e. it always use cursor word as query content (instead of arguments). Because this command is to navigate lsp symbols, i.e. go to implementations. - Internal lsp protocol textDocument/implementation.
FzfxLspReferences
(Search lsp references)
-
There's only 1
args
variant, while it behaves likecword
, i.e. it always use cursor word as query content (instead of arguments). Because this command is to navigate lsp symbols, i.e. go to references. - Internal lsp protocol textDocument/references.
FzfxLspIncomingCalls
(Search lsp incoming calls)
-
There's only 1
args
variant, while it behaves likecword
, i.e. it always use cursor word as query content (instead of arguments). Because this command is to navigate lsp symbols, i.e. go to incoming calls. - Internal lsp protocol callHierarchy/incomingCalls.
FzfxLspOutgoingCalls
(Search lsp outgoing calls)
-
There's only 1
args
variant, while it behaves likecword
, i.e. it always use cursor word as query content (instead of arguments). Because this command is to navigate lsp symbols, i.e. go to outgoing calls. - Internal lsp protocol callHierarchy/outgoingCalls.
FzfxLspDiagnostics
(Search lsp diagnostics)
-
Current buffer only variant is named with
buf_
prefix. All variants are:(buf_)args
(buf_)visual
(buf_)cword
(buf_)put
(buf_)resume
FzfxCommands
(Search vim commands)
- Press
enter
to feed command into cmdline. - Select keys is disabled (since it is not allowed to feed multiple commands into cmdline).
-
Ex (builtin) command variant is named with
ex_
prefix. User command variant is named withuser_
prefix. All variants are:(ex_/user_)args
(ex_/user_)visual
(ex_/user_)cword
(ex_/user_)put
(ex_/user_)resume
FzfxKeyMaps
(Search vim key mappings)
- Press
enter
to execute key mapping. - Select keys is disabled (since it is not allowed to execute multiple key mappings).
-
Normal mode variant is named with
n_mode_
prefix. Insert mode variant is named withi_mode_
prefix. Visual/select mode variant is named withv_mode_
prefix. All variants are:(n_mode_/i_mode_/v_mode_)args
(n_mode_/i_mode_/v_mode_)visual
(n_mode_/i_mode_/v_mode_)cword
(n_mode_/i_mode_/v_mode_)put
(n_mode_/i_mode_/v_mode_)resume
FzfxMarks
(Search vim marks)
FzfxCommandHistory
(Search vim command history)
- Press
enter
to feed command into cmdline. - Select keys is disabled (since it is not allowed to feed multiple commands into cmdline). Preview keys is disabled (since there is nothing to preview).
-
Ex (builtin) command variant is named with
ex_
prefix. User command variant is named withuser_
prefix. All variants are:(ex_/user_)args
(ex_/user_)visual
(ex_/user_)cword
(ex_/user_)put
(ex_/user_)resume
FzfxFileExplorer
(Search and navigate in file explorer)
- Press
enter
to feed command into cmdline. - Select keys is disabled (since it is not allowed to feed multiple commands into cmdline).
-
Include hidden files variant is named with
hidden_
prefix. All variants are:(hidden_)args
(hidden_)visual
(hidden_)cword
(hidden_)put
(hidden_)resume
Click here to see vim scripts
" ======== files ========
" by args
nnoremap <space>f :\<C-U>FzfxFiles<CR>
" by visual select
xnoremap <space>f :\<C-U>FzfxFiles visual<CR>
" by cursor word
nnoremap <space>wf :\<C-U>FzfxFiles cword<CR>
" by yank text
nnoremap <space>pf :\<C-U>FzfxFiles put<CR>
" by resume
nnoremap <space>rf :\<C-U>FzfxFiles resume<CR>
" ======== live grep ========
" by args
nnoremap <space>l :\<C-U>FzfxLiveGrep<CR>
" by visual select
xnoremap <space>l :\<C-U>FzfxLiveGrep visual<CR>
" by cursor word
nnoremap <space>wl :\<C-U>FzfxLiveGrep cword<CR>
" by yank text
nnoremap <space>pl :\<C-U>FzfxLiveGrep put<CR>
" by resume
nnoremap <space>rl :\<C-U>FzfxLiveGrep resume<CR>
" ======== buffers ========
" by args
nnoremap <space>bf :\<C-U>FzfxBuffers<CR>
" ======== git files ========
" by args
nnoremap <space>gf :\<C-U>FzfxGFiles<CR>
" ======== git live grep ========
" by args
nnoremap <space>gl :\<C-U>FzfxGLiveGrep<CR>
" by visual select
xnoremap <space>gl :\<C-U>FzfxGLiveGrep visual<CR>
" by cursor word
nnoremap <space>wgl :\<C-U>FzfxGLiveGrep cword<CR>
" by yank text
nnoremap <space>pgl :\<C-U>FzfxGLiveGrep put<CR>
" by resume
nnoremap <space>rgl :\<C-U>FzfxGLiveGrep resume<CR>
" ======== git changed files (status) ========
" by args
nnoremap <space>gs :\<C-U>FzfxGStatus<CR>
" ======== git branches ========
" by args
nnoremap <space>br :\<C-U>FzfxGBranches<CR>
" ======== git commits ========
" by args
nnoremap <space>gc :\<C-U>FzfxGCommits<CR>
" ======== git blame ========
" by args
nnoremap <space>gb :\<C-U>FzfxGBlame<CR>
" ======== lsp diagnostics ========
" by args
nnoremap <space>dg :\<C-U>FzfxLspDiagnostics<CR>
" ======== lsp locations ========
" lsp definitions
nnoremap gd :\<C-U>FzfxLspDefinitions<CR>
" lsp type definitions
nnoremap gt :\<C-U>FzfxLspTypeDefinitions<CR>
" lsp references
nnoremap gr :\<C-U>FzfxLspReferences<CR>
" lsp implementations
nnoremap gi :\<C-U>FzfxLspImplementations<CR>
" lsp incoming calls
nnoremap gI :\<C-U>FzfxLspIncomingCalls<CR>
" lsp outgoing calls
nnoremap gO :\<C-U>FzfxLspOutgoingCalls<CR>
" ======== vim commands ========
" by args
nnoremap <space>cm :\<C-U>FzfxCommands<CR>
" ======== vim key maps ========
" by args
nnoremap <space>km :\<C-U>FzfxKeyMaps<CR>
" ======== vim marks ========
" by args
nnoremap <space>mk :\<C-U>FzfxMarks<CR>
" ======== file explorer ========
" by args
nnoremap <space>xp :\<C-U>FzfxFileExplorer<CR>
Click here to see lua scripts
-- ======== files ========
-- by args
vim.keymap.set(
"n",
"<space>f",
"<cmd>FzfxFiles<cr>",
{ silent = true, noremap = true, desc = "Find files" }
)
-- by visual select
vim.keymap.set(
"x",
"<space>f",
"<cmd>FzfxFiles visual<CR>",
{ silent = true, noremap = true, desc = "Find files" }
)
-- by cursor word
vim.keymap.set(
"n",
"<space>wf",
"<cmd>FzfxFiles cword<cr>",
{ silent = true, noremap = true, desc = "Find files by cursor word" }
)
-- by yank text
vim.keymap.set(
"n",
"<space>pf",
"<cmd>FzfxFiles put<cr>",
{ silent = true, noremap = true, desc = "Find files by yank text" }
)
-- by resume
vim.keymap.set(
"n",
"<space>rf",
"<cmd>FzfxFiles resume<cr>",
{ silent = true, noremap = true, desc = "Find files by resume last" }
)
-- ======== live grep ========
-- live grep
vim.keymap.set(
"n",
"<space>l",
"<cmd>FzfxLiveGrep<cr>",
{ silent = true, noremap = true, desc = "Live grep" }
)
-- by visual select
vim.keymap.set(
"x",
"<space>l",
"<cmd>FzfxLiveGrep visual<cr>",
{ silent = true, noremap = true, desc = "Live grep" }
)
-- by cursor word
vim.keymap.set(
"n",
"<space>wl",
"<cmd>FzfxLiveGrep cword<cr>",
{ silent = true, noremap = true, desc = "Live grep by cursor word" }
)
-- by yank text
vim.keymap.set(
"n",
"<space>pl",
"<cmd>FzfxLiveGrep put<cr>",
{ silent = true, noremap = true, desc = "Live grep by yank text" }
)
-- by resume
vim.keymap.set(
"n",
"<space>rl",
"<cmd>FzfxLiveGrep resume<cr>",
{ silent = true, noremap = true, desc = "Live grep by resume last" }
)
-- ======== buffers ========
-- by args
vim.keymap.set(
"n",
"<space>bf",
"<cmd>FzfxBuffers<cr>",
{ silent = true, noremap = true, desc = "Find buffers" }
)
-- ======== git files ========
-- by args
vim.keymap.set(
"n",
"<space>gf",
"<cmd>FzfxGFiles<cr>",
{ silent = true, noremap = true, desc = "Find git files" }
)
-- ======== git live grep ========
-- by args
vim.keymap.set(
"n",
"<space>gl",
"<cmd>FzfxGLiveGrep<cr>",
{ silent = true, noremap = true, desc = "Git live grep" }
)
-- by visual select
vim.keymap.set(
"x",
"<space>gl",
"<cmd>FzfxGLiveGrep visual<cr>",
{ silent = true, noremap = true, desc = "Git live grep" }
)
-- by cursor word
vim.keymap.set(
"n",
"<space>wgl",
"<cmd>FzfxGLiveGrep cword<cr>",
{ silent = true, noremap = true, desc = "Git live grep by cursor word" }
)
-- by yank text
vim.keymap.set(
"n",
"<space>pgl",
"<cmd>FzfxGLiveGrep put<cr>",
{ silent = true, noremap = true, desc = "Git live grep by yank text" }
)
-- by resume
vim.keymap.set(
"n",
"<space>rgl",
"<cmd>FzfxGLiveGrep resume<cr>",
{ silent = true, noremap = true, desc = "Git live grep by resume last" }
)
-- ======== git changed files (status) ========
-- by args
vim.keymap.set(
"n",
"<space>gs",
"<cmd>FzfxGStatus<cr>",
{ silent = true, noremap = true, desc = "Find git changed files (status)" }
)
-- ======== git branches ========
-- by args
vim.keymap.set(
"n",
"<space>br",
"<cmd>FzfxGBranches<cr>",
{ silent = true, noremap = true, desc = "Search git branches" }
)
-- ======== git commits ========
-- by args
vim.keymap.set(
"n",
"<space>gc",
"<cmd>FzfxGCommits<cr>",
{ silent = true, noremap = true, desc = "Search git commits" }
)
-- ======== git blame ========
-- by args
vim.keymap.set(
"n",
"<space>gb",
"<cmd>FzfxGBlame<cr>",
{ silent = true, noremap = true, desc = "Search git blame" }
)
-- ======== lsp diagnostics ========
-- by args
vim.keymap.set(
"n",
"<space>dg",
"<cmd>FzfxLspDiagnostics<cr>",
{ silent = true, noremap = true, desc = "Search lsp diagnostics" }
)
-- ======== lsp symbols ========
-- lsp definitions
vim.keymap.set(
"n",
"gd",
"<cmd>FzfxLspDefinitions<cr>",
{ silent = true, noremap = true, desc = "Goto lsp definitions" }
)
-- lsp type definitions
vim.keymap.set(
"n",
"gt",
"<cmd>FzfxLspTypeDefinitions<cr>",
{ silent = true, noremap = true, desc = "Goto lsp type definitions" }
)
-- lsp references
vim.keymap.set(
"n",
"gr",
"<cmd>FzfxLspReferences<cr>",
{ silent = true, noremap = true, desc = "Goto lsp references" }
)
-- lsp implementations
vim.keymap.set(
"n",
"gi",
"<cmd>FzfxLspImplementations<cr>",
{ silent = true, noremap = true, desc = "Goto lsp implementations" }
)
-- lsp incoming calls
vim.keymap.set(
"n",
"gI",
"<cmd>FzfxLspIncomingCalls<cr>",
{ silent = true, noremap = true, desc = "Goto lsp incoming calls" }
)
-- lsp outgoing calls
vim.keymap.set(
"n",
"gO",
"<cmd>FzfxLspOutgoingCalls<cr>",
{ silent = true, noremap = true, desc = "Goto lsp outgoing calls" }
)
-- ======== vim commands ========
-- by args
vim.keymap.set(
"n",
"<space>cm",
"<cmd>FzfxCommands<cr>",
{ silent = true, noremap = true, desc = "Search vim commands" }
)
-- ======== vim key maps ========
-- by args
vim.keymap.set(
"n",
"<space>km",
"<cmd>FzfxKeyMaps<cr>",
{ silent = true, noremap = true, desc = "Search vim keymaps" }
)
-- ======== vim marks ========
-- by args
vim.keymap.set(
"n",
"<space>mk",
"<cmd>FzfxMarks<cr>",
{ silent = true, noremap = true, desc = "Search vim marks" }
)
-- ======== file explorer ========
-- by args
vim.keymap.set(
"n",
"<space>xp",
"<cmd>FzfxFileExplorer<cr>",
{ silent = true, noremap = true, desc = "File explorer" }
)
To configure options, please use:
require('fzfx').setup(opts)
The opts
is an optional lua table that override the default options.
For complete default options, please see config.lua.
For advanced configurations, please check Advanced Configuration.
Here's a minimal example that implement the ls -1
like FzfxLs
command:
FzfxLs-v2.mp4
Click here to see how to configure
require("fzfx").setup()
require("fzfx").register("ls", {
--- @type fzfx.CommandConfig
command = {
name = "FzfxLs",
desc = "File Explorer (ls -1)",
},
variants = {
{
name = "args",
feed = "args",
default_provider = "filter_hiddens",
},
{
name = "hidden_args",
feed = "args",
default_provider = "include_hiddens",
},
},
--- @type table<string, fzfx.ProviderConfig>
providers = {
filter_hiddens = {
key = "ctrl-h",
provider = { "ls", "--color=always", "-1" },
provider_type = "COMMAND_ARRAY",
},
include_hiddens = {
key = "ctrl-u",
provider = { "ls", "--color=always", "-1a" },
provider_type = "COMMAND_ARRAY",
},
},
--- @type table<string, fzfx.PreviewerConfig>
previewers = {
filter_hiddens = {
previewer = function(line)
-- each line is either a folder or a file
return vim.fn.isdirectory(line) > 0 and { "ls", "--color=always", "-lha", line }
or { "cat", line }
end,
previewer_type = "COMMAND_ARRAY",
},
include_hiddens = {
previewer = function(line)
return vim.fn.isdirectory(line) > 0 and { "ls", "--color=always", "-lha", line }
or { "cat", line }
end,
previewer_type = "COMMAND_ARRAY",
},
},
actions = {
["esc"] = function(lines)
-- do nothing
end,
["enter"] = function(lines)
for _, line in ipairs(lines) do
vim.cmd(string.format([[edit %s]], line))
end
end,
},
fzf_opts = {
"--multi",
{ "--prompt", "Ls > " },
},
})
First setup this plugin, then use require("fzfx").register(name, opts})
api to create your own searching command.
For detailed explanation of each components, please see A Generic Schema for Creating FZF Command and schema.lua.
To help easier customizing/integrating, fzfx provides below modules and APIs.
It's highly recommended to use these APIs when you're creating a new searching command, rather than start from scratch, since they are usually robust and take various situations into consideration.
-
fzfx.cfg
: Top-level configurations that directly register the searching command, such asFzfxFiles
,FzfxLiveGrep
, etc. Each module is an independent configuration. -
fzfx.helper
: Line-oriented utilities for parsing user input, query results and rendering the lines for (both left side and right side of) the fzf binary. Since a searching command is actually all about the lines: generating, previewing and invoking binded function on the lines. -
fzfx.lib
: Fundamental infrastructures, fzfx provides a set of plugin-logic non-related infrastructures to help user implement their own logic. -
fzfx.commons
: Embedded commons.nvim library as a common utility lua library, please refer to the commons.nvim's documentation for more details.The
commons.nvim
library was originally part offzfx.lib
, since I found they're so commonly used and I almost need them for every of my Neovim plugins, I extracted them into this library.
Please see API References for more details.
Please see Known Issues if you encountered any issue.
Note
This plugin no longer supports nvim native buffer previewer since v8.x, I would recommend fzf-lua if you need it.
- fzf.vim: Things you can do with fzf and Vim.
- fzf-lua: Improved fzf.vim written in lua.
- telescope.nvim: Find, Filter, Preview, Pick. All lua, all the time.
To develop the project and make PR, please setup with:
To run unit tests, please install below dependencies:
Then test with vusted ./spec
.
Please open issue/PR for anything about fzfx.nvim.
Like fzfx.nvim? Consider