mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 08:53:33 +02:00
refactor: config.plugins -> plugins
This commit is contained in:
parent
8625b49288
commit
09c27b5e4d
17 changed files with 43 additions and 36 deletions
6
lua/plugins/api.lua
Normal file
6
lua/plugins/api.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
-- plugins that provide apis for other plugins
|
||||
return {
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
"nvim-lua/plenary.nvim",
|
||||
"MunifTanjim/nui.nvim",
|
||||
}
|
91
lua/plugins/coding.lua
Normal file
91
lua/plugins/coding.lua
Normal file
|
@ -0,0 +1,91 @@
|
|||
return {
|
||||
|
||||
-- git signs
|
||||
{
|
||||
"lewis6991/gitsigns.nvim",
|
||||
event = "BufReadPre",
|
||||
config = {
|
||||
signs = {
|
||||
add = { hl = "GitSignsAdd", text = "▎", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
|
||||
change = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
|
||||
delete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
|
||||
topdelete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
|
||||
changedelete = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
|
||||
untracked = { hl = "GitSignsAdd", text = "▍", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- snippets
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
dependencies = {
|
||||
"rafamadriz/friendly-snippets",
|
||||
config = function()
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
-- auto completion
|
||||
{
|
||||
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
-- auto pairs
|
||||
{
|
||||
"echasnovski/mini.pairs",
|
||||
event = "VeryLazy",
|
||||
config = function()
|
||||
require("mini.pairs").setup({})
|
||||
end,
|
||||
},
|
||||
|
||||
-- comments
|
||||
{ "JoosepAlviste/nvim-ts-context-commentstring" },
|
||||
{
|
||||
"echasnovski/mini.comment",
|
||||
event = "VeryLazy",
|
||||
config = function()
|
||||
require("mini.comment").setup({
|
||||
hooks = {
|
||||
pre = function()
|
||||
require("ts_context_commentstring.internal").update_commentstring({})
|
||||
end,
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
21
lua/plugins/colorscheme.lua
Normal file
21
lua/plugins/colorscheme.lua
Normal file
|
@ -0,0 +1,21 @@
|
|||
return {
|
||||
|
||||
-- tokyonight
|
||||
{
|
||||
"folke/tokyonight.nvim",
|
||||
lazy = false,
|
||||
priority = 1000,
|
||||
config = function()
|
||||
local tokyonight = require("tokyonight")
|
||||
tokyonight.setup({ style = "moon" })
|
||||
tokyonight.load()
|
||||
end,
|
||||
},
|
||||
|
||||
-- catppuccin
|
||||
{
|
||||
"catppuccin/nvim",
|
||||
name = "catppuccin",
|
||||
priority = 1000,
|
||||
},
|
||||
}
|
35
lua/plugins/editor.lua
Normal file
35
lua/plugins/editor.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
vim.g.neo_tree_remove_legacy_commands = 1
|
||||
|
||||
return {
|
||||
|
||||
-- file explorer
|
||||
{
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
cmd = "Neotree",
|
||||
keys = { { "<leader>ft", "<cmd>Neotree toggle<cr>", desc = "NeoTree" } },
|
||||
config = {
|
||||
filesystem = {
|
||||
follow_current_file = true,
|
||||
hijack_netrw_behavior = "open_current",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- fuzzy finder
|
||||
{
|
||||
"nvim-telescope/telescope.nvim",
|
||||
cmd = "Telescope",
|
||||
keys = { { "<leader><space>", "<cmd>Telescope find_files<cr>", desc = "Find Files" } },
|
||||
config = true,
|
||||
},
|
||||
|
||||
-- which-key
|
||||
{
|
||||
"folke/which-key.nvim",
|
||||
event = "VeryLazy",
|
||||
config = {
|
||||
plugins = { spelling = true },
|
||||
key_labels = { ["<leader>"] = "SPC" },
|
||||
},
|
||||
},
|
||||
}
|
40
lua/plugins/lsp/format.lua
Normal file
40
lua/plugins/lsp/format.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
local M = {}
|
||||
|
||||
M.autoformat = true
|
||||
|
||||
function M.toggle()
|
||||
M.autoformat = not M.autoformat
|
||||
vim.notify(M.autoformat and "Enabled format on save" or "Disabled format on save")
|
||||
end
|
||||
|
||||
function M.format()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local ft = vim.bo[buf].filetype
|
||||
local have_nls = #require("null-ls.sources").get_available(ft, "NULL_LS_FORMATTING") > 0
|
||||
|
||||
vim.lsp.buf.format({
|
||||
bufnr = buf,
|
||||
filter = function(client)
|
||||
if have_nls then
|
||||
return client.name == "null-ls"
|
||||
end
|
||||
return client.name ~= "null-ls"
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function M.on_attach(client, buf)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = vim.api.nvim_create_augroup("LspFormat", {}),
|
||||
buffer = buf,
|
||||
callback = function()
|
||||
if M.autoformat then
|
||||
M.format()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
46
lua/plugins/lsp/init.lua
Normal file
46
lua/plugins/lsp/init.lua
Normal file
|
@ -0,0 +1,46 @@
|
|||
local servers = require("plugins.lsp.servers")
|
||||
|
||||
local function on_attach(client, bufnr)
|
||||
require("plugins.lsp.format").on_attach(client, bufnr)
|
||||
require("plugins.lsp.keymaps").on_attach(client, bufnr)
|
||||
end
|
||||
|
||||
return {
|
||||
-- lspconfig
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = "BufReadPre",
|
||||
dependencies = {
|
||||
{ "folke/neoconf.nvim", cmd = "Neoconf", config = true },
|
||||
{ "folke/neodev.nvim", config = true },
|
||||
{ "williamboman/mason.nvim", config = true },
|
||||
{ "williamboman/mason-lspconfig.nvim", config = { ensure_installed = vim.tbl_keys(servers) } },
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
config = function()
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
for server, opts in pairs(servers) do
|
||||
opts.capabilities = capabilities
|
||||
opts.on_attach = on_attach
|
||||
require("lspconfig")[server].setup(opts)
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
-- formatters
|
||||
{
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
event = "BufReadPre",
|
||||
config = function()
|
||||
local nls = require("null-ls")
|
||||
nls.setup({
|
||||
on_attach = on_attach,
|
||||
sources = {
|
||||
-- nls.builtins.formatting.prettierd,
|
||||
nls.builtins.formatting.stylua,
|
||||
nls.builtins.diagnostics.flake8,
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
70
lua/plugins/lsp/keymaps.lua
Normal file
70
lua/plugins/lsp/keymaps.lua
Normal file
|
@ -0,0 +1,70 @@
|
|||
local M = {}
|
||||
|
||||
function M.on_attach(client, buffer)
|
||||
local cap = client.server_capabilities
|
||||
|
||||
require("which-key").register({
|
||||
buffer = buffer,
|
||||
["<leader>"] = {
|
||||
c = {
|
||||
name = "+code",
|
||||
{
|
||||
cond = client.name == "tsserver",
|
||||
o = { "<cmd>:TypescriptOrganizeImports<CR>", "Organize Imports" },
|
||||
R = { "<cmd>:TypescriptRenameFile<CR>", "Rename File" },
|
||||
},
|
||||
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename", cond = cap.renameProvider },
|
||||
a = {
|
||||
{ vim.lsp.buf.code_action, "Code Action" },
|
||||
{ "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action", mode = "v" },
|
||||
},
|
||||
f = {
|
||||
{
|
||||
require("plugins.lsp.format").format,
|
||||
"Format Document",
|
||||
cond = cap.documentFormatting,
|
||||
},
|
||||
{
|
||||
require("plugins.lsp.format").format,
|
||||
"Format Range",
|
||||
cond = cap.documentRangeFormatting,
|
||||
mode = "v",
|
||||
},
|
||||
},
|
||||
d = { vim.diagnostic.open_float, "Line Diagnostics" },
|
||||
l = {
|
||||
name = "+lsp",
|
||||
i = { "<cmd>LspInfo<cr>", "Lsp Info" },
|
||||
},
|
||||
},
|
||||
x = {
|
||||
d = { "<cmd>Telescope diagnostics<cr>", "Search Diagnostics" },
|
||||
},
|
||||
},
|
||||
g = {
|
||||
name = "+goto",
|
||||
d = { "<cmd>Telescope lsp_definitions<cr>", "Goto Definition" },
|
||||
r = { "<cmd>Telescope lsp_references<cr>", "References" },
|
||||
R = { "<cmd>Trouble lsp_references<cr>", "Trouble References" },
|
||||
D = { "<cmd>Telescope lsp_declarations<CR>", "Goto Declaration" },
|
||||
I = { "<cmd>Telescope lsp_implementations<CR>", "Goto Implementation" },
|
||||
t = { "<cmd>Telescope lsp_type_definitions<cr>", "Goto Type Definition" },
|
||||
},
|
||||
["<C-k>"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "Signature Help", mode = { "n", "i" } },
|
||||
["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Hover" },
|
||||
["[d"] = { "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Next Diagnostic" },
|
||||
["]d"] = { "<cmd>lua vim.diagnostic.goto_next()<CR>", "Prev Diagnostic" },
|
||||
["[e"] = { "<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<CR>", "Next Error" },
|
||||
["]e"] = { "<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<CR>", "Prev Error" },
|
||||
["[w"] = {
|
||||
"<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.WARNING})<CR>",
|
||||
"Next Warning",
|
||||
},
|
||||
["]w"] = {
|
||||
"<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.WARNING})<CR>",
|
||||
"Prev Warning",
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
25
lua/plugins/lsp/servers.lua
Normal file
25
lua/plugins/lsp/servers.lua
Normal file
|
@ -0,0 +1,25 @@
|
|||
---@type lspconfig.options
|
||||
local servers = {
|
||||
bashls = {},
|
||||
clangd = {},
|
||||
cssls = {},
|
||||
tsserver = {},
|
||||
html = {},
|
||||
jsonls = {},
|
||||
pyright = {},
|
||||
yamlls = {},
|
||||
sumneko_lua = {
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return servers
|
16
lua/plugins/treesitter.lua
Normal file
16
lua/plugins/treesitter.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
return {
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
build = ":TSUpdate",
|
||||
event = "BufReadPost",
|
||||
config = function()
|
||||
require("nvim-treesitter.configs").setup({
|
||||
sync_install = false,
|
||||
auto_install = true,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
context_commentstring = { enable = true, enable_autocmd = false },
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
99
lua/plugins/ui.lua
Normal file
99
lua/plugins/ui.lua
Normal file
|
@ -0,0 +1,99 @@
|
|||
return {
|
||||
-- better vim.notify
|
||||
{
|
||||
"rcarriga/nvim-notify",
|
||||
init = function()
|
||||
vim.notify = function(...)
|
||||
vim.notify = require("notify")
|
||||
return vim.notify(...)
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
-- better vim.ui
|
||||
{
|
||||
"stevearc/dressing.nvim",
|
||||
event = "VeryLazy",
|
||||
config = true,
|
||||
},
|
||||
|
||||
-- bufferline
|
||||
{
|
||||
"akinsho/nvim-bufferline.lua",
|
||||
event = "BufAdd",
|
||||
config = true,
|
||||
},
|
||||
|
||||
-- statusline
|
||||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
event = "VeryLazy",
|
||||
config = {
|
||||
options = {
|
||||
globalstatus = true,
|
||||
disabled_filetypes = { statusline = { "lazy", "alpha" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- indent guides for Neovim
|
||||
{
|
||||
"lukas-reineke/indent-blankline.nvim",
|
||||
event = "BufReadPre",
|
||||
config = {
|
||||
char = "▏",
|
||||
},
|
||||
},
|
||||
|
||||
-- dashboard
|
||||
{
|
||||
"goolord/alpha-nvim",
|
||||
lazy = false,
|
||||
config = function()
|
||||
local dashboard = require("alpha.themes.dashboard")
|
||||
local logo = [[
|
||||
██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z
|
||||
██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z
|
||||
██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z
|
||||
██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z
|
||||
███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║
|
||||
╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
|
||||
]]
|
||||
|
||||
dashboard.section.header.val = vim.split(logo, "\n")
|
||||
dashboard.section.buttons.val = {
|
||||
dashboard.button("f", " " .. " Find file", ":Telescope find_files <CR>"),
|
||||
dashboard.button("n", " " .. " New file", ":ene <BAR> startinsert <CR>"),
|
||||
dashboard.button("r", " " .. " Recent files", ":Telescope oldfiles <CR>"),
|
||||
dashboard.button("g", " " .. " Find text", ":Telescope live_grep <CR>"),
|
||||
dashboard.button("c", " " .. " Config", ":e $MYVIMRC <CR>"),
|
||||
dashboard.button("q", " " .. " Quit", ":qa<CR>"),
|
||||
}
|
||||
for _, button in ipairs(dashboard.section.buttons.val) do
|
||||
button.opts.hl = "AlphaButtons"
|
||||
button.opts.hl_shortcut = "AlphaShortcut"
|
||||
end
|
||||
dashboard.section.footer.opts.hl = "Type"
|
||||
dashboard.section.header.opts.hl = "AlphaHeader"
|
||||
dashboard.section.buttons.opts.hl = "AlphaButtons"
|
||||
dashboard.opts.layout[1].val = 8
|
||||
|
||||
if vim.bo[0].filetype == "lazy" then
|
||||
vim.notify("Missing plugins installed!", vim.log.levels.INFO, { title = "LazyVim" })
|
||||
vim.cmd.close()
|
||||
end
|
||||
|
||||
require("alpha").setup(dashboard.opts)
|
||||
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "LazyVimStarted",
|
||||
callback = function()
|
||||
local stats = require("lazy").stats()
|
||||
local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100)
|
||||
dashboard.section.footer.val = "⚡ Neovim loaded " .. stats.count .. " plugins in " .. ms .. "ms"
|
||||
pcall(vim.cmd.AlphaRedraw)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue