migrate to lazy.nvim

This commit is contained in:
siduck 2023-01-07 13:41:43 +05:30
parent 5db2f0978d
commit 1b8eff7516
11 changed files with 176 additions and 244 deletions

View file

@ -1,20 +1,33 @@
local M = {}
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" })
M.lazy = function(install_path)
print "Bootstrapping lazy.nvim .."
M.packer = function(install_path)
print "Cloning packer .."
vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
vim.fn.system {
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
install_path,
}
vim.fn.mkdir(vim.g.base46_cache, "p")
vim.opt.rtp:prepend(install_path)
-- install plugins + compile their configs
vim.cmd "packadd packer.nvim"
require "plugins"
vim.cmd "PackerSync"
vim.fn.mkdir(vim.g.base46_cache, "p")
vim.cmd "CompileNvTheme"
require("lazy").load { plugins = "nvim-treesitter" }
-- install binaries from mason.nvim & tsparsers on LazySync
vim.schedule(function()
vim.cmd "bw | silent! MasonInstallAll" -- close lazy window
end, 0)
end
M.chadrc_template = function()
M.gen_chadrc_template = function()
if not vim.api.nvim_get_runtime_file("lua/custom/chadrc.lua", false)[1] then
local input = vim.fn.input "Do you want to install chadrc template? (y/n) : "
vim.cmd "redraw|echo ''"
@ -34,18 +47,4 @@ M.chadrc_template = function()
end
end
-- install binaries from mason.nvim & tsparsers on PackerComplete
vim.api.nvim_create_autocmd("User", {
pattern = "PackerComplete",
callback = function()
require("base46").load_all_highlights()
vim.cmd "bw | silent! MasonInstallAll" -- close packer window
require("packer").loader "nvim-treesitter"
local statusline_theme = require("core.utils").load_config().ui.statusline.theme
vim.opt.statusline = "%!v:lua.require('nvchad_ui.statusline." .. statusline_theme .. "').run()"
end,
})
return M

View file

@ -38,17 +38,3 @@ autocmd("FileType", {
vim.opt_local.buflisted = false
end,
})
-- wrap the PackerSync command to warn people before using it in NvChadSnapshots
autocmd("VimEnter", {
callback = function()
vim.api.nvim_create_user_command("PackerSync", function(opts)
require "plugins"
require("core.utils").packer_sync(opts.fargs)
end, {
bang = true,
nargs = "*",
complete = require("packer").plugin_complete,
})
end,
})

View file

@ -11,6 +11,12 @@ M.general = {
-- go to beginning and end
["<C-b>"] = { "<ESC>^i", "beginning of line" },
["<C-e>"] = { "<End>", "end of line" },
-- navigate within insert mode
["<C-h>"] = { "<Left>", "move left" },
["<C-l>"] = { "<Right>", "move right" },
["<C-j>"] = { "<Down>", "move down" },
["<C-k>"] = { "<Up>", "move up" },
},
n = {

View file

@ -49,40 +49,6 @@ opt.whichwrap:append "<>[]hl"
g.mapleader = " "
-- disable some builtin vim plugins
local default_plugins = {
"2html_plugin",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"matchit",
"tar",
"tarPlugin",
"rrhelper",
"spellfile_plugin",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
}
for _, plugin in pairs(default_plugins) do
g["loaded_" .. plugin] = 1
end
local default_providers = {
"node",
"perl",

View file

@ -116,49 +116,12 @@ M.load_override = function(options_table, name)
return merge_tb("force", options_table, plugin_options)
end
M.packer_sync = function(...)
local git_exists, git = pcall(require, "nvchad.utils.git")
local defaults_exists, defaults = pcall(require, "nvchad.utils.config")
local packer_exists, packer = pcall(require, "packer")
if git_exists and defaults_exists then
local current_branch_name = git.get_current_branch_name()
-- warn the user if we are on a snapshot branch
if current_branch_name:match(defaults.snaps.base_snap_branch_name .. "(.+)" .. "$") then
vim.api.nvim_echo({
{ "WARNING: You are trying to use ", "WarningMsg" },
{ "PackerSync" },
{
" on a NvChadSnapshot. This will cause issues if NvChad dependencies contain "
.. "any breaking changes! Plugin updates will not be included in this "
.. "snapshot, so they will be lost after switching between snapshots! Would "
.. "you still like to continue? [y/N]\n",
"WarningMsg",
},
}, false, {})
local ans = vim.trim(string.lower(vim.fn.input "-> "))
if ans ~= "y" then
return
end
end
end
if packer_exists then
packer.sync(...)
else
error "Packer could not be loaded!"
end
end
M.lazy_load = function(plugin)
vim.api.nvim_create_autocmd({ "BufRead", "BufWinEnter", "BufNewFile" }, {
group = vim.api.nvim_create_augroup("BeLazyOnFileOpen" .. plugin, {}),
callback = function()
local file = vim.fn.expand "%"
local condition = file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
local condition = file ~= "NvimTree_1" and file ~= "[lazy]" and file ~= ""
if condition then
vim.api.nvim_del_augroup_by_name("BeLazyOnFileOpen" .. plugin)
@ -166,14 +129,15 @@ M.lazy_load = function(plugin)
-- dont defer for treesitter as it will show slow highlighting
-- This deferring only happens only when we do "nvim filename"
if plugin ~= "nvim-treesitter" then
vim.defer_fn(function()
require("packer").loader(plugin)
vim.schedule(function()
require("lazy").load { plugins = plugin }
if plugin == "nvim-lspconfig" then
vim.cmd "silent! do FileType"
end
end, 0)
else
require("packer").loader(plugin)
require("lazy").load { plugins = plugin }
end
end
end,