Fuzzy.nvim
Fuzzy matching APIs for neovim.
Backends
- FZF
- Fzy
Backends are the program that the result of your command get piped into
Installation
Packer
use { 'amirrezaask/fuzzy.nvim' }
Plug
Plug 'amirrezaask/fuzzy.nvim'
Commands
- Files
- Cd
- GFiles
- Buffers
- Rg
- Colors
- LspReferences
- LspWorkspaceSyms
- LspDocuemntSyms
Configuration Sample
nnoremap <leader><leader> <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').files{}<CR>
nnoremap <leader>fg <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').git_files{}<CR>
nnoremap ?? <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').rg{}<CR>
let g:config_location = "~/w/dotfiles"
map <leader>ec <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').files{cwd=vim.g.config_location}<CR>
map <leader>ea <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').files{cwd='~/.config/awesome', hidden = true}<CR>
map <leader>en <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').files{cwd='~/.config/nvim/', hidden = true}<CR>
let g:plugins_location = "~/.local/share/nvim/site/pack/packer/start/"
map <leader>fnp <cmd>lua require('fuzzy.builtin')(require'fuzzy.fzf').cd{cwd=vim.g.plugins_location}<CR>
Terminology:
Backend:
Backends process the floating buffer and get the result and pass it into callback. Backends are basically a table with two fields a process function that gets a buffer to read data from and a callback to pass the output to it, and a command name that fuzzy pipes data into.
Usage
You can use fuzzy.nvim APIs to create custom searches or use builtin ones as shown above in Configuration Sample or even create your own backends for any fuzzy finder you want, forexample this is the builtin backend for FZF:
local api = vim.api
return {
process = function(buf, callback)
local line = api.nvim_buf_get_lines(buf, 0, 2, -1)[1]
if line ~= nil and line ~= "" then
callback(line)
end
end,
command_name = "fzf",
}
You can also create your own functionality like all builtin functions in builtin.lua module. Forexample adding a functionality for choosing the colorscheme using fuzzy interface:
local function colors()
list(backend, vim.fn.getcompletion('', 'color'), function(color)
vim.cmd(string.format('colorscheme %s', color))
end
then you can bind this function to a keybinding or a command.
TODO
- [] Make floating buffer more beautiful
- [] Add Lua fuzzy finder to remove dependency to FZF, FZY