refactor: automatically load keymaps, autocmds and options

This commit is contained in:
Folke Lemaitre
2023-01-03 23:51:57 +01:00
parent d224aea4a4
commit a15f44eb89
6 changed files with 40 additions and 16 deletions

View File

@ -1,4 +1,4 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "
require("lazyvim").setup()
require("lazyvim.config.lazy")

View File

@ -1,3 +1,5 @@
-- This file is automatically loaded by plugins.config
-- Check if we need to reload the file when it changed
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, { command = "checktime" })

View File

@ -1,3 +1,5 @@
-- This file is automatically loaded by plugins.config
-- Move to window using the <meta> movement keys
vim.keymap.set("n", "<A-left>", "<C-w>h")
vim.keymap.set("n", "<A-down>", "<C-w>j")

View File

@ -1,3 +1,5 @@
-- This file is automatically loaded by plugins.config
vim.opt.autowrite = true -- enable auto write
vim.opt.clipboard = "unnamedplus" -- sync with system clipboard
vim.opt.cmdheight = 1

View File

@ -1,15 +0,0 @@
local M = {}
---@param opts? LazyVimSettings
function M.setup(opts)
if not package.loaded.lazy then
require("lazyvim.config.lazy")
end
local settings = require("lazyvim.config.settings")
package.loaded["lazyvim.config.settings"] = vim.tbl_deep_extend("force", settings, opts or {})
require("lazyvim.config.options")
require("lazyvim.config.autocmds")
require("lazyvim.config.keymaps")
end
return M

View File

@ -0,0 +1,33 @@
local function load(name)
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
Util.try(function()
require(mod)
end, {
msg = "Failed loading " .. mod,
on_error = function(msg)
local modpath = require("lazy.core.cache").find(mod)
if modpath then
Util.error(msg)
end
end,
})
end
end
-- load options here, before lazy init while sourcing plugin modules
-- this is needed to make sure options will be correctly applied
-- after installing missing plugins
load("options")
-- autocmds and keymaps can wait to load
vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
callback = function()
load("autocmds")
load("keymaps")
end,
})
return {}