From 37c3c6da98c9b0bfb041011cd7e002ed2628e6fe Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Wed, 6 Mar 2024 16:02:31 +0100 Subject: [PATCH] plugin mappings --- init.lua | 51 +++++++++------------------------------------- lua/core/utils.lua | 38 ++++++++++++++++++++++++++++++++++ lua/mappings.lua | 13 ++++++++++++ lua/plugins.lua | 14 +++++++++++++ 4 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 lua/core/utils.lua diff --git a/init.lua b/init.lua index fb369e4..24373cc 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/lua/core/utils.lua b/lua/core/utils.lua new file mode 100644 index 0000000..7b74938 --- /dev/null +++ b/lua/core/utils.lua @@ -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 diff --git a/lua/mappings.lua b/lua/mappings.lua index 8dc931f..cdba6a2 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -399,4 +399,17 @@ M.ui = { }, } +M.trailspace = { + plugin = true, + n = { + -- remove trailing whitespace + ["fw"] = { + function() + require("mini.trailspace").trim() + end, + "remove whitespace", + }, + }, +} + return M diff --git a/lua/plugins.lua b/lua/plugins.lua index c99e8e9..c5141cf 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -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({ -- tm is automatically set for toggle -- see t menu }, + "nvim-tree/nvim-web-devicons", + { + "nvim-tree/nvim-tree.lua", + lazy = false, + config = function() + require("nvim-tree").setup() + end, + }, })