mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-23 09:18:51 +02:00
refactor(keymaps): move safe keymap.set wrapper to util and add message not to use it in a personal config
This commit is contained in:
parent
0cdc23a51d
commit
25f3587f3f
2 changed files with 26 additions and 19 deletions
|
@ -320,4 +320,27 @@ function M.on_rename(from, to)
|
|||
end
|
||||
end
|
||||
|
||||
-- Wrapper around vim.keymap.set that will
|
||||
-- not create a keymap if a lazy key handler exists.
|
||||
-- It will also set `silent` to true by default.
|
||||
function M.safe_keymap_set(mode, lhs, rhs, opts)
|
||||
local keys = require("lazy.core.handler").handlers.keys
|
||||
---@cast keys LazyKeysHandler
|
||||
local modes = type(mode) == "string" and { mode } or mode
|
||||
|
||||
modes = vim.tbl_filter(function(mode)
|
||||
return not (keys.have and keys:have(lhs, mode))
|
||||
end, modes)
|
||||
|
||||
-- do not create the keymap if a lazy keys handler exists
|
||||
if #modes > 0 then
|
||||
opts = opts or {}
|
||||
opts.silent = opts.silent ~= false
|
||||
if opts.remap and not vim.g.vscode then
|
||||
opts.remap = nil
|
||||
end
|
||||
vim.keymap.set(modes, lhs, rhs, opts)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue