1
0
Fork 0

simplify neovim config

This commit is contained in:
Luca Bilke 2024-05-28 11:13:16 +02:00
parent 8a552bf9c9
commit 0f2cf9b657
8 changed files with 112 additions and 562 deletions

View file

@ -1,4 +1,88 @@
_G.Config = require("config")
_G.Lib = require("lib")
require("config.lazy")
-- NOTE: lazy.nvim setup
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
require("lazy").setup({
spec = {
{
"LazyVim/LazyVim",
import = "lazyvim.plugins",
},
{ import = "lazyvim.plugins.extras.coding.copilot" },
{ import = "lazyvim.plugins.extras.coding.mini-surround" },
{ import = "lazyvim.plugins.extras.dap.core" },
{ import = "lazyvim.plugins.extras.editor.aerial" },
{ import = "lazyvim.plugins.extras.editor.leap" },
{ import = "lazyvim.plugins.extras.test.core" },
-- { import = "lazyvim.plugins.extras.ui.edgy" },
{ import = "lazyvim.plugins.extras.ui.mini-indentscope" },
{ import = "lazyvim.plugins.extras.lang.ansible" },
{ import = "lazyvim.plugins.extras.lang.docker" },
{ import = "lazyvim.plugins.extras.lang.helm" },
{ import = "lazyvim.plugins.extras.lang.markdown" },
{ import = "lazyvim.plugins.extras.lang.python" },
{ import = "lazyvim.plugins.extras.lang.rust" },
{ import = "lazyvim.plugins.extras.lang.terraform" },
{ import = "lazyvim.plugins.extras.lang.toml" },
{ import = "lazyvim.plugins.extras.lang.toml" },
{ import = "plugins" },
},
defaults = {
lazy = true,
version = false,
},
install = { colorscheme = { "tokyonight" } },
checker = { enabled = true },
performance = {
rtp = {
disabled_plugins = {
"gzip",
-- "matchit",
"matchparen",
"netrwPlugin",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})
-- NOTE: Autocmds
for _, autocmd in ipairs({
{ -- Automatically change line numeration
{ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" },
{ command = 'if &nu && mode() != "i" | set rnu | endif' },
},
{ -- Automatically change line numeration
{ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" },
{ command = "if &nu | set nornu | endif" },
},
{ -- Trigger shortcuts script
"BufWritePost",
{ pattern = { "directories", "files" }, command = "silent!!shortcuts" },
},
{ -- Trigger xrdb
"BufWritePost",
{ pattern = { "xresources" }, command = "silent!!xrdb %" },
},
}) do
vim.api.nvim_create_autocmd(autocmd[1], autocmd[2])
end

View file

@ -1,57 +0,0 @@
-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
-- Add any additional autocmds here
local autocmds = {
{ -- Automatically change line numeration
{ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" },
{
group = "auto_number",
command = 'if &nu && mode() != "i" | set rnu | endif',
-- callback = function()
-- if vim.opt.number and vim.fn.mode() ~= "i" then
-- vim.opt.relativenumber = true
-- end
-- end,
},
},
{ -- Automatically change line numeration
{ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" },
{
group = "auto_number",
command = "if &nu | set nornu | endif",
-- callback = function()
-- if vim.opt.number then
-- vim.opt.relativenumber = false
-- end
-- end,
},
},
{ -- Trigger shortcuts script
"BufWritePost",
{
pattern = { "directories", "files" },
command = "silent!!shortcuts",
},
},
{ -- Trigger xrdb
"BufWritePost",
{
pattern = { "xresources" },
command = "silent!!xrdb %",
},
},
}
vim.api.nvim_create_augroup("user_config", { clear = true })
for _, entry in ipairs(autocmds) do
local event = entry[1]
local opts = entry[2]
if type(opts.group) == "string" and opts.group ~= "" then
local exists, _ = pcall(vim.api.nvim_get_autocmds, { group = opts.group })
if not exists then
vim.api.nvim_create_augroup(opts.group, {})
end
end
vim.api.nvim_create_autocmd(event, opts)
end

View file

@ -1,205 +0,0 @@
---@diagnostic disable: missing-fields
---@class config.language
local M = {}
---@type table<string, conform.FormatterUnit>
M.formatters_by_ft = {
css = { "prettier" },
scss = { "prettier" },
lua = { "stylua" },
python = { "black" },
sh = { "shfmt" },
}
---@type table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride>
M.formatters = {
injected = { options = { ignore_errors = true } },
shfmt = { prepend_args = { "-i", "4", "-ci" } },
}
---@type table<string,table>
M.linters_by_ft = {
dockerfile = { "hadolint" },
markdown = { "markdownlint" },
}
---@type table<string,table>
M.linters = {}
---@type Array<string>
M.mason_install = {
"ansible-lint",
"ansible-language-server",
"basedpyright",
"bash-language-server",
"codelldb",
"debugpy",
"dockerfile-language-server",
"docker-compose-language-service",
"helm-ls",
"json-lsp",
"lua-language-server",
"hadolint",
"marksman",
"markdownlint",
"prettier",
"ruff-lsp",
"rust-analyzer",
"yaml-language-server",
}
---@type Array<string>
M.treesitter_install = {
"bash",
"c",
"diff",
"dockerfile",
"helm",
"html",
"json",
"jsonc",
"json5",
"lua",
"luadoc",
"luap",
"markdown",
"markdown_inline",
"ninja",
"python",
"query",
"regex",
"ron",
"rst",
"rust",
"toml",
"vim",
"vimdoc",
"xml",
"yaml",
}
---@type lspconfig.options
M.lsp = {
intelephense = {
init_options = {
storagePath = os.getenv("XDG_CACHE_HOME") .. "/intelephense",
globalStoragePath = os.getenv("XDG_CONFIG_HOME") .. "/intelephense",
licenceKey = require("lib").get_secret("intelephense")
},
},
jsonls = {
on_new_config = function(new_config)
new_config.settings.json.schemas = new_config.settings.json.schemas or {}
vim.list_extend(new_config.settings.json.schemas, require("schemastore").json.schemas())
end,
settings = {
json = {
format = {
enable = true,
},
validate = { enable = true },
},
},
},
lua_ls = {
settings = {
Lua = {
workspace = {
checkThirdParty = false,
},
codeLens = {
enable = true,
},
completion = {
callSnippet = "Replace",
},
},
},
},
ruff_lsp = {
keys = {
{
"<leader>co",
function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { "source.organizeImports" },
diagnostics = {},
},
})
end,
desc = "Organize Imports",
},
},
},
yamlls = {
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
},
},
on_new_config = function(new_config)
new_config.settings.yaml.schemas = vim.tbl_deep_extend(
"force",
new_config.settings.yaml.schemas or {},
require("schemastore").yaml.schemas()
)
end,
settings = {
redhat = { telemetry = { enabled = false } },
yaml = {
keyOrdering = false,
format = {
enable = true,
},
validate = true,
schemaStore = {
enable = false,
url = "",
},
},
},
},
}
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
M.lsp_setup = {
ruff_lsp = function()
LazyVim.lsp.on_attach(function(client, _)
if client.name == "ruff_lsp" then
client.server_capabilities.hoverProvider = false
client.server_capabilities.renameProvider = false
end
end)
end,
rust_analyzer = function()
return true
end,
["*"] = function(server, opts)
local base = vim.lsp.protocol.make_client_capabilities()
local cmp = require("cmp_nvim_lsp").default_capabilities()
vim.tbl_deep_extend("force", opts.capabilities, base)
vim.tbl_deep_extend("force", opts.capabilities, cmp)
require("lspconfig")[server].setup(opts)
end,
}
setmetatable(M, {
__index = function(_, k)
if k == "lsp" then
for l, _ in pairs(M.lsp) do
M.lsp[l].mason = false
return M.lsp
end
end
return require("custom." .. k)
end,
})
M.dap = {}
return M

View file

@ -1,51 +0,0 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
require("lazy").setup({
spec = {
{
"LazyVim/LazyVim",
import = "lazyvim.plugins",
},
{ import = "lazyvim.plugins.extras.coding.copilot" },
{ import = "lazyvim.plugins.extras.coding.mini-surround" },
{ import = "lazyvim.plugins.extras.ui.mini-indentscope" },
{ import = "lazyvim.plugins.extras.dap.core" },
-- { import = "lazyvim.plugins.extras.ui.edgy" },
{ import = "lazyvim.plugins.extras.editor.aerial" },
{ import = "lazyvim.plugins.extras.editor.leap" },
{ import = "lazyvim.plugins.extras.test.core" },
{ import = "plugins" },
},
defaults = {
lazy = true,
version = false,
},
install = { colorscheme = { "tokyonight" } },
checker = { enabled = true },
performance = {
rtp = {
disabled_plugins = {
"gzip",
-- "matchit",
"matchparen",
"netrwPlugin",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})

View file

@ -1,7 +1,5 @@
---@class config.ui
local M = {}
---@type Array<string>
M.banners = {
[[
@ -78,7 +76,6 @@ M.banners = {
]],
}
---@type Array<table>
M.buttons = {
-- {
-- action = LazyVim.telescope("files"),

View file

@ -1,23 +0,0 @@
return {
{
"echasnovski/mini.surround",
opts = {
custom_surroundings = {
B = {
input = { "{{ ().*() }}" },
output = { left = "{{ ", right = " }}" },
},
},
},
},
{
"echasnovski/mini.ai",
opts = {
custom_textobjects = {
B = {
require("mini.ai").gen_spec.pair("{{ ", " }}"),
},
},
},
},
}

View file

@ -1,5 +1,26 @@
---@type LazySpec
return {
{
"echasnovski/mini.surround",
opts = {
custom_surroundings = {
B = {
input = { "{{ ().*() }}" },
output = { left = "{{ ", right = " }}" },
},
},
},
},
{
"echasnovski/mini.ai",
opts = {
custom_textobjects = {
B = {
require("mini.ai").gen_spec.pair("{{ ", " }}"),
},
},
},
},
{
"ggandor/flit.nvim",
enabled = false,

View file

@ -1,232 +1,16 @@
---@type LazySpec
return {
{
"nvim-treesitter/nvim-treesitter",
opts = {
auto_install = true,
ensure_installed = Config.language.treesitter_install,
highlight = {
additional_vim_regex_highlighting = { "markdown" },
},
},
},
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = Config.language.formatters_by_ft,
formatters = Config.language.formatters,
},
},
{
"neovim/nvim-lspconfig",
opts = {
servers = Config.language.lsp,
setup = Config.language.lsp_setup,
},
},
{
"mfussenegger/nvim-lint",
opts = {
linters_by_ft = Config.language.linters_by_ft,
linters = Config.language.linters,
},
},
{
"williamboman/mason.nvim",
opts = {
ensure_installed = Config.language.mason_install,
},
},
{
"hrsh7th/nvim-cmp",
opts = function(_, opts)
table.insert(opts.auto_brackets, "python")
table.insert(opts.sources, { name = "crates" })
opts.experimental = {
ghost_text = false,
}
-- local cmp = require("cmp")
-- local luasnip = require("luasnip")
--
-- opts.preselect = cmp.PreselectMode.None
-- opts.snippet = {
-- expand = function(args)
-- require("luasnip").lsp_expand(args.body)
-- end,
-- }
-- opts.mapping = {
-- ["<Up>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
-- ["<Down>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
-- ["<C-Space>"] = cmp.mapping(function(fallback)
-- if cmp.visible() then
-- if luasnip.expandable() then
-- luasnip.expand()
-- else
-- cmp.confirm({
-- select = true,
-- })
-- end
-- else
-- fallback()
-- end
-- end),
--
-- ["<Tab>"] = cmp.mapping(function(fallback)
-- if cmp.visible() then
-- cmp.select_next_item()
-- elseif luasnip.locally_jumpable(1) then
-- luasnip.jump(1)
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
--
-- ["<S-Tab>"] = cmp.mapping(function(fallback)
-- if cmp.visible() then
-- cmp.select_prev_item()
-- elseif luasnip.locally_jumpable(-1) then
-- luasnip.jump(-1)
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
-- }
end,
},
{
"towolf/vim-helm",
ft = "helm",
},
{
"mfussenegger/nvim-ansible",
keys = {
{
"<leader>tr",
function()
require("ansible").run()
end,
silent = true,
},
},
{
"b0o/SchemaStore.nvim",
lazy = true,
version = false,
},
},
{
"iamcco/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
build = function()
vim.fn["mkdp#util#install"]()
end,
keys = {
{
"<leader>cp",
ft = "markdown",
"<cmd>MarkdownPreviewToggle<cr>",
desc = "Markdown Preview",
},
},
config = function()
vim.cmd([[do FileType]])
end,
},
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/neotest-python",
},
opts = function(_, opts)
local _, rt = pcall(require, "rustaceanvim.neotest")
opts.adapters = vim.tbl_deep_extend("force", opts.adapters, {
["neotest-python"] = {},
rt,
})
end,
},
{
"mfussenegger/nvim-dap-python",
-- stylua: ignore
keys = {
{ "<leader>dPt", function() require("dap-python").test_method() end, desc = "Debug Method", ft = "python" },
{ "<leader>dPc", function() require("dap-python").test_class() end, desc = "Debug Class", ft = "python" },
},
config = function()
local path = require("mason-registry").get_package("debugpy"):get_install_path()
require("dap-python").setup(path .. "/venv/bin/python")
end,
},
{
"linux-cultist/venv-selector.nvim",
cmd = "VenvSelect",
opts = function(_, opts)
if LazyVim.has("nvim-dap-python") then
opts.dap_enabled = true
end
return vim.tbl_deep_extend("force", opts, {
name = {
"venv",
".venv",
"env",
".env",
},
})
end,
keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
},
{
"Saecki/crates.nvim",
event = { "BufRead Cargo.toml" },
opts = {
src = {
cmp = { enabled = true },
},
},
},
{
"mrcjkb/rustaceanvim",
version = "^4",
ft = { "rust" },
opts = {
server = {
on_attach = function(_, bufnr)
vim.keymap.set("n", "<leader>cR", function()
vim.cmd.RustLsp("codeAction")
end, { desc = "Code Action", buffer = bufnr })
vim.keymap.set("n", "<leader>dr", function()
vim.cmd.RustLsp("debuggables")
end, { desc = "Rust Debuggables", buffer = bufnr })
end,
default_settings = {
["rust-analyzer"] = {
cargo = {
allFeatures = true,
loadOutDirsFromCheck = true,
runBuildScripts = true,
},
checkOnSave = {
allFeatures = true,
command = "clippy",
extraArgs = { "--no-deps" },
},
procMacro = {
enable = true,
ignored = {
["async-trait"] = { "async_trait" },
["napi-derive"] = { "napi" },
["async-recursion"] = { "async_recursion" },
},
},
servers = {
intelephense = {
init_options = {
storagePath = os.getenv("XDG_CACHE_HOME") .. "/intelephense",
globalStoragePath = os.getenv("XDG_CONFIG_HOME") .. "/intelephense",
licenceKey = require("lib").get_secret("intelephense"),
},
},
},
},
config = function(_, opts)
vim.g.rustaceanvim = vim.tbl_deep_extend("keep", vim.g.rustaceanvim or {}, opts or {})
end,
},
}