plugin mappings

This commit is contained in:
Christoph J. Scherr 2024-03-06 16:02:31 +01:00
parent 510ab5ec4e
commit 37c3c6da98
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
4 changed files with 75 additions and 41 deletions

View File

@ -3,6 +3,10 @@ local g = vim.g
g.maplocalleader = ";"
g.python3_host_prog = "/usr/bin/python3"
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
opt.mouse = "a" -- mouse does annoying things for me if it's not 'a'
opt.signcolumn = "yes"
opt.clipboard = "" -- don't just use the system clipboard
@ -143,46 +147,11 @@ if vim.g.vscode then
end
-- mappings
local load_mappings = function(section, mapping_opt)
vim.schedule(function()
local function set_section_map(section_values)
if section_values.plugin then
return
end
section_values.plugin = nil
local merge_tb = vim.tbl_deep_extend
for mode, mode_values in pairs(section_values) do
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
mapping_info.opts, opts.mode = nil, nil
opts.desc = mapping_info[2]
vim.keymap.set(mode, keybind, mapping_info[1], opts)
end
end
end
local mappings = require("mappings")
if type(section) == "string" then
mappings[section]["plugin"] = nil
mappings = { mappings[section] }
end
for _, sect in pairs(mappings) do
set_section_map(sect)
end
end)
end
load_mappings("clipboard")
load_mappings("movements")
load_mappings("edit")
load_mappings("tabs")
load_mappings("ui")
local utils = require("core.utils")
utils.load_mappings("clipboard")
utils.load_mappings("movements")
utils.load_mappings("edit")
utils.load_mappings("tabs")
utils.load_mappings("ui")
require("plugins")

38
lua/core/utils.lua Normal file
View File

@ -0,0 +1,38 @@
local M = {}
M.load_mappings = function(section, mapping_opt)
vim.schedule(function()
local function set_section_map(section_values)
if section_values.plugin then
return
end
section_values.plugin = nil
local merge_tb = vim.tbl_deep_extend
for mode, mode_values in pairs(section_values) do
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
mapping_info.opts, opts.mode = nil, nil
opts.desc = mapping_info[2]
vim.keymap.set(mode, keybind, mapping_info[1], opts)
end
end
end
local mappings = require("mappings")
if type(section) == "string" then
mappings[section]["plugin"] = nil
mappings = { mappings[section] }
end
for _, sect in pairs(mappings) do
set_section_map(sect)
end
end)
end
return M

View File

@ -399,4 +399,17 @@ M.ui = {
},
}
M.trailspace = {
plugin = true,
n = {
-- remove trailing whitespace
["<leader>fw"] = {
function()
require("mini.trailspace").trim()
end,
"remove whitespace",
},
},
}
return M

View File

@ -25,6 +25,9 @@ require("lazy").setup({
{
"ggandor/leap.nvim",
lazy = false,
config = function()
require("core.utils").load_mappings "leap"
end,
},
{
"ggandor/flit.nvim",
@ -46,6 +49,9 @@ require("lazy").setup({
lazy = false,
event = { "BufReadPost", "BufNewFile" },
opts = {},
config = function()
require("core.utils").load_mappings "trailspace"
end,
},
{
-- exit insert mode with 'jk'
@ -62,4 +68,12 @@ require("lazy").setup({
-- <Leader>tm is automatically set for toggle
-- see <Leader>t menu
},
"nvim-tree/nvim-web-devicons",
{
"nvim-tree/nvim-tree.lua",
lazy = false,
config = function()
require("nvim-tree").setup()
end,
},
})