WIP, cant get which key to register at startup setup function, calling in open nvwim works. Also + purple text is weird
This commit is contained in:
parent
5fcc77255c
commit
713d128018
5 changed files with 33 additions and 27 deletions
|
@ -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
|
local which_key_queue = nil
|
||||||
--- Register queued which-key mappings
|
function M.which_key_register()
|
||||||
function which_key_register()
|
|
||||||
if which_key_queue then
|
if which_key_queue then
|
||||||
local wk_avail, wk = pcall(require, "which-key")
|
local wk_avail, wk = pcall(require, "which-key")
|
||||||
if wk_avail then
|
if wk_avail then
|
||||||
|
@ -123,9 +141,6 @@ function which_key_register()
|
||||||
end
|
end
|
||||||
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)
|
function set_mappings(map_table, base)
|
||||||
-- iterate over the first keys for each mode
|
-- iterate over the first keys for each mode
|
||||||
base = base or {}
|
base = base or {}
|
||||||
|
@ -151,27 +166,10 @@ function set_mappings(map_table, base)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if package.loaded["which-key"] then which_key_register() end -- if which-key is loaded already, register
|
if package.loaded["which-key"] then M.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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
set_mappings(mappings);
|
set_mappings(mappings);
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
|
@ -123,5 +123,9 @@ return {
|
||||||
ensure_installed = { "codelldb" },
|
ensure_installed = { "codelldb" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mappings = {
|
||||||
|
n = {
|
||||||
|
["<leader>l"] = { desc = " LSP" },
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,9 @@ return {
|
||||||
-- your configuration comes here
|
-- your configuration comes here
|
||||||
-- or leave it empty to use the default settings
|
-- or leave it empty to use the default settings
|
||||||
-- refer to the configuration section below
|
-- refer to the configuration section below
|
||||||
}
|
},
|
||||||
|
setup = function(_, opts)
|
||||||
|
require("which-key").setup(opts)
|
||||||
|
require("keymaps").which_key_register()
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue