lazy: modularize config

This commit is contained in:
Guanran Wang 2024-02-21 12:09:18 +08:00
parent 7db94b71d6
commit 673547e91a
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
17 changed files with 271 additions and 284 deletions

View file

@ -1,2 +1,26 @@
require("options") require("options")
require("plugins")
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
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
-- Import plugin configurations
import = "plugins",
-- Required for the Nix package to function.
performance = {
rtp = {
reset = false,
},
},
})

13
lua/plugins/barbar.lua Normal file
View file

@ -0,0 +1,13 @@
return {
"romgrk/barbar.nvim",
dependencies = {
"lewis6991/gitsigns.nvim", -- OPTIONAL: for git status
"nvim-tree/nvim-web-devicons", -- OPTIONAL: for file icons
},
init = function()
vim.g.barbar_auto_setup = false
end,
opts = {
auto_hide = 1,
},
}

View file

@ -0,0 +1,9 @@
return {
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
opts = {},
init = function()
vim.cmd([[ colorscheme tokyonight-night ]])
end,
}

View file

@ -0,0 +1,82 @@
return {
"hrsh7th/nvim-cmp",
dependencies = {
-- Adds LSP completion capabilities
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-cmdline",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
"neovim/nvim-lspconfig",
-- Snippets
"L3MON4D3/LuaSnip", -- snippet engine
"rafamadriz/friendly-snippets", -- pre-configured snippet texts
"saadparwaiz1/cmp_luasnip", -- nvim-cmp source
},
init = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
require("mason").setup()
require("luasnip.loaders.from_vscode").lazy_load()
require("cmp").setup({
-- keybinds
mapping = cmp.mapping.preset.insert({
-- unsure
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-o>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
-- return to confirm
["<CR>"] = cmp.mapping.confirm({ select = false }),
-- tab to select prev/next option
-- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- that way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
-- snippet engine
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
-- snippet source
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "buffer" },
{ name = "path" },
}),
})
end,
}

View file

@ -1,64 +0,0 @@
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
require("mason").setup()
require("luasnip.loaders.from_vscode").lazy_load()
require("cmp").setup({
-- keybinds
mapping = cmp.mapping.preset.insert({
-- unsure
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-o>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
-- return to confirm
["<CR>"] = cmp.mapping.confirm({ select = false }),
-- tab to select prev/next option
-- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- that way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
-- snippet engine
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
-- snippet source
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "buffer" },
{ name = "path" },
}),
})

4
lua/plugins/gitsigns.lua Normal file
View file

@ -0,0 +1,4 @@
return {
"lewis6991/gitsigns.nvim",
opts = {},
}

View file

@ -1,181 +0,0 @@
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
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
performance = {
rtp = {
reset = false,
},
},
-- completions.lua
{
"hrsh7th/nvim-cmp", -- Auto completion
dependencies = {
"neovim/nvim-lspconfig",
-- Snippet Engine & its associated nvim-cmp source
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
-- Adds LSP completion capabilities
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
-- Adds a number of user-friendly snippets
"rafamadriz/friendly-snippets",
},
},
-- lspconfig.lua
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
},
{
-- I didn't figure out how to use null-ls/none-ls...
"sbdchd/neoformat",
init = function()
-- Prefer Alejandra for Nix files
vim.g.neoformat_enabled_nix = { "alejandra" }
end,
keys = {
{ "<Space>lf", "<cmd>Neoformat<CR>", desc = "Format file" },
},
},
-- nvim-tree.lua
{
"nvim-tree/nvim-tree.lua",
opts = {
view = {
adaptive_size = true,
},
},
init = function()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
end,
keys = {
{ "<Space>e", "<cmd>NvimTreeFindFileToggle<CR>", desc = "File Explorer" },
},
},
-- telescope.lua
{
"nvim-telescope/telescope.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
opts = {},
keys = {
{ "<Space>f", "<cmd>Telescope find_files<CR>", desc = "Find files" },
{ "<Space><Space>", "<cmd>Telescope oldfiles<CR>", desc = "Recent files" },
{ "<Space>sg", "<cmd>Telescope live_grep<CR>", desc = "Live grep" },
},
},
-- treesitter.lua
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
},
-- misc
{
"folke/tokyonight.nvim", -- theme
lazy = false,
priority = 1000,
opts = {},
init = function()
vim.cmd([[ colorscheme tokyonight-night ]])
end,
},
{
"nvim-lualine/lualine.nvim", -- status line
dependencies = {
"kyazdani42/nvim-web-devicons", -- for filetype icons
},
opts = {
options = {
-- disable separators
section_separators = "",
component_separators = "",
-- color scheme
theme = "tokyonight",
},
-- hide filename
sections = {
lualine_c = {},
},
},
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
opts = {}, -- this is equalent to setup({}) function
},
{
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeoutlen = 300
end,
opts = {},
},
{
"glepnir/lspsaga.nvim",
dependencies = {
"nvim-treesitter/nvim-treesitter", -- optional
"nvim-tree/nvim-web-devicons", -- optional
},
opts = {
lightbulb = {
virtual_text = false,
},
},
keys = {
{ "<Space>a", "<cmd>Lspsaga code_action<CR>", desc = "Code Action" },
},
},
{
"romgrk/barbar.nvim",
dependencies = {
"lewis6991/gitsigns.nvim", -- OPTIONAL: for git status
"nvim-tree/nvim-web-devicons", -- OPTIONAL: for file icons
},
init = function()
vim.g.barbar_auto_setup = false
end,
opts = {
auto_hide = 1,
},
},
{ "lewis6991/gitsigns.nvim", opts = {} },
})
-- LSP related
require("plugins.lspconfig") -- utilizes lsp
require("plugins.completions") -- adds completions
require("plugins.treesitter") -- better highlights

51
lua/plugins/lspconfig.lua Executable file → Normal file
View file

@ -1,24 +1,35 @@
local capabilities = require("cmp_nvim_lsp").default_capabilities() -- needed for nvim-cmp return {
require("mason").setup() "neovim/nvim-lspconfig",
require("mason-lspconfig").setup() dependencies = {
-- Portable package manager
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
-- lspconfig init = function()
require("lspconfig").lua_ls.setup({ local capabilities = require("cmp_nvim_lsp").default_capabilities() -- needed for nvim-cmp
capabilities = capabilities, require("mason").setup()
}) require("mason-lspconfig").setup()
require("lspconfig").nil_ls.setup({ -- lspconfig
capabilities = capabilities, require("lspconfig").lua_ls.setup({
settings = { capabilities = capabilities,
["nil"] = { })
formatting = {
command = { "alejandra" }, require("lspconfig").nil_ls.setup({
}, capabilities = capabilities,
nix = { settings = {
flake = { ["nil"] = {
autoArchive = true, formatting = {
command = { "alejandra" },
},
nix = {
flake = {
autoArchive = true,
},
},
}, },
}, },
}, })
}, end,
}) }

15
lua/plugins/lspsaga.lua Normal file
View file

@ -0,0 +1,15 @@
return {
"glepnir/lspsaga.nvim",
dependencies = {
"nvim-treesitter/nvim-treesitter", -- optional
"nvim-tree/nvim-web-devicons", -- optional
},
opts = {
lightbulb = {
virtual_text = false,
},
},
keys = {
{ "<Space>a", "<cmd>Lspsaga code_action<CR>", desc = "Code Action" },
},
}

20
lua/plugins/lualine.lua Normal file
View file

@ -0,0 +1,20 @@
return {
"nvim-lualine/lualine.nvim", -- status line
dependencies = {
"kyazdani42/nvim-web-devicons", -- for filetype icons
},
opts = {
options = {
-- disable separators
section_separators = "",
component_separators = "",
-- color scheme
theme = "tokyonight",
},
-- hide filename
sections = {
lualine_c = {},
},
},
}

10
lua/plugins/neoformat.lua Normal file
View file

@ -0,0 +1,10 @@
return {
"sbdchd/neoformat",
init = function()
-- Prefer Alejandra for Nix files
vim.g.neoformat_enabled_nix = { "alejandra" }
end,
keys = {
{ "<Space>lf", "<cmd>Neoformat<CR>", desc = "Format file" },
},
}

View file

@ -0,0 +1,5 @@
return {
"windwp/nvim-autopairs",
event = "InsertEnter",
opts = {},
}

15
lua/plugins/nvim-tree.lua Normal file
View file

@ -0,0 +1,15 @@
return {
"nvim-tree/nvim-tree.lua",
opts = {
view = {
adaptive_size = true,
},
},
init = function()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
end,
keys = {
{ "<Space>e", "<cmd>NvimTreeFindFileToggle<CR>", desc = "File Explorer" },
},
}

View file

@ -0,0 +1,24 @@
return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
init = function()
require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all"
ensure_installed = {
"nix",
"lua",
"vim",
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
auto_install = true,
highlight = {
enable = true,
},
indent = {
enable = true,
},
})
end,
}

10
lua/plugins/telescope.lua Normal file
View file

@ -0,0 +1,10 @@
return {
"nvim-telescope/telescope.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
opts = {},
keys = {
{ "<Space>f", "<cmd>Telescope find_files<CR>", desc = "Find files" },
{ "<Space><Space>", "<cmd>Telescope oldfiles<CR>", desc = "Recent files" },
{ "<Space>sg", "<cmd>Telescope live_grep<CR>", desc = "Live grep" },
},
}

View file

@ -1,18 +0,0 @@
require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all"
ensure_installed = {
"nix",
"lua",
"vim",
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
auto_install = true,
highlight = {
enable = true,
},
indent = {
enable = true,
},
})

View file

@ -0,0 +1,8 @@
return {
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeoutlen = 300
end,
opts = {},
}