Code Monkey home page Code Monkey logo

fzfx.nvim's Introduction

fzfx.nvim

Neovim commons.nvim luarocks ci.yml codecov

FZF-based fuzzy finder running on a dynamic engine that parsing user query and selection on every keystroke.

FzfxLiveGrep-v3.mp4

Search fzfx with rg's -g *spec.lua option.

๐Ÿ“– Table of contents

โœจ Features

  • Icons & colors.
  • Windows support.
  • Lua support: preview lua defined vim commands and key mappings.
  • Parsing user query and selection on every keystroke, a typical use case is passing raw rg options via -- flag (see Demo).
  • 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 the hidden/ignored files when searching files.
    • Local or remote branches when searching git branches.
    • Workspace or only current buffer diagnostics when searching diagnostics.
    • ...
  • Maximized configuration.
  • And a lot more.

Please see Demo for more features & use cases.

โœ… Requirements

  • Neovim โ‰ฅ v0.7.0.
  • fzf.
  • Nerd-fonts (optional for icons).
  • rg (optional for live grep, by default use grep).
  • fd (optional for files, by default use find).
  • bat (optional for preview files, by default use cat).
  • curl (optional for preview window labels).
  • delta (optional for preview git diff, show, blame).
  • lsd/eza (optional for file explorer, by default use ls).

Windows

grep, find, cat, etc are unix/linux builtin commands, while on Windows we don't have a builtin shell environment, so install rust commands such as rg, fd, bat, etc should be better choice.

While still recommend Windows users install linux shell commands, since utils like echo, curl are internally used by somewhere.

Click here to see how to install linux commands

There're many ways to install portable linux shell and builtin commands on Windows, but 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.

    install-windows-git1.png
  • In Adjusting your PATH environment, select Use Git and optional Unix tools from the Command Prompt.

    install-windows-git2.png
  • In Configuring the terminal emulator to use with Git Bash, select Use Windows's default console window.

    install-windows-git3.png

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 uutils-coreutils     # echo, ls, cat
scoop install curl          # curl
scoop install grep          # grep

Note: install the rust-reimplementation uutils-coreutils instead of GNU coreutils, since some (for example ls) GNU commands is actually broken on Windows 10 x86_64 PC.

Fix conflicts between embedded commands in C:\Windows\System32 and portable linux commands

Windows actually already provide some commands (find.exe, bash.exe) in C:\Windows\System32 (or %SystemRoot%\system32), while they are not the linux commands they are named after, but could override our installations. To fix this issue, we could prioritize the git or scoop environment variables in %PATH%.

windows-path

Whitespace Escaping Issue

Click here to see how whitespace affect characters escaping

This plugin internally extends nvim, fzf and lua scripts to full path when launching command.

  1. Example on macOS:

    /Users/rlin/.config/nvim/lazy/fzf/bin/fzf --print-query --listen --query '' --preview 'nvim -n -u NONE --clean --headless -l /Users/rlin/.local/share/nvim/site/pack/test/start/fzfx.nvim/bin/general/previewer.lua 2 /Users/rlin/.local/share/nvim/fzfx.nvim/previewer_metafile /Users/rlin/.local/share/nvim/fzfx.nvim/previewer_resultfile {}' --bind 'start:execute-silent(echo $FZF_PORT>/Users/rlin/.local/share/nvim/fzfx.nvim/fzf_port_file)' --multi --preview-window 'left,65%,+{2}-/2' --border=none --delimiter ':' --prompt 'Incoming Calls > ' --expect 'esc' --expect 'double-click' --expect 'enter' >/var/folders/5p/j4q6bz395fbbxdf_6b95_nz80000gp/T/nvim.rlin/fIj5xA/2

  2. Example on Windows 10:

    C:/Users/linrongbin/github/junegunn/fzf/bin/fzf --query "" --header ":: Press \27[38;2;255;121;198mCTRL-U\27[0m to unrestricted mode" --prompt "~/g/l/fzfx.nvim > " --bind "start:unbind(ctrl-r)" --bind "ctrl-u:unbind(ctrl-u)+execute-silent(C:\\Users\\linrongbin\\scoop\\apps\\neovim\\current\\bin\\nvim.exe -n --clean --headless -l C:\\Users\\linrongbin\\github\\linrongbin16\\fzfx.nvim\\bin\\rpc\\client.lua 1)+change-header(:: Press \27[38;2;255;121;198mCTRL-R\27[0m to restricted mode)+rebind(ctrl-r)+reload(C:\\Users\\linrongbin\\scoop\\apps\\neovim\\current\\bin\\nvim.exe -n --clean --headless -l C:\\Users\\linrongbin\\github\\linrongbin16\\fzfx.nvim\\bin\\files\\provider.lua C:\\Users\\linrongbin\\AppData\\Local\\nvim-data\\fzfx.nvim\\switch_files_provider)" --bind "ctrl-r:unbind(ctrl-r)+execute-silent(C:\\Users\\linrongbin\\scoop\\apps\\neovim\\current\\bin\\nvim.exe -n --clean --headless -l C:\\Users\\linrongbin\\github\\linrongbin16\\fzfx.nvim\\bin\\rpc\\client.lua 1)+change-header(:: Press \27[38;2;255;121;198mCTRL-U\27[0m to unrestricted mode)+rebind(ctrl-u)+reload(C:\\Users\\linrongbin\\scoop\\apps\\neovim\\current\\bin\\nvim.exe -n --clean --headless -l C:\\Users\\linrongbin\\github\\linrongbin16\\fzfx.nvim\\bin\\files\\provider.lua C:\\Users\\linrongbin\\AppData\\Local\\nvim-data\\fzfx.nvim\\switch_files_provider)" --preview "C:\\Users\\linrongbin\\scoop\\apps\\neovim\\current\\bin\\nvim.exe -n --clean --headless -l C:\\Users\\linrongbin\\github\\linrongbin16\\fzfx.nvim\\bin\\files\\previewer.lua {}" --bind "ctrl-l:toggle-preview" --expect "enter" --expect "double-click" >C:\\Users\\LINRON~1\\AppData\\Local\\Temp\\nvim.0\\JSmP06\\2

But when there're whitespaces on the path, launching correct shell command becomes quite difficult, since it will seriously affected escaping characters. Here're two typical cases:

  1. C:\Program Files\Neovim\bin\nvim.exe: nvim installed in C:\Program Files directory.

    Please add executables (nvim.exe, fzf.exe) to %PATH% ($env:PATH in PowerShell), and set the env configuration:

    require("fzfx").setup({
      env = {
        nvim = 'nvim',
        fzf = 'fzf',
      }
    })

    This will help avoid the shell command issue.

  2. C:\Users\Lin Rongbin\opt\Neovim\bin\nvim.exe: user name (Lin Rongbin) contains whitespace.

    We still cannot handle the 2nd case because all lua scripts in this plugin will thus always contain whitespaces in their path.

Please always avoid whitespaces in directories and file names.

๐Ÿ“ฆ Install

Important

Please specify a version/tag (such as 'v5.*') to avoid break changes between major versions!

With lazy.nvim
require("lazy").setup({
  -- optional for icons
  { "nvim-tree/nvim-web-devicons" },

  -- optional for the 'fzf' command
  {
    "junegunn/fzf",
    build = function()
      vim.fn["fzf#install"]()
    end,
  },

  {
    "linrongbin16/fzfx.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons", 'junegunn/fzf' },

    -- specify version to avoid break changes
    version = 'v5.*',

    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 the 'fzf' command
  use({
    "junegunn/fzf",
    run = function()
      vim.fn["fzf#install"]()
    end,
  })

  use({
    "linrongbin16/fzfx.nvim",

    -- specify version to avoid break changes
    version = 'v5.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 the 'fzf' command
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }

" specify version to avoid break changes
Plug 'linrongbin16/fzfx.nvim', { 'tag': 'v5.0.0' }

call plug#end()

lua require('fzfx').setup()

๐Ÿš€ Commands

All commands are named with prefix Fzfx, the sub commands e.g. the variants are usually named with below rules:

  • Basic variant is named with args, accepts the following arguments as query content.
  • 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 (e.g. yank text) variant is named with put (just like press the p 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, which means no arguments. For example :FzfxFiles<CR> is equivalent to :FzfxFiles args<CR>.

But if you want to specify query content, for example fzfx, you will have to type :FzfxFiles args fzfx<CR>.

Below keys are binded by default:

  • Exit keys (fzf --expect option)
    • esc: quit.
    • double-click/enter: open/jump to file (behave different on some specific commands).
  • Preview keys
    • alt-p: 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.

Files & Buffers

FzfxFiles (Find Files)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
  2. Unrestricted variant is named with unres_ suffix.
Variant Mode Select Keys Preview Keys
(unres_)args N Yes Yes
(unres_)visual V
(unres_)cword N
(unres_)put N
(unres_)resume N

FzfxBuffers (Find Buffers)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
Variant Mode Select Keys Preview Keys
args N Yes Yes
visual V
cword N
put N
resume N

Grep

FzfxLiveGrep (Live Grep)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
  2. Use -- flag to pass raw options to search command (rg/grep).
  3. Unrestricted variant is named with unres_ suffix.
  4. Current buffer (only) variant is named with buf_ suffix.
Variant Mode Select Keys Preview Keys
(unres_/buf_)args N Yes Yes
(unres_/buf_)visual V
(unres_/buf_)cword N
(unres_/buf_)put N
(unres_/buf_)resume N

FzfxGLiveGrep (Live Git Grep)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
  2. Use -- flag to pass raw options to search command (git grep).
Variant Mode Select Keys Preview Keys
args N Yes Yes
visual V
cword N
put N
resume N

Git

FzfxGFiles (Find Git Files)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
  2. Current directory (only) variant is named with cwd_ suffix.
Variant Mode Select Keys Preview Keys
(cwd_)args N Yes Yes
(cwd_)visual V
(cwd_)cword N
(cwd_)put N
(cwd_)resume N

FzfxGStatus (Search Git Status, e.g. Git Changed Files)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
  2. Current directory (only) variant is named with cwd_ suffix.
Variant Mode Select Keys Preview Keys
(cwd_)args N Yes Yes
(cwd_)visual V
(cwd_)cword N
(cwd_)put N
(cwd_)resume N

FzfxGBranches (Find Git Branches)

Note

  1. Use enter to checkout branch.
  2. Remote branch variant is named with remote_ suffix.
Variant Mode Select Keys Preview Keys
(remote_)args N No Yes
(remote_)visual V
(remote_)cword N
(remote_)put N
(remote_)resume N

FzfxGCommits (Search Git Commits)

Note

  1. Use enter to copy git commit SHA.
  2. Current buffer (only) variant is named with buf_ suffix.
Variant Mode Select Keys Preview Keys
(buf_)args N No Yes
(buf_)visual V
(buf_)cword N
(buf_)put N
(buf_)resume N

FzfxGBlame (Search Git Blame)

Note

  1. Use enter to copy git commit SHA.
Variant Mode Select Keys Preview Keys
args N No Yes
visual V
cword N
put N
resume N

Lsp & Diagnostics

FzfxLsp{Locations} (Search Lsp Locations)

This is a group of several commands (and related LSP protocol methods):

Note

  1. The args variant has a different behavior, it always use cursor word instead of command arguments. Because most use cases are navigating symbol locations, for example mapping gd/gt/gi/gr to go to definitions/type definitions/implementations/references.
Variant Mode Select Keys Preview Keys
args N Yes Yes

FzfxLspDiagnostics (Search Diagnostics)

Note

  1. Use ctrl-q to send selected lines to quickfix window and quit.
  2. Current buffer (only) variant is named with buf_ suffix.
Variant Mode Select Keys Preview Keys
(buf_)args N Yes Yes
(buf_)visual V
(buf_)cword N
(buf_)put N
(buf_)resume N

Vim

FzfxCommands (Search Vim Commands)

Note

  1. Use enter to input vim command.
  2. Ex (builtin) commands variant is named with ex_ suffix.
  3. User commands variant is named with user_ suffix.
Variant Mode Select Keys Preview Keys
(ex_/user_)args N No Yes
(ex_/user_)visual V
(ex_/user_)cword N
(ex_/user_)put N
(ex_/user_)resume N

FzfxKeyMaps (Search Vim Key Mappings)

Note

  1. Use enter to execute vim key.
  2. Normal mode variant is named with n_mode_ suffix.
  3. Insert mode variant is named with i_mode_ suffix.
  4. Visual/select mode variant is named with v_mode_ suffix.
Variant Mode Select Keys Preview Keys
(n_mode_/i_mode_/v_mode_)args N No Yes
(n_mode_/i_mode_/v_mode_)visual V
(n_mode_/i_mode_/v_mode_)cword N
(n_mode_/i_mode_/v_mode_)put N
(n_mode_/i_mode_/v_mode_)resume N

Misc

FzfxFileExplorer (File Explorer)

Note

  1. Include hidden variant is named with hidden_ suffix.
Variant Mode Select Keys Preview Keys
(hidden_)args N Yes Yes
(hidden_)visual V
(hidden_)cword N
(hidden_)put N
(hidden_)resume N

๐Ÿ“Œ Recommended Key Mappings

Click here to see vim scripts
" ======== FzfxFiles (Find 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>

" ======== FzfxLiveGrep (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>

" ======== FzfxBuffers (Find Buffers) ========

" by args
nnoremap <space>bf :\<C-U>FzfxBuffers<CR>

" ======== FzfxGFiles (Find 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>

" ======== 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" }
)

-- ======== file explorer ========

-- by args
vim.keymap.set(
  "n",
  "<space>xp",
  "<cmd>FzfxFileExplorer<cr>",
  { silent = true, noremap = true, desc = "File explorer" }
)

๐Ÿ”ง Configuration

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.

Create Your Own Command

Here's a minimal commands group example that implement the ls -1 like command FzfxLs:

FzfxLs-v2.mp4
Click here to see how to configure
require("fzfx").setup({
  users = {
    ls = {
      --- @type CommandConfig
      command = {
        name = "FzfxLs",
        desc = "File Explorer (ls -1)",
      },
      variants = {
        {
          name = "FzfxLs",
          feed = "args",
          default_provider = "filter_hiddens",
        },
        {
          name = "FzfxLsU",
          feed = "args",
          default_provider = "include_hiddens",
        },
      },
      --- @type table<string, ProviderConfig>
      providers = {
        filter_hiddens = {
          key = "ctrl-h",
          provider = { "ls", "--color=always", "-1" },
        },
        include_hiddens = {
          key = "ctrl-u",
          provider = { "ls", "--color=always", "-1a" },
        },
      },
      --- @type table<string, 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_list",
        },
        include_hiddens = {
          previewer = function(line)
            return vim.fn.isdirectory(line) > 0 and { "ls", "--color=always", "-lha", line }
              or { "cat", line }
          end,
          previewer_type = "command_list",
        },
      },
      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 > " },
      },
    },
  },
})

You can also use the require("fzfx").register("ls", {...}) api to do that.

For detailed explanation of each components, please see A Generic Schema for Creating FZF Command and schema.lua.

API References

To help easier customizing/integrating, fzfx provides below builtin modules and APIs:

  • fzfx.cfg: Top-level configurations, e.g. directly create the FzfxFiles, FzfxLiveGrep, etc search commands. Easy to read and learn all the components used in those commands, as well as easy to copy and paste.

  • fzfx.helper: Line-oriented helper utilities for parsing and rendering user queries and lines, since a search command is actually all about the lines in (both left and right side of) the fzf binary: generate lines, preview lines, invoke callbacks on selected lines, etc.

  • fzfx.lib: Low-level fundamental infrastructures, fzfx use the commons lua library for most of the common utilities, please also refer to commons.nvim's documentation.

    The commons lua library was originally part of the fzfx.lib modules, since I found they're so commonly useful that I need them for most of my Neovim plugins, I extracted them from fzfx.lib and come up with this commons lua library.

Please see API References for more details.

๐Ÿชฒ Known Issues

Please see Known Issues if you encountered any issue.

๐Ÿ€ Credit

  • fzf.vim: Things you can do with fzf and Vim.
  • fzf-lua: Improved fzf.vim written in lua.

โœ๏ธ Development

To develop the project and make PR, please setup with:

To run unit tests, please install below dependencies:

Then test with vusted ./test.

๐ŸŽ Contribute

Please open issue/PR for anything about fzfx.nvim.

Like fzfx.nvim? Consider

Github Sponsor Wechat Pay Alipay

fzfx.nvim's People

Contributors

linrongbin16 avatar github-actions[bot] avatar roland-5 avatar savchenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.