diff --git a/autocommands.lua b/lua/autocommands.lua similarity index 100% rename from autocommands.lua rename to lua/autocommands.lua diff --git a/keymaps.lua b/lua/keymaps.lua similarity index 92% rename from keymaps.lua rename to lua/keymaps.lua index 50ddb2a..ae10bb6 100644 --- a/keymaps.lua +++ b/lua/keymaps.lua @@ -109,9 +109,27 @@ local mappings = { }, } +for _, file in ipairs(vim.fn.readdir(vim.fn.stdpath('config')..'/lua/user', [[v:val =~ '\.lua$']])) do + local uplugin = require('user.'..file:gsub('%.lua$', '')) + -- if (uplugin[1] ~= nil) then + if (uplugin.mappings ~= nil) then + for mode, keymaps in pairs(uplugin.mappings) do + -- Add new mode if not already existing + if (mappings[mode] == nil) then + mappings[mode] = {} + end + + for key, value in pairs(keymaps) do + mappings[mode][key] = value; + end + end + end + -- end +end + +local M = {} local which_key_queue = nil ---- Register queued which-key mappings -function which_key_register() +function M.which_key_register() if which_key_queue then local wk_avail, wk = pcall(require, "which-key") if wk_avail then @@ -123,9 +141,6 @@ function which_key_register() end end ---- Table based API for setting keybindings ----@param map_table table A nested table where the first key is the vim mode, the second key is the key to map, and the value is the function to set the mapping to ----@param base? table A base set of options to set on every keybinding function set_mappings(map_table, base) -- iterate over the first keys for each mode base = base or {} @@ -151,27 +166,10 @@ function set_mappings(map_table, base) end end end - if package.loaded["which-key"] then which_key_register() end -- if which-key is loaded already, register -end - -for _, file in ipairs(vim.fn.readdir(vim.fn.stdpath('config')..'/lua/user', [[v:val =~ '\.lua$']])) do - local uplugin = require('user.'..file:gsub('%.lua$', '')) - if (uplugin[1] ~= nil) then - if (uplugin.mappings ~= nil) then - for mode, keymaps in pairs(uplugin.mappings) do - -- Add new mode if not already existing - if (mappings[mode] == nil) then - mappings[mode] = {} - end - - for key, value in pairs(keymaps) do - mappings[mode][key] = value; - end - end - end - - end + if package.loaded["which-key"] then M.which_key_register() end -- if which-key is loaded already, register end set_mappings(mappings); +return M + diff --git a/options.lua b/lua/options.lua similarity index 100% rename from options.lua rename to lua/options.lua diff --git a/lua/user/ide_lsp_mason.lua b/lua/user/ide_lsp_mason.lua index bb9377d..834c018 100644 --- a/lua/user/ide_lsp_mason.lua +++ b/lua/user/ide_lsp_mason.lua @@ -123,5 +123,9 @@ return { ensure_installed = { "codelldb" }, }, }, - + mappings = { + n = { + ["l"] = { desc = " LSP" }, + } + } } diff --git a/lua/user/util_which-key.lua b/lua/user/util_which-key.lua index e33f8d0..f98a2e7 100644 --- a/lua/user/util_which-key.lua +++ b/lua/user/util_which-key.lua @@ -12,5 +12,9 @@ return { -- your configuration comes here -- or leave it empty to use the default settings -- refer to the configuration section below - } + }, + setup = function(_, opts) + require("which-key").setup(opts) + require("keymaps").which_key_register() + end }