clean packer config | Breaking change

This commit is contained in:
siduck 2022-01-30 12:51:46 +05:30
parent e8b31c9308
commit 64c32d2e5e
7 changed files with 89 additions and 104 deletions

View File

@ -9,4 +9,15 @@ M.ui = {
theme = "onedark", theme = "onedark",
} }
-- Install plugins
local userPlugins = require "custom.plugins" -- path to table
M.plugins = {
install = userPlugins,
}
-- NOTE: we heavily suggest using Packer's lazy loading (with the 'event','cmd' fields)
-- see: https://github.com/wbthomason/packer.nvim
-- https://nvchad.github.io/config/walkthrough
return M return M

View File

@ -1,30 +1,11 @@
-- This is an example init file , its supposed to be placed in /lua/custom/
-- This is where your custom modules and plugins go.
-- Please check NvChad docs if you're totally new to nvchad + dont know lua!! -- Please check NvChad docs if you're totally new to nvchad + dont know lua!!
-- This is an example init file in /lua/custom/
-- this init.lua can load stuffs etc too so treat it like your ~/.config/nvim/
-- MAPPINGS -- MAPPINGS
local map = require("core.utils").map local map = require("core.utils").map
map("n", "<leader>cc", ":Telescope <CR>") map("n", "<leader>cc", ":Telescope <CR>")
map("n", "<leader>q", ":q <CR>") map("n", "<leader>q", ":q <CR>")
-- NOTE: the 4th argument in the map function can be a table i.e options but its most likely un-needed so dont worry about it
-- Install plugins -- NOTE: the 4th argument in the map function is be a table i.e options but its most likely un-needed so dont worry about it
local customPlugins = require "core.customPlugins"
customPlugins.add(function(use)
use {
"max397574/better-escape.nvim",
event = "InsertEnter",
}
use {
"user or orgname/reponame",
--further packer options
}
end)
-- NOTE: we heavily suggest using Packer's lazy loading (with the 'event','cmd' fields)
-- see: https://github.com/wbthomason/packer.nvim
-- https://nvchad.github.io/config/walkthrough

7
examples/plugins.lua Normal file
View File

@ -0,0 +1,7 @@
-- Example plugins file!
-- (suggestion) -> lua/custom/plugins/init.lua or anywhere in custom dir
return {
{ "elkowar/yuck.vim", ft = "yuck" },
{ "ellisonleao/glow.nvim", cmd = "Glow" },
}

View File

@ -1,15 +0,0 @@
local M = {}
local plugins = {}
M.add = function(fn)
table.insert(plugins, fn)
end
-- load custom plugins in packer startup function
M.run = function(args)
for _, hook in pairs(plugins) do
hook(args)
end
end
return M

View File

@ -107,6 +107,7 @@ M.plugins = {
esc_insertmode_timeout = 300, esc_insertmode_timeout = 300,
}, },
default_plugin_config_replace = {}, default_plugin_config_replace = {},
install = nil,
} }
-- Don't use a single keymap twice -- Don't use a single keymap twice

View File

@ -42,7 +42,7 @@ local default = {
["<Tab>"] = function(fallback) ["<Tab>"] = function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif snippents_status and require("luasnip").expand_or_jumpable() then elseif snippets_status and require("luasnip").expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "") vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
else else
fallback() fallback()

View File

@ -5,46 +5,41 @@ if not present then
return false return false
end end
local use = packer.use local override_req = require("core.utils").override_req
return packer.startup(function() local plugins = {
local override_req = require("core.utils").override_req { "Nvchad/extensions" },
{ "nvim-lua/plenary.nvim" },
{ "lewis6991/impatient.nvim" },
{ "nathom/filetype.nvim" },
-- this is arranged on the basis of when a plugin starts {
-- this is the nvchad core repo containing utilities for some features like theme swticher, no need to lazy load
use "Nvchad/extensions"
use "nvim-lua/plenary.nvim"
use "lewis6991/impatient.nvim"
use "nathom/filetype.nvim"
use {
"wbthomason/packer.nvim", "wbthomason/packer.nvim",
event = "VimEnter", event = "VimEnter",
} },
use { {
"NvChad/nvim-base16.lua", "NvChad/nvim-base16.lua",
after = "packer.nvim", after = "packer.nvim",
config = function() config = function()
require("colors").init() require("colors").init()
end, end,
} },
use { {
"kyazdani42/nvim-web-devicons", "kyazdani42/nvim-web-devicons",
after = "nvim-base16.lua", after = "nvim-base16.lua",
config = override_req("nvim_web_devicons", "plugins.configs.icons", "setup"), config = override_req("nvim_web_devicons", "plugins.configs.icons", "setup"),
} },
use { {
"feline-nvim/feline.nvim", "feline-nvim/feline.nvim",
disable = not plugin_settings.status.feline, disable = not plugin_settings.status.feline,
after = "nvim-web-devicons", after = "nvim-web-devicons",
config = override_req("feline", "plugins.configs.statusline", "setup"), config = override_req("feline", "plugins.configs.statusline", "setup"),
} },
use { {
"akinsho/bufferline.nvim", "akinsho/bufferline.nvim",
disable = not plugin_settings.status.bufferline, disable = not plugin_settings.status.bufferline,
after = "nvim-web-devicons", after = "nvim-web-devicons",
@ -52,30 +47,30 @@ return packer.startup(function()
setup = function() setup = function()
require("core.mappings").bufferline() require("core.mappings").bufferline()
end, end,
} },
use { {
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
disable = not plugin_settings.status.blankline, disable = not plugin_settings.status.blankline,
event = "BufRead", event = "BufRead",
config = override_req("indent_blankline", "plugins.configs.others", "blankline"), config = override_req("indent_blankline", "plugins.configs.others", "blankline"),
} },
use { {
"norcalli/nvim-colorizer.lua", "norcalli/nvim-colorizer.lua",
disable = not plugin_settings.status.colorizer, disable = not plugin_settings.status.colorizer,
event = "BufRead", event = "BufRead",
config = override_req("nvim_colorizer", "plugins.configs.others", "colorizer"), config = override_req("nvim_colorizer", "plugins.configs.others", "colorizer"),
} },
use { {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
event = "BufRead", event = "BufRead",
config = override_req("nvim_treesitter", "plugins.configs.treesitter", "setup"), config = override_req("nvim_treesitter", "plugins.configs.treesitter", "setup"),
} },
-- git stuff -- git stuff
use { {
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
disable = not plugin_settings.status.gitsigns, disable = not plugin_settings.status.gitsigns,
opt = true, opt = true,
@ -83,11 +78,11 @@ return packer.startup(function()
setup = function() setup = function()
require("core.utils").packer_lazy_load "gitsigns.nvim" require("core.utils").packer_lazy_load "gitsigns.nvim"
end, end,
} },
-- lsp stuff -- lsp stuff
use { {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
module = "lspconfig", module = "lspconfig",
opt = true, opt = true,
@ -99,105 +94,106 @@ return packer.startup(function()
end, 0) end, 0)
end, end,
config = override_req("lspconfig", "plugins.configs.lspconfig"), config = override_req("lspconfig", "plugins.configs.lspconfig"),
} },
use { {
"ray-x/lsp_signature.nvim", "ray-x/lsp_signature.nvim",
disable = not plugin_settings.status.lspsignature, disable = not plugin_settings.status.lspsignature,
after = "nvim-lspconfig", after = "nvim-lspconfig",
config = override_req("signature", "plugins.configs.others", "signature"), config = override_req("signature", "plugins.configs.others", "signature"),
} },
use { {
"andymass/vim-matchup", "andymass/vim-matchup",
disable = not plugin_settings.status.vim_matchup, disable = not plugin_settings.status.vim_matchup,
opt = true, opt = true,
setup = function() setup = function()
require("core.utils").packer_lazy_load "vim-matchup" require("core.utils").packer_lazy_load "vim-matchup"
end, end,
} },
use { {
"max397574/better-escape.nvim", "max397574/better-escape.nvim",
disable = not plugin_settings.status.better_escape, disable = not plugin_settings.status.better_escape,
event = "InsertEnter", event = "InsertEnter",
config = override_req("better_escape", "plugins.configs.others", "better_escape"), config = override_req("better_escape", "plugins.configs.others", "better_escape"),
} },
-- load luasnips + cmp related in insert mode only -- load luasnips + cmp related in insert mode only
use { {
"rafamadriz/friendly-snippets", "rafamadriz/friendly-snippets",
module = "cmp_nvim_lsp", module = "cmp_nvim_lsp",
disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets), disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets),
event = "InsertEnter", event = "InsertEnter",
} },
-- cmp by default loads after friendly snippets -- cmp by default loads after friendly snippets
-- if snippets are disabled -> cmp loads on insertEnter! -- if snippets are disabled -> cmp loads on insertEnter!
use { {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
event = not plugin_settings.status.snippets and "InsertEnter", event = not plugin_settings.status.snippets and "InsertEnter",
after = plugin_settings.status.snippets and "friendly-snippets", after = plugin_settings.status.snippets and "friendly-snippets",
config = override_req("nvim_cmp", "plugins.configs.cmp", "setup"), config = override_req("nvim_cmp", "plugins.configs.cmp", "setup"),
} },
use { {
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets), disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets),
wants = "friendly-snippets", wants = "friendly-snippets",
after = "nvim-cmp", after = "nvim-cmp",
config = override_req("luasnip", "plugins.configs.others", "luasnip"), config = override_req("luasnip", "plugins.configs.others", "luasnip"),
} },
use { {
"saadparwaiz1/cmp_luasnip", "saadparwaiz1/cmp_luasnip",
disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets), disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets),
after = plugin_settings.options.cmp.lazy_load and "LuaSnip", after = plugin_settings.options.cmp.lazy_load and "LuaSnip",
} },
use { {
"hrsh7th/cmp-nvim-lua", "hrsh7th/cmp-nvim-lua",
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
after = (plugin_settings.status.snippets and "cmp_luasnip") or "nvim-cmp", after = (plugin_settings.status.snippets and "cmp_luasnip") or "nvim-cmp",
} },
use { {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
after = "cmp-nvim-lua", after = "cmp-nvim-lua",
} },
use { {
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
after = "cmp-nvim-lsp", after = "cmp-nvim-lsp",
} },
use { {
"hrsh7th/cmp-path", "hrsh7th/cmp-path",
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
after = "cmp-buffer", after = "cmp-buffer",
} },
-- misc plugins -- misc plugins
use { {
"windwp/nvim-autopairs", "windwp/nvim-autopairs",
disable = not plugin_settings.status.autopairs, disable = not plugin_settings.status.autopairs,
after = plugin_settings.options.autopairs.loadAfter, after = plugin_settings.options.autopairs.loadAfter,
config = override_req("nvim_autopairs", "plugins.configs.others", "autopairs"), config = override_req("nvim_autopairs", "plugins.configs.others", "autopairs"),
} },
use { {
"glepnir/dashboard-nvim", "glepnir/dashboard-nvim",
disable = not plugin_settings.status.dashboard, disable = not plugin_settings.status.dashboard,
config = override_req("dashboard", "plugins.configs.dashboard"), config = override_req("dashboard", "plugins.configs.dashboard"),
setup = function() setup = function()
require("core.mappings").dashboard() require("core.mappings").dashboard()
end, end,
} },
use { {
"numToStr/Comment.nvim", "numToStr/Comment.nvim",
disable = not plugin_settings.status.comment, disable = not plugin_settings.status.comment,
module = "Comment", module = "Comment",
@ -205,10 +201,10 @@ return packer.startup(function()
setup = function() setup = function()
require("core.mappings").comment() require("core.mappings").comment()
end, end,
} },
-- file managing , picker etc -- file managing , picker etc
use { {
"kyazdani42/nvim-tree.lua", "kyazdani42/nvim-tree.lua",
disable = not plugin_settings.status.nvimtree, disable = not plugin_settings.status.nvimtree,
-- only set "after" if lazy load is disabled and vice versa for "cmd" -- only set "after" if lazy load is disabled and vice versa for "cmd"
@ -218,9 +214,9 @@ return packer.startup(function()
setup = function() setup = function()
require("core.mappings").nvimtree() require("core.mappings").nvimtree()
end, end,
} },
use { {
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
module = "telescope", module = "telescope",
cmd = "Telescope", cmd = "Telescope",
@ -228,7 +224,11 @@ return packer.startup(function()
setup = function() setup = function()
require("core.mappings").telescope() require("core.mappings").telescope()
end, end,
} },
-- load user defined plugins }
require("core.customPlugins").run(use)
end) -- append user plugins to default plugins
local user_Plugins = plugin_settings.install
plugins[#plugins + 1] = user_Plugins
return packer.startup { plugins }