refactor: move everything under lazyvim

This commit is contained in:
Folke Lemaitre 2023-01-01 14:33:56 +01:00
parent 39ccddad5f
commit 8eb8d235c9
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
17 changed files with 10 additions and 10 deletions

View 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",
}

View file

@ -0,0 +1,83 @@
return {
-- 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" },
}),
formatting = {
format = function(_, item)
local icons = require("lazyvim.config.icons").kinds
if icons[item.kind] then
item.kind = icons[item.kind] .. item.kind
end
return item
end,
},
})
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,
},
}

View 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,
},
}

View file

@ -0,0 +1,130 @@
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" },
{ "<leader>ff", "<cmd>Telescope find_files<cr>", desc = "Find Files" },
{ "<leader>fr", "<cmd>Telescope oldfiles<cr>", desc = "Recent" },
{ "<leader>fb", "<cmd>Telescope buffers<cr>", desc = "Buffers" },
{ "<leader>/", "<cmd>Telescope live_grep<cr>", desc = "Find in Files (Grep)" },
},
config = true,
},
-- easily jump to any location and enhanced f/t motions for Leap
{
"ggandor/leap.nvim",
event = "VeryLazy",
dependencies = {
{ "ggandor/flit.nvim", config = { labeled_modes = "nv" } },
},
config = function()
require("leap").add_default_mappings()
end,
},
-- which-key
{
"folke/which-key.nvim",
event = "VeryLazy",
config = function()
local wk = require("which-key")
wk.setup({
show_help = false,
plugins = { spelling = true },
key_labels = { ["<leader>"] = "SPC" },
})
wk.register({
mode = { "n", "v" },
["g"] = { name = "+goto" },
["]"] = { name = "+next" },
["["] = { name = "+prev" },
["<leader>b"] = { name = "+buffer" },
["<leader>c"] = { name = "+code" },
["<leader>f"] = { name = "+file" },
["<leader>g"] = { name = "+git" },
["<leader>x"] = { name = "+diagnostics" },
})
end,
},
-- git signs
{
"lewis6991/gitsigns.nvim",
event = "BufReadPre",
config = {
signs = {
add = { text = "" },
change = { text = "" },
delete = { text = "" },
topdelete = { text = "" },
changedelete = { text = "" },
untracked = { text = "" },
},
},
},
-- references
{
"RRethy/vim-illuminate",
event = "BufReadPost",
config = function()
require("illuminate").configure({ delay = 200 })
end,
keys = {
{
"]]",
function()
require("illuminate").goto_next_reference(false)
end,
desc = "Next Reference",
},
{
"[[",
function()
require("illuminate").goto_prev_reference(false)
end,
desc = "Prev Reference",
},
},
},
-- buffer remove
{
"echasnovski/mini.bufremove",
keys = {
{
"<leader>bd",
function()
require("mini.bufremove").delete(0, false)
end,
desc = "Delete Buffer",
},
{
"<leader>bD",
function()
require("mini.bufremove").delete(0, true)
end,
desc = "Delete Buffer (Force)",
},
},
},
}

View 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." .. buf, {}),
buffer = buf,
callback = function()
if M.autoformat then
M.format()
end
end,
})
end
end
return M

View file

@ -0,0 +1,64 @@
local servers = require("lazyvim.plugins.lsp.servers")
local function on_attach(client, bufnr)
require("lazyvim.plugins.lsp.format").on_attach(client, bufnr)
require("lazyvim.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,
cmd = "Mason",
keys = { { "<leader>cm", "<cmd>Mason<cr>", desc = "Mason" } },
},
{ "williamboman/mason-lspconfig.nvim", config = { automatic_installation = true } },
"hrsh7th/cmp-nvim-lsp",
},
config = function()
-- diagnostics
for name, icon in pairs(require("lazyvim.config.icons").diagnostics) do
name = "DiagnosticSign" .. name
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
end
vim.diagnostic.config({
underline = true,
update_in_insert = false,
virtual_text = { spacing = 4, prefix = "" },
severity_sort = true,
})
-- lspconfig
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,
},
}

View file

@ -0,0 +1,74 @@
local M = {}
function M.on_attach(client, buffer)
local self = M.new(client, buffer)
self:map("<leader>cd", vim.diagnostic.open_float, { desc = "Line Diagnostics" })
self:map("<leader>cl", "LspInfo", { desc = "Lsp Info" })
self:map("<leader>xd", "Telescope diagnostics", { desc = "Telescope Diagnostics" })
self:map("gd", "Telescope lsp_definitions", { desc = "Goto Definition" })
self:map("gr", "Telescope lsp_references", { desc = "References" })
self:map("gD", "Telescope lsp_declarations", { desc = "Goto Declaration" })
self:map("gI", "Telescope lsp_implementations", { desc = "Goto Implementation" })
self:map("gt", "Telescope lsp_type_definitions", { desc = "Goto Type Definition" })
self:map("K", vim.lsp.buf.hover, { desc = "Hover" })
self:map("[d", M.diagnostic_goto(true), { desc = "Next Diagnostic" })
self:map("]d", M.diagnostic_goto(false), { desc = "Prev Diagnostic" })
self:map("]e", M.diagnostic_goto(true, "ERROR"), { desc = "Next Error" })
self:map("[e", M.diagnostic_goto(false, "ERROR"), { desc = "Prev Error" })
self:map("]w", M.diagnostic_goto(true, "WARNING"), { desc = "Next Warning" })
self:map("[w", M.diagnostic_goto(false, "WARNING"), { desc = "Prev Warning" })
self:map("<C-k>", vim.lsp.buf.signature_help, { desc = "Signature Help", mode = { "i", "n" }, has = "signatureHelp" })
self:map("<leader>ca", vim.lsp.buf.code_action, { desc = "Code Action", mode = { "n", "v" }, has = "codeAction" })
local format = require("lazyvim.plugins.lsp.format").format
self:map("<leader>cf", format, { desc = "Format Document", has = "documentFormatting" })
self:map("<leader>cf", format, { desc = "Format Range", mode = "v", has = "documentRangeFormatting" })
self:map("<leader>cr", M.rename, { expr = true, desc = "Rename", has = "rename" })
if client.name == "tsserver" and pcall(require, "typescript") then
self:map("<leader>co", "TypescriptOrganizeImports", { desc = "Organize Imports" })
self:map("<leader>cR", "TypescriptRenameFile", { desc = "Rename File" })
end
end
function M.new(client, buffer)
return setmetatable({ client = client, buffer = buffer }, { __index = M })
end
function M:has(cap)
return self.client.server_capabilities[cap .. "Provider"]
end
function M:map(lhs, rhs, opts)
opts = opts or {}
if opts.has and not self:has(opts.has) then
return
end
vim.keymap.set(
opts.mode or "n",
lhs,
type(rhs) == "string" and ("<cmd>%s<cr>"):format(rhs) or rhs,
---@diagnostic disable-next-line: no-unknown
{ silent = true, buffer = self.buffer, expr = opts.expr, desc = opts.desc }
)
end
function M.rename()
if pcall(require, "inc_rename") then
return ":IncRename " .. vim.fn.expand("<cword>")
else
vim.lsp.buf.rename()
end
end
function M.diagnostic_goto(next, severity)
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
severity = severity and vim.diagnostic.severity[severity] or nil
return function()
go({ severity = severity })
end
end
return M

View file

@ -0,0 +1,26 @@
-- Add any servers here together with their settings
---@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

View file

@ -0,0 +1,32 @@
return {
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
event = "BufReadPost",
config = function()
require("nvim-treesitter.configs").setup({
sync_install = false,
ensure_installed = {
"bash",
"help",
"html",
"javascript",
"json",
"lua",
"markdown",
"markdown_inline",
"python",
"query",
"regex",
"tsx",
"typescript",
"vim",
"yaml",
},
highlight = { enable = true },
indent = { enable = true },
context_commentstring = { enable = true, enable_autocmd = false },
})
end,
},
}

122
lua/lazyvim/plugins/ui.lua Normal file
View file

@ -0,0 +1,122 @@
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 = "",
},
},
-- noicer ui
{
"folke/noice.nvim",
event = "VeryLazy",
config = {
lsp = {
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
},
},
presets = {
bottom_search = true,
command_palette = true,
long_message_to_split = true,
},
},
},
-- 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("l", "" .. " Lazy", ":Lazy<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.o.filetype == "lazy" then
-- close and re-open Lazy after showing alpha
vim.notify("Missing plugins installed!", vim.log.levels.INFO, { title = "lazy.nvim" })
vim.cmd.close()
require("alpha").setup(dashboard.opts)
require("lazy").show()
else
require("alpha").setup(dashboard.opts)
end
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,
},
}

View file

@ -0,0 +1,5 @@
return {
-- measure startuptime
{ "dstein64/vim-startuptime", cmd = "StartupTime" },
}