diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 6684b1e..7525255 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -4,31 +4,18 @@ local api = vim.api api.nvim_exec2("runtime abbrev.vim", {}) -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) +for _, source in ipairs({ + "core.settings", + "core.lazy", + "core.autocmds", + "core.mappings", + "core.look", +}) do + local status_ok, fault = pcall(require, source) + if not status_ok then + vim.api.nvim_err_writeln("Failed to load " .. source .. "\n\n" .. fault) + end end -vim.opt.rtp:prepend(lazypath) - --- set our leader key to space since with hjkl, space is largely useless --- needs to be set before lazy.nvim is loaded -vim.g.mapleader = " " - -require("settings") -require("autocmds") -require("lazy").setup("plugins", { - defaults = { version = "*" }, - performance = { rtp = { disabled_plugins = { "netrw", "netrwPlugin" } } }, -}) -require("look") -require("maps") -- to include e.g. the spell dictionaries for vim vim.opt.rtp:append(vim.fn.stdpath("data") .. "/site") diff --git a/nvim/.config/nvim/lua/autocmds.lua b/nvim/.config/nvim/lua/core/autocmds.lua similarity index 100% rename from nvim/.config/nvim/lua/autocmds.lua rename to nvim/.config/nvim/lua/core/autocmds.lua diff --git a/nvim/.config/nvim/lua/core/lazy.lua b/nvim/.config/nvim/lua/core/lazy.lua new file mode 100644 index 0000000..840f4e2 --- /dev/null +++ b/nvim/.config/nvim/lua/core/lazy.lua @@ -0,0 +1,38 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +-- inspired from astronvim lazy bootstrapping +if not vim.loop.fs_stat(lazypath) then + local output = vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) + if vim.api.nvim_get_vvar("shell_error") ~= 0 then + vim.api.nvim_err_writeln("Error cloning lazy.nvim repository...\n\n" .. output) + end + local oldcmdheight = vim.opt.cmdheight:get() + vim.opt.cmdheight = 1 + vim.notify("Please wait while plugins are installed...") + vim.api.nvim_create_autocmd("User", { + desc = "Load Mason and Treesitter after Lazy installs plugins", + once = true, + pattern = "LazyInstall", + callback = function() + vim.cmd.bw() + vim.opt.cmdheight = oldcmdheight + vim.tbl_map(function(module) + pcall(require, module) + end, { "nvim-treesitter", "mason" }) + vim.notify("Mason is installing packages if configured, check status with :Mason") + end, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + spec = { { import = "plugins" } }, + defaults = { lazy = true, version = "*" }, + performance = { rtp = { disabled_plugins = { "netrw", "netrwPlugin" } } }, +}) diff --git a/nvim/.config/nvim/lua/look.lua b/nvim/.config/nvim/lua/core/look.lua similarity index 100% rename from nvim/.config/nvim/lua/look.lua rename to nvim/.config/nvim/lua/core/look.lua diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/core/mappings.lua similarity index 100% rename from nvim/.config/nvim/lua/maps.lua rename to nvim/.config/nvim/lua/core/mappings.lua diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/core/plugins.lua similarity index 100% rename from nvim/.config/nvim/lua/plugins.lua rename to nvim/.config/nvim/lua/core/plugins.lua diff --git a/nvim/.config/nvim/lua/settings.lua b/nvim/.config/nvim/lua/core/settings.lua similarity index 79% rename from nvim/.config/nvim/lua/settings.lua rename to nvim/.config/nvim/lua/core/settings.lua index 34108de..a225dbd 100644 --- a/nvim/.config/nvim/lua/settings.lua +++ b/nvim/.config/nvim/lua/core/settings.lua @@ -4,8 +4,13 @@ local disable_builtins = function(builtins) vim.g["loaded_" .. plugin] = 1 end end +disable_builtins(default_builtins_disabled) -local o = { +if vim.fn.has("nvim-0.9") == 1 then + vim.opt.diffopt:append("linematch:60") +end + +local options = { termguicolors = true, -- sets tabs to be 2 characters, expanded into spaces, but still removable with -- one press of backspace. @@ -47,6 +52,7 @@ local o = { -- set to use treesitter in treesitter config foldlevel = 2, conceallevel = 2, + foldcolumn = vim.fn.has("nvim-0.9") == 1 and "auto:1" or nil, -- enable mouse, doesn't bug me and might come in useful at some point mouse = "a", -- pump all clippings into the system clipboard @@ -60,11 +66,25 @@ local o = { splitbelow = true, -- remove command line if no command is currently present cmdheight = 0, + -- try to cleverly manage indents by preserving them from line to line + breakindent = true, + copyindent = true, + preserveindent = true, + smartindent = true, } -for k, v in pairs(o) do - vim.opt[k] = v +for o, v in pairs(options) do + vim.opt[o] = v end +vim.opt.shortmess:append({ s = true, I = true }) +vim.opt.backspace:append({ "nostop" }) -vim.api.nvim_set_var("tex_flavor", "latex") -disable_builtins(default_builtins_disabled) +local globals = { + mapleader = " ", + maplocalleader = ",", + tex_flavor = "latex", +} + +for o, v in pairs(globals) do + vim.g[o] = v +end