From 7535dda26f102faf766b55c037fa76c6c772f5a0 Mon Sep 17 00:00:00 2001 From: Abdulrahman Sheikho Date: Thu, 19 Mar 2026 22:38:13 +0300 Subject: [PATCH] add-plugin: fzf-lua - add `which-key` groups, with additional `which-key` config. - solve keymap conflict with `conform.nvim`. --- lua/plugins/conform.lua | 2 +- lua/plugins/fzf-lua.lua | 112 ++++++++++++++++++++++++++++++++++++++ lua/plugins/which-key.lua | 9 +++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 lua/plugins/fzf-lua.lua diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index 5792f75c..48527a23 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -5,7 +5,7 @@ return { cmd = { 'ConformInfo' }, keys = { { - 'f', + 'F', function() require('conform').format { async = true, lsp_format = 'fallback' } end, diff --git a/lua/plugins/fzf-lua.lua b/lua/plugins/fzf-lua.lua new file mode 100644 index 00000000..60f58df9 --- /dev/null +++ b/lua/plugins/fzf-lua.lua @@ -0,0 +1,112 @@ +return { + 'ibhagwan/fzf-lua', + -- optional for icon support + dependencies = { + 'nvim-mini/mini.nvim', -- for mini.icons + 'nvim-treesitter/nvim-treesitter', + }, + config = function() + local fl = require 'fzf-lua' + fl.setup { + lsp = { + symbols = { + symbol_icons = Glyphs.kinds, + }, + }, + } + + -- fuzzy-find specific + vim.keymap.set('n', 'fl', fl.blines, { desc = 'Find line - current buf' }) + vim.keymap.set('n', 'fL', fl.lines, { desc = 'Find line - open buffers' }) + vim.keymap.set('n', 'ff', fl.files, { desc = 'Find files' }) + vim.keymap.set('n', 'o', fl.buffers, { desc = '[O]pen buffers' }) + vim.keymap.set('n', 'fR', fl.history, { desc = 'Recent files & buffers' }) + vim.keymap.set('n', 'fr', fl.oldfiles, { desc = 'Recent files' }) + vim.keymap.set('n', 'ft', fl.treesitter, { desc = 'Treesiter objects' }) + vim.keymap.set('n', 'fn', function() + fl.files { cwd = '~/.config/nvim/' } + end, { desc = 'Neovim config files' }) + vim.keymap.set('n', 'fN', function() + fl.files { cwd = '~/.local/share/nvim/lazy/' } + end, { desc = 'Neovim plugins src' }) + + -- grep specific + vim.keymap.set('n', 'gb', fl.grep_curbuf, { desc = 'Grep current buffer' }) + vim.keymap.set('n', 'gG', fl.grep_project, { desc = 'Grep project' }) + vim.keymap.set('n', 'gg', fl.live_grep, { desc = 'Grep a pattern' }) + vim.keymap.set({ 'n', 'v' }, 'gv', fl.grep_visual, { desc = 'Grep with visual selection' }) + vim.keymap.set('n', 'gw', fl.grep_cword, { desc = 'Grep word under cursor' }) + vim.keymap.set('n', 'gW', fl.grep_cWORD, { desc = 'Grep WORD under cursor' }) + vim.keymap.set('n', 'g.', function() + fl.grep { resume = true } + end, { desc = 'Resume last grep' }) + vim.keymap.set('n', 'gN', function() + fl.live_grep { cwd = '~/.local/share/nvim/lazy/' } + end, { desc = 'Grep Neovim plugins src' }) + + -- Git specific + vim.keymap.set('n', 'GC', fl.git_bcommits, { desc = 'Git: commits - current buf' }) + vim.keymap.set('n', 'GS', fl.git_stash, { desc = 'Git: stash' }) + vim.keymap.set('n', 'Gb', fl.git_branches, { desc = 'Git: branches' }) + vim.keymap.set('n', 'Gc', fl.git_commits, { desc = 'Git: commits' }) + vim.keymap.set('n', 'Gd', fl.git_diff, { desc = 'Git: diff' }) + vim.keymap.set('n', 'Gf', fl.git_files, { desc = 'Git: files' }) + vim.keymap.set('n', 'Gh', fl.git_hunks, { desc = 'Git: hunks' }) + vim.keymap.set('n', 'Gs', fl.git_status, { desc = 'Git: status' }) + vim.keymap.set('n', 'Gw', fl.git_worktrees, { desc = 'Git: worktrees' }) + + -- LSP specific + vim.keymap.set({ 'n', 'v' }, 'la', fl.lsp_code_actions, { desc = 'LSP: code actions' }) + vim.keymap.set({ 'n', 'v' }, 'lD', fl.lsp_declarations, { desc = 'LSP: declaration' }) + vim.keymap.set({ 'n', 'v' }, 'ld', fl.lsp_definitions, { desc = 'LSP: definition' }) + vim.keymap.set({ 'n', 'v' }, 'li', fl.lsp_implementations, { desc = 'LSP: implementations' }) + vim.keymap.set({ 'n', 'v' }, 'lI', fl.lsp_incoming_calls, { desc = 'LSP: incoming calls' }) + vim.keymap.set({ 'n', 'v' }, 'lO', fl.lsp_outgoing_calls, { desc = 'LSP: outgoing calls' }) + vim.keymap.set({ 'n', 'v' }, 'lr', fl.lsp_references, { desc = 'LSP: references' }) + vim.keymap.set('n', 'ls', fl.lsp_document_symbols, { desc = 'LSP: symbols - current buf' }) + vim.keymap.set('n', 'lw', fl.lsp_workspace_symbols, { desc = 'LSP: symbols - workspace' }) + vim.keymap.set({ 'n', 'v' }, 'lt', fl.lsp_typedefs, { desc = 'LSP: type definition' }) + + -- Diagnostic specific + vim.keymap.set('n', 'dd', fl.diagnostics_document, { desc = 'List diagnostics - current buf' }) + vim.keymap.set('n', 'dw', fl.diagnostics_workspace, { desc = 'List diagnostics - workspace' }) + vim.keymap.set('n', 'dz', fl.spellcheck, { desc = 'Spelling mistakes' }) + + -- misc specific + vim.keymap.set('n', "f'", fl.marks, { desc = 'Marks' }) + vim.keymap.set('n', 'f:', fl.command_history, { desc = 'Command history' }) + vim.keymap.set('n', 'f"', fl.registers, { desc = 'Registers' }) + vim.keymap.set('n', 'f/', fl.search_history, { desc = 'Search history' }) + vim.keymap.set('n', 'f;', fl.jumps, { desc = 'Jump list' }) + vim.keymap.set('n', 'f.', fl.resume, { desc = 'Resume last command/query' }) -- conflict + vim.keymap.set('n', 'fh', fl.helptags, { desc = 'Help-Pages' }) + vim.keymap.set('n', 'fk', fl.keymaps, { desc = 'Keymaps' }) + vim.keymap.set('n', 'fm', fl.manpages, { desc = 'Man-Pages' }) + vim.keymap.set('n', 'fb', fl.builtin, { desc = 'Builtin pickers' }) + -- TODO: I should implement _clipboard history_ in fzf-lua + -- vim.keymap.set('n', 'fy', _I need to implement it_, { desc = 'Clipboard history' }) + + -- use fzf-lua for spelling suggestion + vim.keymap.set('i', '', function() + fl.spell_suggest { + winopts = { + height = 0.4, + width = 30, + relative = 'cursor', + }, + } + end, { desc = 'Spelling suggestions' }) + vim.keymap.set('n', 'z=', function() + fl.spell_suggest { + winopts = { + height = 0.4, + width = 30, + relative = 'cursor', + }, + } + end, { desc = 'Spelling suggestions' }) + + -- application specific + vim.keymap.set('n', 'fZ', fl.zoxide, { desc = 'Zoxide directories' }) + end, +} diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 4a096e85..bff38108 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -11,10 +11,19 @@ return { -- delay between pressing a key and opening which-key (milliseconds) delay = 0, icons = { mappings = false }, + sort = { 'local', 'order', 'group', 'desc', 'case', 'alphanum', 'mod' }, + + plugins = { + spelling = { enabled = false }, + }, -- Document existing key chains spec = { { 's', group = '[S]earch', mode = { 'n', 'v' } }, + { 'f', group = '[F]uzzy-find', mode = { 'n', 'v' } }, + { 'g', group = '[G]rep', mode = { 'n', 'v' } }, + { 'G', group = '[G]it', mode = { 'n', 'v' } }, + { 'l', group = '[L]SP', mode = { 'n', 'v' } }, { 't', group = '[T]oggle' }, { 'd', group = '[D]iangostic' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } },