diff --git a/init.lua b/init.lua index 52db41c..a781263 100644 --- a/init.lua +++ b/init.lua @@ -1,49 +1,24 @@ -vim.defer_fn(function() - pcall(require, "impatient") -end, 0) +require "core.options" +require("core.utils").load_mappings() +-- require("colors").core_setup() --- setup packer + plugins -local fn = vim.fn -local install_path = fn.stdpath "data" .. "/site/pack/packer/opt/packer.nvim" - -if fn.empty(fn.glob(install_path)) > 0 then - vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" }) - print "Cloning packer .." - fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path } - - -- install plugins + compile their configs - vim.cmd "packadd packer.nvim" - require "plugins" - vim.cmd "PackerSync" - - -- install binaries from mason.nvim & tsparsers - vim.api.nvim_create_autocmd("User", { - pattern = "PackerComplete", - callback = function() - vim.cmd "bw | silent! MasonInstallAll" -- close packer window - require("packer").loader "nvim-treesitter" - end, - }) +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, + }) end - -local modules = { - "core.options", - "core.packer", -} +vim.opt.rtp:prepend(lazypath) +require "plugins" -- add binaries installed by mason.nvim to path vim.env.PATH = vim.env.PATH .. ":" .. vim.fn.stdpath "data" .. "/mason/bin" -for _, module in ipairs(modules) do - local ok, err = pcall(require, module) - if not ok then - error("Error loading " .. module .. "\n\n" .. err) - end -end - -require("core.utils").load_mappings() --- require("colors").core_setup() - require('rose-pine').setup({ disable_background = true }) diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..c10e1a0 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,28 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "eab2c83a0207369900e92783f56990808082eac2" }, + "LuaSnip": { "branch": "master", "commit": "af60ac12fa1349dbad479fc1e95d5aea977c0c37" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "59224771f91b86d1de12570b4070fe4ad7cd1eeb" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f3491638d123cfd2c8048aefaf66d246ff250ca6" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, + "crates.nvim": { "branch": "main", "commit": "707ed7d6f8927a5ec0c241aa793f694f1b05f731" }, + "friendly-snippets": { "branch": "main", "commit": "046e4d3491baf664e0eef5231d28beb49333578b" }, + "gitsigns.nvim": { "branch": "main", "commit": "addd6e174a85fc1c4007ab0b65d77e6555b417bf" }, + "indent-blankline.nvim": { "branch": "master", "commit": "c4c203c3e8a595bc333abaf168fcb10c13ed5fb7" }, + "kterm": { "branch": "main", "commit": "91bd6e3750a4c9302abe87260256cca97f71666b" }, + "lazy.nvim": { "branch": "main", "commit": "4739c2d95af17acb786ed33445f59b7b13671417" }, + "lualine.nvim": { "branch": "master", "commit": "0050b308552e45f7128f399886c86afefc3eb988" }, + "mason.nvim": { "branch": "main", "commit": "d825d3d1612c31caaff60901e0a6600cab8624d3" }, + "neovim": { "branch": "main", "commit": "845a6ad5443e3559dde42910c4523a5835c9233b" }, + "nvim-autopairs": { "branch": "master", "commit": "f00eb3b766c370cb34fdabc29c760338ba9e4c6c" }, + "nvim-cmp": { "branch": "main", "commit": "11a95792a5be0f5a40bab5fc5b670e5b1399a939" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "760e27df4dd966607e8fb7fd8b6b93e3c7d2e193" }, + "nvim-lspconfig": { "branch": "master", "commit": "d228bcf7cd94611929482a09e114a42c41fe81a8" }, + "nvim-treesitter": { "branch": "master", "commit": "42c3a3c51e8fef027655e7facd293aae7c6984bb" }, + "plenary.nvim": { "branch": "master", "commit": "1c7e3e6b0f4dd5a174fcea9fda8a4d7de593b826" }, + "rust-tools.nvim": { "branch": "master", "commit": "df584e84393ef255f5b8cbd709677d6a3a5bf42f" }, + "telescope.nvim": { "branch": "master", "commit": "2f32775405f6706348b71d0bb8a15a22852a61e4" }, + "vimwiki": { "branch": "dev", "commit": "fea8bee382b2051b0137fd2cacf0862823ee69b3" }, + "which-key.nvim": { "branch": "main", "commit": "e4fa445065a2bb0bbc3cca85346b67817f28e83e" } +} \ No newline at end of file diff --git a/lua/core/bootstrap.lua b/lua/core/bootstrap.lua new file mode 100644 index 0000000..97ae008 --- /dev/null +++ b/lua/core/bootstrap.lua @@ -0,0 +1,28 @@ +local M = {} + +M.lazy = function(install_path) + print "Bootstrapping lazy.nvim .." + + vim.fn.system { + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + install_path, + } + + vim.opt.rtp:prepend(install_path) + + -- install plugins + compile their configs + require "plugins" + + 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 + +return M diff --git a/lua/core/lazy_load.lua b/lua/core/lazy_load.lua deleted file mode 100644 index 9ce6ad4..0000000 --- a/lua/core/lazy_load.lua +++ /dev/null @@ -1,79 +0,0 @@ -local M = {} -local autocmd = vim.api.nvim_create_autocmd - --- require("packer").loader(tb.plugins) --- This must be used for plugins that need to be loaded just after a file --- ex : treesitter, lspconfig etc -M.lazy_load = function(tb) - autocmd(tb.events, { - group = vim.api.nvim_create_augroup(tb.augroup_name, {}), - callback = function() - if tb.condition() then - vim.api.nvim_del_augroup_by_name(tb.augroup_name) - - -- dont defer for treesitter as it will show slow highlighting - -- This deferring only happens only when we do "nvim filename" - if tb.plugin ~= "nvim-treesitter" then - vim.defer_fn(function() - require("packer").loader(tb.plugin) - if tb.plugin == "nvim-lspconfig" then - vim.cmd "silent! do FileType" - end - end, 0) - else - require("packer").loader(tb.plugin) - end - end - end, - }) -end - --- load certain plugins only when there's a file opened in the buffer --- if "nvim filename" is executed -> load the plugin after nvim gui loads --- This gives an instant preview of nvim with the file opened - -M.on_file_open = function(plugin_name) - M.lazy_load { - events = { "BufRead", "BufWinEnter", "BufNewFile" }, - augroup_name = "BeLazyOnFileOpen" .. plugin_name, - plugin = plugin_name, - condition = function() - local file = vim.fn.expand "%" - return file ~= "[packer]" and file ~= "" - end, - } -end - -M.packer_cmds = { - "PackerSnapshot", - "PackerSnapshotRollback", - "PackerSnapshotDelete", - "PackerInstall", - "PackerUpdate", - "PackerSync", - "PackerClean", - "PackerCompile", - "PackerStatus", - "PackerProfile", - "PackerLoad", -} - -M.treesitter_cmds = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" } -M.mason_cmds = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" } - -M.gitsigns = function() - autocmd({ "BufRead" }, { - group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }), - callback = function() - vim.fn.system("git -C " .. vim.fn.expand "%:p:h" .. " rev-parse") - if vim.v.shell_error == 0 then - vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad" - vim.schedule(function() - require("packer").loader "gitsigns.nvim" - end) - end - end, - }) -end - -return M diff --git a/lua/core/options.lua b/lua/core/options.lua index d7feafc..74dd8d0 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -42,29 +42,3 @@ opt.timeoutlen = 400 -- interval for writing swap file to disk, also used by gitsigns opt.updatetime = 250 - --- 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", - "vimball_plugin", - "zip", - "zipPlugin", -} - -for _, plugin in pairs(default_plugins) do - g["loaded_" .. plugin] = 1 -end diff --git a/lua/core/packer.lua b/lua/core/packer.lua deleted file mode 100644 index f8d7d11..0000000 --- a/lua/core/packer.lua +++ /dev/null @@ -1,41 +0,0 @@ -local M = {} - -M.run = function(plugins) - local present, packer = pcall(require, "packer") - - if not present then - return - end - - - local final_table = {} - for key, _ in pairs(plugins) do - plugins[key][1] = key - final_table[#final_table + 1] = plugins[key] - end - - - packer.init({ - auto_clean = true, - compile_on_sync = true, - git = { clone_timeout = 6000 }, - display = { - working_sym = "ﲊ", - error_sym = "✗ ", - done_sym = " ", - removed_sym = " ", - moved_sym = "", - open_fn = function() - return require("packer.util").float { border = "single" } - end, - } - }) - - packer.startup(function(use) - for _, v in pairs(final_table) do - use(v) - end - end) -end - -return M diff --git a/lua/core/utils.lua b/lua/core/utils.lua index d9085f3..8c9890d 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -1,6 +1,15 @@ local M = {} local merge_tb = vim.tbl_deep_extend +M.format_plugins = function(plugins) local final_table = {} + for key, _ in pairs(plugins) do + plugins[key][1] = key + final_table[#final_table + 1] = plugins[key] + end + + return final_table +end + M.close_buffer = function(bufnr) if vim.bo.buftype == "terminal" then vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide") @@ -43,4 +52,32 @@ M.load_mappings = function(section, mapping_opt) 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 ~= "[lazy]" and file ~= "" + + if condition then + vim.api.nvim_del_augroup_by_name("BeLazyOnFileOpen" .. 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.schedule(function() + require("lazy").load { plugins = plugin } + + if plugin == "nvim-lspconfig" then + vim.cmd "silent! do FileType" + end + end, 0) + else + require("lazy").load { plugins = plugin } + end + end + end, + }) +end + return M diff --git a/lua/plugins/configs/lazy_nvim.lua b/lua/plugins/configs/lazy_nvim.lua new file mode 100644 index 0000000..8ac2a20 --- /dev/null +++ b/lua/plugins/configs/lazy_nvim.lua @@ -0,0 +1,70 @@ +return { + defaults = { + lazy = true, + }, + + -- install = { + -- try to load one of these colorschemes when starting an installation during startup + -- colorscheme = { "rose-pine" }, + -- }, + + ui = { + icons = { + cmd = " ", + config = "", + event = "", + ft = " ", + init = " ", + import = " ", + keys = " ", + lazy = "鈴 ", + loaded = "", + not_loaded = "", + plugin = " ", + runtime = " ", + source = " ", + start = "", + task = "✔ ", + list = { + "●", + "➜", + "★", + "‒", + }, + }, + }, + + -- performance = { + -- rtp = { + -- disabled_plugins = { + -- "2html_plugin", + -- "tohtml", + -- "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", + -- }, + -- }, + -- }, +} diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index c28b89b..023efd3 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -20,30 +20,31 @@ M.autopairs = function() end M.luasnip = function() - local present, luasnip = pcall(require, "luasnip") + local present, luasnip = pcall(require, "luasnip") - if not present then - return - end + if not present then + return + end - local options = { - history = true, - updateevents = "TextChanged,TextChangedI", - } + local options = { + history = true, + updateevents = "TextChanged,TextChangedI", + } - luasnip.config.set_config(options) - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" } + luasnip.config.set_config(options) + require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" } + require("luasnip.loaders.from_vscode").lazy_load() - vim.api.nvim_create_autocmd("InsertLeave", { - callback = function() - if require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] - and not require("luasnip").session.jump_active - then - require("luasnip").unlink_current() - end - end, - }) + vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, + }) end M.gitsigns = function() @@ -99,7 +100,7 @@ M.blankline = function() "help", "terminal", "alpha", - "packer", + "lazy", "lspinfo", "TelescopePrompt", "TelescopeResults", @@ -136,6 +137,7 @@ M.colorizer = function() css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn mode = "background", -- Set the display mode. + tailwind = true, }, } diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index a7f84ef..4ae9491 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,42 +1,46 @@ +-- All plugins have lazy = true by default, to load a plugin on startup just lazy=false local plugins = { - ["wbthomason/packer.nvim"] = { - cmd = require("core.lazy_load").packer_cmds, - config = function() - require "plugins" - end, - }, + ['nvim-lua/plenary.nvim'] = {}, ["nvim-treesitter/nvim-treesitter"] = { - module = "nvim-treesitter", - setup = function() - require("core.lazy_load").on_file_open "nvim-treesitter" + init = function() + require("core.utils").lazy_load "nvim-treesitter" end, - cmd = require("core.lazy_load").treesitter_cmds, + cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" }, run = ":TSUpdate", config = function() require "plugins.configs.treesitter" end, }, - -- git ["lewis6991/gitsigns.nvim"] = { ft = "gitcommit", - setup = function() - require("core.lazy_load").gitsigns() + init = function() + -- load gitsigns only when a git file is opened + vim.api.nvim_create_autocmd({ "BufRead" }, { + group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }), + callback = function() + vim.fn.system("git -C " .. vim.fn.expand "%:p:h" .. " rev-parse") + if vim.v.shell_error == 0 then + vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad" + vim.schedule(function() + require("lazy").load { plugins = "gitsigns.nvim" } + end) + end + end, + }) end, config = function() require("plugins.configs.others").gitsigns() end, }, - ['nvim-lua/plenary.nvim'] = {}, - ["nvim-telescope/telescope.nvim"] = { cmd = "Telescope", config = function() require "plugins.configs.telescope" end, - setup = function() + init = function() require("core.utils").load_mappings "telescope" end, }, @@ -44,16 +48,15 @@ local plugins = { -- lsp stuff ["williamboman/mason.nvim"] = { - cmd = require("core.lazy_load").mason_cmds, + cmd = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" }, config = function() require "plugins.configs.mason" end, }, ["neovim/nvim-lspconfig"] = { - opt = true, - setup = function() - require("core.lazy_load").on_file_open "nvim-lspconfig" + init = function() + require("core.utils").lazy_load "nvim-lspconfig" end, config = function() require "plugins.configs.lspconfig" @@ -77,43 +80,40 @@ local plugins = { -- load luasnips + cmp related in insert mode only - ["rafamadriz/friendly-snippets"] = {}, - - ["hrsh7th/nvim-cmp"] = { - event = "InsertEnter", + ["hrsh7th/nvim-cmp"] = { + event = "InsertEnter", + dependencies = { + { + -- snippet plugin + "L3MON4D3/LuaSnip", + dependencies = "rafamadriz/friendly-snippets", config = function() - require "plugins.configs.cmp" + require("plugins.configs.others").luasnip() end, - }, + }, - ["L3MON4D3/LuaSnip"] = { - requires = "friendly-snippets", - after = "nvim-cmp", + -- autopairing of (){}[] etc + { + "windwp/nvim-autopairs", config = function() - require("plugins.configs.others").luasnip() + require("plugins.configs.others").autopairs() end, + }, + + -- cmp sources plugins + { + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + }, }, - ["saadparwaiz1/cmp_luasnip"] = { - after = "LuaSnip", - }, - - ["hrsh7th/cmp-nvim-lua"] = { - after = "cmp_luasnip", - }, - - ["hrsh7th/cmp-nvim-lsp"] = { - after = "cmp-nvim-lua", - }, - - ["hrsh7th/cmp-buffer"] = { - after = "cmp-nvim-lsp", - }, - - ["hrsh7th/cmp-path"] = { - after = "cmp-buffer", - }, - + config = function() + require "plugins.configs.cmp" + end, + }, -- misc ['vimwiki/vimwiki'] = { @@ -128,30 +128,21 @@ local plugins = { end, }, - ["windwp/nvim-autopairs"] = { - after = "nvim-cmp", - config = function() - require("plugins.configs.others").autopairs() - end, - }, - ["numToStr/Comment.nvim"] = { - module = "Comment", - keys = { "gc", "gb" }, + -- keys = { "gc", "gb" }, config = function() require("plugins.configs.others").comment() end, - setup = function() + init = function() require("core.utils").load_mappings "comment" end, }, ["krolyxon/kterm"] = { - module = "kterm", config = function() require "plugins.configs.kterm" end, - setup = function() + init = function() require("core.utils").load_mappings "kterm" end, }, @@ -163,15 +154,16 @@ local plugins = { config = function() require("plugins.configs.others").blankline() end, - setup = function() + init = function() + require("core.utils").lazy_load "indent-blankline.nvim" require("core.utils").load_mappings "blankline" end, }, ["nvchad/nvim-colorizer.lua"] = { opt = true, - setup = function() - require("core.lazy_load").on_file_open "nvim-colorizer.lua" + init = function() + require("core.utils").lazy_load "nvim-colorizer.lua" end, config = function() require("plugins.configs.others").colorizer() @@ -186,20 +178,26 @@ local plugins = { -- Only load whichkey after all the gui ["folke/which-key.nvim"] = { - disable = false, - module = "which-key", + enabled = true, keys = { "", "\"", "'", "`" }, config = function() require "plugins.configs.whichkey" end, - setup = function() + init = function() require("core.utils").load_mappings "whichkey" end, }, ["rose-pine/neovim"] = {}, - - -- speed up deffered plugins - ["lewis6991/impatient.nvim"] = {}, } -require("core.packer").run(plugins) + +plugins = require("core.utils").format_plugins(plugins) + +-- pin commits for all default plugins +for _, value in pairs(plugins) do + value.pin = true +end + +-- load lazy.nvim options +local lazy_config = require "plugins.configs.lazy_nvim" +require("lazy").setup(plugins, lazy_config)