-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
83 lines (76 loc) · 3.39 KB
/
Copy pathinit.lua
File metadata and controls
83 lines (76 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- =============================================================================
-- Entry point for Neovim configuration (~/.config/nvim/init.lua)
-- =============================================================================
--
-- This is the first file Neovim loads. It bootstraps lazy.nvim (the plugin
-- manager), then loads all config modules in a specific order.
--
-- ARCHITECTURE OVERVIEW
-- ---------------------
-- init.lua Bootstraps lazy.nvim, loads config modules in order
-- lua/config/options.lua Core editor settings (vim.opt / vim.g)
-- lua/config/autocmds.lua Autocommands (event-driven hooks)
-- lua/config/filetypes.lua Filetype-specific overrides
-- lua/config/lazy_setup.lua Plugin manager setup (imports lua/plugins/)
-- lua/config/keymaps.lua All keybindings
-- lua/config/cmds.lua User-defined Ex commands
-- lua/config/utils.lua Shared helpers (keymap wrapper, root detection)
-- lua/config/lsp_setup.lua LSP auto-discovery + diagnostic UI
-- lua/plugins/ Individual plugin specs (one file per plugin)
-- lsp/ Per-language LSP server configs
--
-- LOAD ORDER
-- ----------
-- Options must load first (other modules may read vim settings). Plugins are
-- set up before keymaps because many keybindings call plugin functions. LSP is
-- last so all LSP-related plugins (mason, cmp, conform) are initialized.
--
-- KEY CONCEPTS FOR BEGINNERS
-- --------------------------
-- - safe_require: wraps pcall(require) so a broken module doesn't crash startup
-- - lazy.nvim: plugin manager that supports lazy-loading (plugins load on
-- events/commands/keys rather than at startup)
-- - vim.fn.stdpath("data") → ~/.local/share/nvim
-- - vim.fn.stdpath("config") → ~/.config/nvim
local function bootstrap_lazy()
local lazypath = vim.env.LAZY or vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
-- Only clone if lazy.nvim doesn't exist yet (fast on subsequent startups)
if not vim.loop.fs_stat(lazypath) then
local result = vim.fn.system({
"git",
"clone",
"--filter=blob:none", -- shallow clone for speed
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({ { "Error cloning lazy.nvim:\n" .. result, "ErrorMsg" } }, true, {})
vim.cmd.quit()
end
end
-- Add lazy.nvim to Neovim's runtime path so `require("lazy")` works
vim.opt.rtp:prepend(lazypath)
end
-- pcall(require) — catches errors so one broken module doesn't crash startup.
-- The error is still shown as a notification so you know something is wrong.
local function safe_require(module)
local ok, result = pcall(require, module)
if not ok then
vim.notify(string.format("Failed to load '%s':\n%s", module, tostring(result)), vim.log.levels.ERROR)
end
return result
end
-- 1. Plugin manager comes first
bootstrap_lazy()
-- 2. Core settings (vim options other modules may depend on)
safe_require("config.options")
-- 3. Autocommands & filetype overrides
safe_require("config.autocmds")
safe_require("config.filetypes")
-- 4. Plugins, then user commands and keymaps (keymaps call plugin functions)
safe_require("config.lazy_setup")
safe_require("config.cmds")
safe_require("config.keymaps")
-- 5. LSP last — all LSP plugins (mason, cmp, conform) must be initialized first
safe_require("config.lsp_setup")