From ccb0cd27b2eca759993b5e74190e2df1ca6b99a1 Mon Sep 17 00:00:00 2001 From: "Anders N. Slinde" Date: Sun, 11 Jul 2021 09:54:02 +0200 Subject: Refactor whichkey config to make all keys overridable in user config (#813) --- lua/lv-which-key/config.lua | 30 +++++++++++++++++++++--------- lua/lv-which-key/init.lua | 29 +++-------------------------- 2 files changed, 24 insertions(+), 35 deletions(-) (limited to 'lua/lv-which-key') diff --git a/lua/lv-which-key/config.lua b/lua/lv-which-key/config.lua index bd244d74..d4c3f6bd 100644 --- a/lua/lv-which-key/config.lua +++ b/lua/lv-which-key/config.lua @@ -45,16 +45,28 @@ O.plugin.which_key = { noremap = true, -- use `noremap` when creating keymaps nowait = true, -- use `nowait` when creating keymaps }, + vopts = { + mode = "v", -- VISUAL 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 + }, + -- NOTE: Prefer using : over as the latter avoids going back in normal-mode. + -- see https://neovim.io/doc/user/map.html#:map-cmd + vmappings ={ + ["/"] = { ":CommentToggle", "Comment" }, + }, mappings = { - ["w"] = "Save", - ["q"] = "Quit", - ["."] = "LunarConfig", - ["/"] = "Comment", - ["c"] = "Close Buffer", - ["e"] = "Explorer", - ["f"] = "Find File", - ["h"] = "No Highlight", - [";"] = "Dashboard", + ["w"] = { "w!", "Save" }, + ["q"] = { "q!", "Quit" }, + ["/"] = { "CommentToggle", "Comment" }, + ["c"] = { "BufferClose", "Close Buffer" }, + ["e"] = { "lua require'lv-nvimtree'.toggle_tree()", "Explorer" }, + ["f"] = { "Telescope find_files", "Find File" }, + ["h"] = { 'let @/=""', "No Highlight" }, + [";"] = { "Dashboard", "Dashboard" }, p = { name = "Packer", c = { "PackerCompile", "Compile" }, diff --git a/lua/lv-which-key/init.lua b/lua/lv-which-key/init.lua index 81542ca4..37feca95 100644 --- a/lua/lv-which-key/init.lua +++ b/lua/lv-which-key/init.lua @@ -18,34 +18,10 @@ else end local opts = O.plugin.which_key.opts - --- Comments -vim.api.nvim_set_keymap("n", "/", ":CommentToggle", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("v", "/", ":CommentToggle", { noremap = true, silent = true }) --- dashboard -vim.api.nvim_set_keymap("n", ";", ":Dashboard", { noremap = true, silent = true }) --- Save -vim.api.nvim_set_keymap("n", "w", ":w!", { noremap = true, silent = true }) --- no hl -vim.api.nvim_set_keymap("n", "h", ':let @/=""', { noremap = true, silent = true }) --- Quit -vim.api.nvim_set_keymap("n", "q", ":q!", { noremap = true, silent = true }) --- open lv-config -vim.api.nvim_set_keymap( - "n", - ".", - ":e " .. CONFIG_PATH .. "/lv-config.lua", - { noremap = true, silent = true } -) --- explorer -vim.api.nvim_set_keymap( - "n", - "e", - ":lua require'lv-nvimtree'.toggle_tree()", - { noremap = true, silent = true } -) +local vopts = O.plugin.which_key.vopts local mappings = O.plugin.which_key.mappings +local vmappings = O.plugin.which_key.vmappings; -- if O.plugin.ts_playground.active then -- vim.api.nvim_set_keymap("n", "Th", ":TSHighlightCapturesUnderCursor", { noremap = true, silent = true }) @@ -84,3 +60,4 @@ end local wk = require "which-key" wk.register(mappings, opts) +wk.register(vmappings, vopts) -- cgit v1.2.3