From 1c510cbc395bb7f0cb1382b2035132076e19ce2c Mon Sep 17 00:00:00 2001 From: prrockzed Date: Wed, 2 Oct 2024 17:25:47 +0530 Subject: [PATCH] Moving to current which-key version to v1.6.0 Also added customization to which key popup. The conversion to the earlier is because of ease of configurating which-key --- lua/nvimdev/plugin_config/whichkey.lua | 216 ++++++++++++++++++------- lua/nvimdev/plugins/dump_plugins.lua | 8 +- 2 files changed, 161 insertions(+), 63 deletions(-) diff --git a/lua/nvimdev/plugin_config/whichkey.lua b/lua/nvimdev/plugin_config/whichkey.lua index 622fed6..d66f13f 100644 --- a/lua/nvimdev/plugin_config/whichkey.lua +++ b/lua/nvimdev/plugin_config/whichkey.lua @@ -1,74 +1,166 @@ -local status_ok, wk = pcall(require, "which-key") -if not status_ok then - return -end +local wk = require("which-key") local mappings = { - { "N", " enew ", desc = "New Buffer", nowait = true, remap = false }, - { "c", " BufferClose ", desc = "Close Buffer", nowait = true, remap = false }, - { "e", " NvimTreeToggle", desc = "Nvim Tree Toggle", nowait = true, remap = false }, - { "q", " q! ", desc = "Quit", nowait = true, remap = false }, - { "w", " w! ", desc = "Save", nowait = true, remap = false }, - { "f", " Telescope find_files ", desc = "Find Files", nowait = true, remap = false }, - { "p", " Telescope projects ", desc = "Projects", nowait = true, remap = false }, + ["e"] = { " NvimTreeToggle ", "Nvim Tree Toggle" }, + ["N"] = { " enew ", "New buffer" }, + ["w"] = { " w! ", "Save" }, + ["q"] = { " q! ", "Quit" }, + ["c"] = { " BufferClose ", "Close Buffer" }, + ["f"] = { " Telescope find_files ", "Find files" }, + ["p"] = { " Telescope projects ", "Projects" }, - -- Diagnostics - { "d", group = "Diagnostics", nowait = true, remap = false }, - { "db", " Telescope diagnostics bufnr=0 ", desc = "Buffer Diagnostics", nowait = true, remap = false }, - { "dp", " Telescope diagnostics ", desc = "Workspace Diagnostics", nowait = true, remap = false }, - -- Finding files/texts etc - { "F", group = "Find", nowait = true, remap = false }, - { "Fa", " Telescope find_files follow=true no_ignore=true hidden=true ", desc = "Find All", nowait = true, remap = false }, - { "Fl", " Telescope live_grep ", desc = "Find Text", nowait = true, remap = false }, - { "Fb", " Telescope buffers ", desc = "Find Buffers", nowait = true, remap = false }, - { "Fh", " Telescope help_tags ", desc = "Help Page", nowait = true, remap = false }, - { "Fo", " Telescope oldfiles ", desc = "Find Old Files", nowait = true, remap = false }, - { "Fk", " Telescope filetypes ", desc = "Find Types", nowait = true, remap = false }, - { "Fc", " Telescope current_buffer_fuzzy_find ", desc = "Find in Current Buffer", nowait = true, remap = false }, + -- Diagnostics + d = { + name = "Diagnostics", + b = { " Telescope diagnostics bufnr=0 ", "Buffer Diagnostics" }, + p = { " Telescope diagnostics ", "Workspace Diagnostics" }, + }, - -- Git - { "g", group = "Git", nowait = true, remap = false }, - { "gb", " Telescope git_branches ", desc = "Git branches", nowait = true, remap = false }, - { "gc", " Telescope git_commits ", desc = "Git commit", nowait = true, remap = false }, - { "gf", " Telescope git_files ", desc = "Git files", nowait = true, remap = false }, - { "gh", " Telescope git_stash ", desc = "Git stash", nowait = true, remap = false }, - { "gs", " Telescope git_status ", desc = "Git Status", nowait = true, remap = false }, + -- finding files/text etc + F = { + name = "Find", + a = { " Telescope find_files follow=true no_ignore=true hidden=true ", "Find All" }, + l = { " Telescope live_grep ", "Find Text" }, + b = { " Telescope buffers ", "Find Buffers" }, + h = { " Telescope help_tags ", "Help Page" }, + o = { " Telescope oldfiles ", "Find Old Files" }, + k = { " Telescope filetypes ", "File Types" }, + c = { " Telescope current_buffer_fuzzy_find ", "Find in Current Buffer" }, + }, + + + -- Git + g = { + name = "Git", + s = { " Telescope git_status ", "Git Status" }, + b = { " Telescope git_branches ", "Git branches" }, + c = { " Telescope git_commits ", "Git commit" }, + f = { " Telescope git_files ", "Git files" }, + h = { " Telescope git_stash ", "Git stash" }, + }, -- Buffer management using Barbar plugin - { "B", group = "Buffer", nowait = true, remap = false }, - { "Bc", " BufferCloseAllButCurrentOrPinned ", desc = "Delete Picked Buffer", nowait = true, remap = false }, - { "Bd", " BufferPickDelete ", desc = "Delete Picked Buffer", nowait = true, remap = false }, - { "Bf", " BufferFirst ", desc = "Move to First Buffer", nowait = true, remap = false }, - { "Bi", " BufferPick ", desc = "Buffer Pick", nowait = true, remap = false }, - { "Bl", " BufferLast ", desc = "Move to Last Buffer", nowait = true, remap = false }, - { "Bp", " BufferPin ", desc = "Pin/Unpin Buffer", nowait = true, remap = false }, - { "Bs", " BufferMoveStart ", desc = "Move Buffer to Start", nowait = true, remap = false }, - { "Bt", " BufferRestore ", desc = "Restore Buffer", nowait = true, remap = false }, - -- Buffer Ordering - { "Bo", group = "Order", nowait = true, remap = false }, - { "Bod", " BufferOrderByDirectory ", desc = "Order by Directory", nowait = true, remap = false }, - { "Bol", " BufferOrderByLanguage ", desc = "Order by Language", nowait = true, remap = false }, - { "Bon", " BufferOrderByBufferNumber ", desc = "Order by Buffer Number", nowait = true, remap = false }, - { "Bow", " BufferOrderByWindowNumber ", desc = "Order by Window Number", nowait = true, remap = false }, + B = { + name = "Buffer", + f = { " BufferFirst ", "Move to First Buffer" }, + l = { " BufferLast ", "Move to Last Buffer" }, + p = { " BufferPin ", "Pin/Unpin Buffer" }, + t = { " BufferRestore ", "Restore Buffer" }, + s = { " BufferMoveStart ", "Move Buffer to Start" }, + i = { " BufferPick ", "Buffer Pick" }, + d = { " BufferPickDelete ", "Delete Picked Buffer" }, + c = { " BufferCloseAllButCurrentOrPinned ", "Delete Picked Buffer" }, + o = { + name = "Order", + n = { " BufferOrderByBufferNumber ", "Order by Buffer Number" }, + d = { " BufferOrderByDirectory ", "Order by Directory" }, + l = { " BufferOrderByLanguage ", "Order by Language" }, + w = { " BufferOrderByWindowNumber ", "Order by Window Number" }, + }, + }, -- Update/Install plugins and languages extensions - { "s", group = "Update/Install", nowait = true, remap = false }, - -- For Lazy Plugin Manager - { "sl", group = "Lazy - Plugin Manager", nowait = true, remap = false }, - { "slc", " Lazy clean ", desc = "Clean", nowait = true, remap = false }, - { "sle", " Lazy health ", desc = "Health", nowait = true, remap = false }, - { "slh", " Lazy help ", desc = "Help", nowait = true, remap = false }, - { "slk", " Lazy check ", desc = "Check", nowait = true, remap = false }, - { "sll", " Lazy log ", desc = "Log", nowait = true, remap = false }, - { "slr", " Lazy reload ", desc = "Reload", nowait = true, remap = false }, - { "sls", " Lazy sync ", desc = "Sync", nowait = true, remap = false }, - { "slu", " Lazy update ", desc = "Update", nowait = true, remap = false }, + s = { + name = "Update/Install", + l = { + name = "Lazy - Plugin Manager", + s = { " Lazy sync ", "Sync" }, + k = { " Lazy check ", "Check" }, + h = { " Lazy help ", "Help" }, + c = { " Lazy clean ", "Clean" }, + e = { " Lazy health ", "Health" }, + l = { " Lazy log ", "Log" }, + u = { " Lazy update ", "Update" }, + r = { " Lazy reload ", "Reload" }, + }, + }, + + -- Setup Related Keymappings + z = { + name = "Setup Keys", + t = { " Telescope colorscheme ", "Colorschemes" }, + h = { " checkhealth ", "Checkhealth" }, + }, +} - -- Setup Releated Keymappings - { "z", group = "Setup Keys", nowait = true, remap = false }, - { "zt", " Telescope colorscheme ", desc = "Coloschemes", nowait = true, remap = false }, - { "zh", " checkhealth ", desc = "Checkhealth", nowait = true, remap = false }, +-- Configuring Which-Key +local setup = { + plugins = { + marks = true, -- shows a list of your marks on ' and ` + registers = true, -- shows your registers on " in NORMAL or in INSERT mode + spelling = { + enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions + suggestions = 20, -- how many suggestions should be shown in the list? + }, + -- the presets plugin, adds help for a bunch of default keybindings in Neovim + -- No actual key bindings are created + presets = { + operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion + motions = true, -- adds help for motions + text_objects = true, -- help for text objects triggered after entering an operator + windows = true, -- default bindings on + nav = true, -- misc bindings to work with windows + z = true, -- bindings for folds, spelling and others prefixed with z + g = true, -- bindings for prefixed with g + }, + }, + -- add operators that will trigger motion and text object completion + -- to enable all native operators, set the preset / operators plugin above + -- operators = { gc = "Comments" }, + key_labels = { + -- override the label used to display some keys. It doesn't effect WK in any other way. + -- For example: + -- [""] = "SPC", + -- [""] = "RET", + -- [""] = "TAB", + }, + icons = { + breadcrumb = "»", -- symbol used in the command line area that shows your active key combo + separator = "➜", -- symbol used between a key and it's label + group = "+", -- symbol prepended to a group + }, + popup_mappings = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + window = { + border = "rounded", -- none, single, double, shadow + position = "bottom", -- bottom, top + margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] + padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] + winblend = 0, + }, + layout = { + height = { min = 4, max = 25 }, -- min and max height of the columns + width = { min = 20, max = 50 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + align = "left", -- align columns left, center or right + }, + ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label + hidden = { "", "", "", "", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate + show_help = true, -- show help message on the command line when the popup is visible + triggers = "auto", -- automatically setup triggers + -- triggers = {""} -- or specify a list manually + triggers_blacklist = { + -- list of mode / prefixes that should never be hooked by WhichKey + -- this is mostly relevant for key maps that start with a native binding + -- most people should not need to change this + i = { "j", "k" }, + v = { "j", "k" }, + }, } -wk.add(mappings) +-- Setting for all the keys +local opts = { + mode = "n", -- NORMAL mode + prefix = "", + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = true, -- use `nowait` when creating keymaps +} + +wk.setup(setup) +wk.register(mappings, opts) + diff --git a/lua/nvimdev/plugins/dump_plugins.lua b/lua/nvimdev/plugins/dump_plugins.lua index c43ca39..4209ea2 100644 --- a/lua/nvimdev/plugins/dump_plugins.lua +++ b/lua/nvimdev/plugins/dump_plugins.lua @@ -4,7 +4,13 @@ local plugins_list = { -- which-key plugin { "folke/which-key.nvim", - { "folke/neoconf.nvim", cmd = "Neoconf" }, + version = "v1.6.0", + }, + { + "folke/neoconf.nvim", + cmd = "Neoconf" + }, + { "folke/lazydev.nvim", },