mappings: Only set mappings if the plugin is enabled
format files fix some lsp warnings
This commit is contained in:
parent
d7b97dfe63
commit
f4655e13ec
5 changed files with 65 additions and 45 deletions
|
@ -8,7 +8,6 @@ local M = {}
|
|||
|
||||
M.general = {
|
||||
i = {
|
||||
|
||||
-- go to beginning and end
|
||||
["<C-b>"] = { "<ESC>^i", "論 beginning of line" },
|
||||
["<C-e>"] = { "<End>", "壟 end of line" },
|
||||
|
@ -21,7 +20,6 @@ M.general = {
|
|||
},
|
||||
|
||||
n = {
|
||||
|
||||
["<ESC>"] = { "<cmd> noh <CR>", " no highlight" },
|
||||
|
||||
-- switch between windows
|
||||
|
@ -47,7 +45,6 @@ M.general = {
|
|||
function()
|
||||
require("base46").toggle_theme()
|
||||
end,
|
||||
|
||||
" toggle theme",
|
||||
},
|
||||
|
||||
|
@ -59,11 +56,20 @@ M.general = {
|
|||
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
|
||||
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
|
||||
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
|
||||
|
||||
-- new buffer
|
||||
["<S-b>"] = { "<cmd> enew <CR>", "烙 new buffer" },
|
||||
|
||||
-- close buffer + hide terminal buffer
|
||||
["<leader>x"] = {
|
||||
function()
|
||||
require("core.utils").close_buffer()
|
||||
end,
|
||||
" close buffer",
|
||||
},
|
||||
},
|
||||
|
||||
t = {
|
||||
["<C-x>"] = { termcodes "<C-\\><C-N>", " escape terminal mode" },
|
||||
},
|
||||
t = { ["<C-x>"] = { termcodes "<C-\\><C-N>", " escape terminal mode" } },
|
||||
|
||||
v = {
|
||||
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
|
||||
|
@ -77,11 +83,8 @@ M.general = {
|
|||
}
|
||||
|
||||
M.tabufline = {
|
||||
|
||||
plugin = true,
|
||||
n = {
|
||||
-- new buffer
|
||||
["<S-b>"] = { "<cmd> enew <CR>", "烙 new buffer" },
|
||||
|
||||
-- cycle through buffers
|
||||
["<TAB>"] = {
|
||||
function()
|
||||
|
@ -97,28 +100,19 @@ M.tabufline = {
|
|||
" goto prev buffer",
|
||||
},
|
||||
|
||||
-- close buffer + hide terminal buffer
|
||||
["<leader>x"] = {
|
||||
function()
|
||||
require("core.utils").close_buffer()
|
||||
end,
|
||||
" close buffer",
|
||||
},
|
||||
|
||||
-- pick buffers via numbers
|
||||
["<Bslash>"] = { "<cmd> TbufPick <CR>", " Pick buffer" },
|
||||
},
|
||||
}
|
||||
|
||||
M.comment = {
|
||||
|
||||
plugin = true,
|
||||
-- toggle comment in both modes
|
||||
n = {
|
||||
["<leader>/"] = {
|
||||
function()
|
||||
require("Comment.api").toggle_current_linewise()
|
||||
end,
|
||||
|
||||
"蘒 toggle comment",
|
||||
},
|
||||
},
|
||||
|
@ -132,6 +126,7 @@ M.comment = {
|
|||
}
|
||||
|
||||
M.lspconfig = {
|
||||
plugin = true,
|
||||
-- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions
|
||||
|
||||
n = {
|
||||
|
@ -193,7 +188,7 @@ M.lspconfig = {
|
|||
|
||||
["gr"] = {
|
||||
function()
|
||||
vim.lsp.buf.references()
|
||||
vim.lsp.buf.references {}
|
||||
end,
|
||||
" lsp references",
|
||||
},
|
||||
|
@ -228,7 +223,7 @@ M.lspconfig = {
|
|||
|
||||
["<leader>fm"] = {
|
||||
function()
|
||||
vim.lsp.buf.formatting()
|
||||
vim.lsp.buf.formatting {}
|
||||
end,
|
||||
" lsp formatting",
|
||||
},
|
||||
|
@ -257,7 +252,7 @@ M.lspconfig = {
|
|||
}
|
||||
|
||||
M.nvimtree = {
|
||||
|
||||
plugin = true,
|
||||
n = {
|
||||
-- toggle
|
||||
["<C-n>"] = { "<cmd> NvimTreeToggle <CR>", " toggle nvimtree" },
|
||||
|
@ -268,6 +263,7 @@ M.nvimtree = {
|
|||
}
|
||||
|
||||
M.telescope = {
|
||||
plugin = true,
|
||||
n = {
|
||||
-- find
|
||||
["<leader>ff"] = { "<cmd> Telescope find_files <CR>", " find files" },
|
||||
|
@ -291,6 +287,7 @@ M.telescope = {
|
|||
}
|
||||
|
||||
M.nvterm = {
|
||||
plugin = true,
|
||||
t = {
|
||||
-- toggle in terminal mode
|
||||
["<A-i>"] = {
|
||||
|
@ -357,6 +354,7 @@ M.nvterm = {
|
|||
}
|
||||
|
||||
M.whichkey = {
|
||||
plugin = true,
|
||||
n = {
|
||||
["<leader>wK"] = {
|
||||
function()
|
||||
|
@ -375,6 +373,7 @@ M.whichkey = {
|
|||
}
|
||||
|
||||
M.blankline = {
|
||||
plugin = true,
|
||||
n = {
|
||||
["<leader>bc"] = {
|
||||
function()
|
||||
|
|
|
@ -64,7 +64,7 @@ M.remove_default_keys = function(disabled_mappings, default_mappings)
|
|||
return default_mappings
|
||||
end
|
||||
|
||||
M.load_mappings = function(mappings, mapping_opt)
|
||||
M.load_mappings = function(section, mapping_opt)
|
||||
-- set mapping function with/without whichkey
|
||||
local set_maps
|
||||
local whichkey_exists, wk = pcall(require, "which-key")
|
||||
|
@ -81,11 +81,9 @@ M.load_mappings = function(mappings, mapping_opt)
|
|||
end
|
||||
end
|
||||
|
||||
mappings = mappings or vim.deepcopy(M.load_config().mappings)
|
||||
mappings.lspconfig = nil
|
||||
|
||||
for _, section in pairs(mappings) do
|
||||
for mode, mode_values in pairs(section) do
|
||||
local set_section_map = function(section_values)
|
||||
section_values.plugin = nil
|
||||
for mode, mode_values in pairs(section_values) do
|
||||
for keybind, mapping_info in pairs(mode_values) do
|
||||
-- merge default + user opts
|
||||
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
|
||||
|
@ -99,6 +97,18 @@ M.load_mappings = function(mappings, mapping_opt)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
local mappings = require("core.utils").load_config().mappings
|
||||
|
||||
if type(section) == "string" then
|
||||
set_section_map(mappings[section])
|
||||
else
|
||||
for _, sect in pairs(mappings) do
|
||||
if sect.plugin == nil or sect.plugin == false then
|
||||
set_section_map(sect)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- remove plugins defined in chadrc
|
||||
|
@ -119,7 +129,7 @@ M.merge_plugins = function(default_plugins)
|
|||
local user_plugins = M.load_config().plugins.user
|
||||
|
||||
-- merge default + user plugin table
|
||||
default_plugins = merge_tb("force", default_plugins, user_plugins)
|
||||
default_plugins = merge_tb("force", default_plugins, user_plugins) or {}
|
||||
|
||||
local final_table = {}
|
||||
|
||||
|
@ -133,8 +143,8 @@ end
|
|||
|
||||
M.load_override = function(default_table, plugin_name)
|
||||
local user_table = M.load_config().plugins.override[plugin_name] or {}
|
||||
user_table = type(user_table) == "table" and user_table or user_table()
|
||||
return merge_tb("force", default_table, user_table)
|
||||
user_table = type(user_table) == "function" and user_table() or user_table
|
||||
return merge_tb("force", default_table, user_table or {}) or {}
|
||||
end
|
||||
|
||||
M.packer_sync = function(...)
|
||||
|
|
|
@ -23,8 +23,7 @@ M.on_attach = function(client, bufnr)
|
|||
client.resolved_capabilities.document_range_formatting = false
|
||||
end
|
||||
|
||||
local lsp_mappings = utils.load_config().mappings.lspconfig
|
||||
utils.load_mappings({ lsp_mappings }, { buffer = bufnr })
|
||||
utils.load_mappings("lspconfig", { buffer = bufnr })
|
||||
|
||||
if client.server_capabilities.signatureHelpProvider then
|
||||
require("nvchad_ui.signature").setup(client)
|
||||
|
|
|
@ -38,14 +38,4 @@ local options = {
|
|||
|
||||
options = require("core.utils").load_override(options, "folke/which-key.nvim")
|
||||
|
||||
local utils = require "core.utils"
|
||||
|
||||
local mappings = utils.load_config().mappings
|
||||
local mapping_groups = { groups = vim.deepcopy(mappings.groups) }
|
||||
|
||||
mappings.disabled = nil
|
||||
mappings.groups = nil
|
||||
|
||||
utils.load_mappings(mapping_groups)
|
||||
|
||||
wk.setup(options)
|
||||
|
|
|
@ -21,6 +21,12 @@ local plugins = {
|
|||
config = function()
|
||||
require("plugins.configs.others").nvchad_ui()
|
||||
end,
|
||||
setup = function()
|
||||
local load_override = require("core.utils").load_override
|
||||
if load_override({}, "NvChad/ui")["tabufline"]["enabled"] then
|
||||
require("core.utils").load_mappings "tabufline"
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
["NvChad/nvterm"] = {
|
||||
|
@ -28,10 +34,13 @@ local plugins = {
|
|||
config = function()
|
||||
require "plugins.configs.nvterm"
|
||||
end,
|
||||
setup = function()
|
||||
require("core.utils").load_mappings "nvterm"
|
||||
end,
|
||||
},
|
||||
|
||||
["kyazdani42/nvim-web-devicons"] = {
|
||||
after = 'ui',
|
||||
after = "ui",
|
||||
module = "nvim-web-devicons",
|
||||
config = function()
|
||||
require("plugins.configs.others").devicons()
|
||||
|
@ -42,6 +51,7 @@ local plugins = {
|
|||
opt = true,
|
||||
setup = function()
|
||||
require("core.lazy_load").on_file_open "indent-blankline.nvim"
|
||||
require("core.utils").load_mappings "blankline"
|
||||
end,
|
||||
config = function()
|
||||
require("plugins.configs.others").blankline()
|
||||
|
@ -164,6 +174,9 @@ local plugins = {
|
|||
config = function()
|
||||
require("plugins.configs.others").comment()
|
||||
end,
|
||||
setup = function()
|
||||
require("core.utils").load_mappings "comment"
|
||||
end,
|
||||
},
|
||||
|
||||
-- file managing , picker etc
|
||||
|
@ -173,6 +186,9 @@ local plugins = {
|
|||
config = function()
|
||||
require "plugins.configs.nvimtree"
|
||||
end,
|
||||
setup = function()
|
||||
require("core.utils").load_mappings "nvimtree"
|
||||
end,
|
||||
},
|
||||
|
||||
["nvim-telescope/telescope.nvim"] = {
|
||||
|
@ -180,6 +196,9 @@ local plugins = {
|
|||
config = function()
|
||||
require "plugins.configs.telescope"
|
||||
end,
|
||||
setup = function()
|
||||
require("core.utils").load_mappings "telescope"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Only load whichkey after all the gui
|
||||
|
@ -188,6 +207,9 @@ local plugins = {
|
|||
config = function()
|
||||
require "plugins.configs.whichkey"
|
||||
end,
|
||||
setup = function()
|
||||
require("core.utils").load_mappings "whichkey"
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue