nvim: bootstrap minimal nix-first config
This commit is contained in:
parent
8a2e735875
commit
d90c74150f
14 changed files with 557 additions and 12 deletions
40
.config/nvim/lua/plugins/completion.lua
Normal file
40
.config/nvim/lua/plugins/completion.lua
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
return {
|
||||
{
|
||||
"saghen/blink.cmp",
|
||||
version = "*",
|
||||
opts = {
|
||||
keymap = {
|
||||
preset = "super-tab",
|
||||
},
|
||||
appearance = {
|
||||
nerd_font_variant = "mono",
|
||||
},
|
||||
completion = {
|
||||
accept = {
|
||||
auto_brackets = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
documentation = {
|
||||
auto_show = false,
|
||||
},
|
||||
ghost_text = {
|
||||
enabled = true,
|
||||
show_with_menu = false,
|
||||
},
|
||||
menu = {
|
||||
auto_show = false,
|
||||
},
|
||||
},
|
||||
signature = {
|
||||
enabled = true,
|
||||
},
|
||||
sources = {
|
||||
default = { "lsp", "path", "buffer" },
|
||||
},
|
||||
fuzzy = {
|
||||
implementation = "prefer_rust_with_warning",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
53
.config/nvim/lua/plugins/editor.lua
Normal file
53
.config/nvim/lua/plugins/editor.lua
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
return {
|
||||
{ "nvim-lua/plenary.nvim", lazy = true },
|
||||
|
||||
{
|
||||
"nvim-telescope/telescope.nvim",
|
||||
branch = "0.1.x",
|
||||
cmd = "Telescope",
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
},
|
||||
keys = {
|
||||
{ "<leader>ff", "<cmd>Telescope find_files<cr>", desc = "Find files" },
|
||||
{ "<leader>fg", "<cmd>Telescope live_grep<cr>", desc = "Live grep" },
|
||||
{ "<leader>fb", "<cmd>Telescope buffers<cr>", desc = "Buffers" },
|
||||
{ "<leader>fh", "<cmd>Telescope help_tags<cr>", desc = "Help tags" },
|
||||
{ "<leader>gc", "<cmd>Telescope git_commits<cr>", desc = "Git commits" },
|
||||
{ "<leader>gB", "<cmd>Telescope git_branches<cr>", desc = "Git branches" },
|
||||
{ "<leader>gs", "<cmd>Telescope git_status<cr>", desc = "Git status" },
|
||||
{ "<leader>gf", "<cmd>Telescope git_files<cr>", desc = "Git files" },
|
||||
},
|
||||
opts = {
|
||||
defaults = {
|
||||
sorting_strategy = "ascending",
|
||||
layout_config = {
|
||||
prompt_position = "top",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
event = { "BufReadPost", "BufNewFile" },
|
||||
build = ":TSUpdate",
|
||||
main = "nvim-treesitter",
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"bash",
|
||||
"lua",
|
||||
"luadoc",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"nix",
|
||||
"query",
|
||||
"vim",
|
||||
"vimdoc",
|
||||
},
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
},
|
||||
},
|
||||
}
|
||||
46
.config/nvim/lua/plugins/explorer.lua
Normal file
46
.config/nvim/lua/plugins/explorer.lua
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
return {
|
||||
{
|
||||
"stevearc/oil.nvim",
|
||||
cmd = "Oil",
|
||||
keys = {
|
||||
{
|
||||
"-",
|
||||
"<cmd>Oil<cr>",
|
||||
desc = "Open parent directory",
|
||||
},
|
||||
{
|
||||
"<leader>e",
|
||||
function()
|
||||
require("oil").toggle_float()
|
||||
end,
|
||||
desc = "Explorer (Oil)",
|
||||
},
|
||||
},
|
||||
dependencies = {
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
},
|
||||
opts = {
|
||||
default_file_explorer = true,
|
||||
columns = {
|
||||
"icon",
|
||||
},
|
||||
delete_to_trash = false,
|
||||
skip_confirm_for_simple_edits = true,
|
||||
view_options = {
|
||||
show_hidden = true,
|
||||
},
|
||||
float = {
|
||||
padding = 2,
|
||||
max_width = 90,
|
||||
max_height = 0,
|
||||
border = "rounded",
|
||||
},
|
||||
keymaps = {
|
||||
["<C-v>"] = { "actions.select", opts = { vertical = true } },
|
||||
["<C-s>"] = { "actions.select", opts = { horizontal = true } },
|
||||
["<C-p>"] = "actions.preview",
|
||||
["<Esc>"] = "actions.close",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
36
.config/nvim/lua/plugins/format.lua
Normal file
36
.config/nvim/lua/plugins/format.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
return {
|
||||
{
|
||||
"stevearc/conform.nvim",
|
||||
event = { "BufWritePre" },
|
||||
cmd = { "ConformInfo" },
|
||||
keys = {
|
||||
{
|
||||
"<leader>cf",
|
||||
function()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end,
|
||||
mode = { "n", "v" },
|
||||
desc = "Format buffer",
|
||||
},
|
||||
},
|
||||
opts = {
|
||||
notify_on_error = false,
|
||||
format_on_save = function()
|
||||
return {
|
||||
timeout_ms = 1000,
|
||||
lsp_fallback = true,
|
||||
}
|
||||
end,
|
||||
formatters_by_ft = {
|
||||
lua = { "stylua" },
|
||||
nix = { "alejandra", "nixfmt" },
|
||||
sh = { "shfmt" },
|
||||
bash = { "shfmt" },
|
||||
zsh = { "shfmt" },
|
||||
json = { "prettierd", "prettier" },
|
||||
yaml = { "prettierd", "prettier" },
|
||||
markdown = { "prettierd", "prettier" },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
23
.config/nvim/lua/plugins/lint.lua
Normal file
23
.config/nvim/lua/plugins/lint.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
return {
|
||||
{
|
||||
"mfussenegger/nvim-lint",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
config = function()
|
||||
local lint = require("lint")
|
||||
|
||||
lint.linters_by_ft = {
|
||||
sh = { "shellcheck" },
|
||||
bash = { "shellcheck" },
|
||||
zsh = { "shellcheck" },
|
||||
}
|
||||
|
||||
local group = vim.api.nvim_create_augroup("user-lint", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
||||
group = group,
|
||||
callback = function()
|
||||
lint.try_lint()
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
158
.config/nvim/lua/plugins/lsp.lua
Normal file
158
.config/nvim/lua/plugins/lsp.lua
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
return {
|
||||
{
|
||||
"folke/lazydev.nvim",
|
||||
ft = "lua",
|
||||
opts = {
|
||||
library = {
|
||||
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
config = function()
|
||||
-- Nix-first workflow:
|
||||
-- - install language servers with nix profile / flake / devShell
|
||||
-- - start Neovim from a direnv-loaded shell
|
||||
-- - Neovim uses server binaries from PATH only
|
||||
local lspconfig = require("lspconfig")
|
||||
local util = require("lspconfig.util")
|
||||
|
||||
vim.diagnostic.config({
|
||||
severity_sort = true,
|
||||
virtual_text = {
|
||||
spacing = 2,
|
||||
source = "if_many",
|
||||
},
|
||||
float = { border = "rounded" },
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("user-lsp-attach", { clear = true }),
|
||||
callback = function(event)
|
||||
local map = function(keys, func, desc)
|
||||
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = desc })
|
||||
end
|
||||
|
||||
map("gd", vim.lsp.buf.definition, "Goto definition")
|
||||
map("gD", vim.lsp.buf.declaration, "Goto declaration")
|
||||
map("gr", vim.lsp.buf.references, "Goto references")
|
||||
map("gi", vim.lsp.buf.implementation, "Goto implementation")
|
||||
map("K", vim.lsp.buf.hover, "Hover")
|
||||
map("<leader>rn", vim.lsp.buf.rename, "Rename")
|
||||
map("<leader>ca", vim.lsp.buf.code_action, "Code action")
|
||||
map("<leader>cd", vim.diagnostic.open_float, "Line diagnostics")
|
||||
|
||||
if vim.lsp.inlay_hint then
|
||||
map("<leader>uh", function()
|
||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }), { bufnr = event.buf })
|
||||
end, "Toggle inlay hints")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
local ok_blink, blink = pcall(require, "blink.cmp")
|
||||
if ok_blink then
|
||||
capabilities = blink.get_lsp_capabilities(capabilities)
|
||||
end
|
||||
|
||||
local missing = {}
|
||||
|
||||
local function setup(server, bin, config)
|
||||
config = config or {}
|
||||
config.capabilities = vim.tbl_deep_extend("force", capabilities, config.capabilities or {})
|
||||
|
||||
if vim.fn.executable(bin) ~= 1 then
|
||||
table.insert(missing, string.format("%s (%s)", server, bin))
|
||||
return
|
||||
end
|
||||
|
||||
lspconfig[server].setup(config)
|
||||
end
|
||||
|
||||
setup("lua_ls", "lua-language-server", {
|
||||
cmd = { "lua-language-server" },
|
||||
settings = {
|
||||
Lua = {
|
||||
completion = { callSnippet = "Replace" },
|
||||
diagnostics = { globals = { "vim" } },
|
||||
telemetry = { enable = false },
|
||||
workspace = { checkThirdParty = false },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
setup("nixd", "nixd", {
|
||||
cmd = { "nixd" },
|
||||
})
|
||||
|
||||
setup("bashls", "bash-language-server", {
|
||||
cmd = { "bash-language-server", "start" },
|
||||
})
|
||||
|
||||
setup("marksman", "marksman", {
|
||||
cmd = { "marksman", "server" },
|
||||
})
|
||||
|
||||
setup("ts_ls", "typescript-language-server", {
|
||||
cmd = { "typescript-language-server", "--stdio" },
|
||||
root_dir = util.root_pattern("tsconfig.json", "jsconfig.json", "package.json", ".git"),
|
||||
single_file_support = false,
|
||||
})
|
||||
|
||||
setup("gopls", "gopls", {
|
||||
cmd = { "gopls" },
|
||||
settings = {
|
||||
gopls = {
|
||||
gofumpt = true,
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
setup("rust_analyzer", "rust-analyzer", {
|
||||
cmd = { "rust-analyzer" },
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
cargo = {
|
||||
allFeatures = true,
|
||||
},
|
||||
checkOnSave = {
|
||||
command = "clippy",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
setup("pyright", "pyright-langserver", {
|
||||
cmd = { "pyright-langserver", "--stdio" },
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
diagnosticMode = "workspace",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if #missing > 0 and #vim.api.nvim_list_uis() > 0 then
|
||||
vim.schedule(function()
|
||||
vim.notify(
|
||||
"LSP not on PATH (install with Nix):\n- " .. table.concat(missing, "\n- "),
|
||||
vim.log.levels.INFO,
|
||||
{ title = "nvim-lspconfig" }
|
||||
)
|
||||
end)
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
41
.config/nvim/lua/plugins/statusline.lua
Normal file
41
.config/nvim/lua/plugins/statusline.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
return {
|
||||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
event = "VeryLazy",
|
||||
dependencies = {
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
},
|
||||
opts = {
|
||||
options = {
|
||||
theme = "catppuccin",
|
||||
globalstatus = true,
|
||||
section_separators = "",
|
||||
component_separators = "│",
|
||||
disabled_filetypes = {
|
||||
statusline = { "oil" },
|
||||
},
|
||||
},
|
||||
sections = {
|
||||
lualine_a = { "mode" },
|
||||
lualine_b = { "branch", "diff", "diagnostics" },
|
||||
lualine_c = {
|
||||
{
|
||||
"filename",
|
||||
path = 1,
|
||||
},
|
||||
},
|
||||
lualine_x = {
|
||||
{
|
||||
"lsp_status",
|
||||
ignore_lsp = { "copilot" },
|
||||
},
|
||||
"encoding",
|
||||
"filetype",
|
||||
},
|
||||
lualine_y = { "progress" },
|
||||
lualine_z = { "location" },
|
||||
},
|
||||
extensions = { "quickfix", "lazy" },
|
||||
},
|
||||
},
|
||||
}
|
||||
58
.config/nvim/lua/plugins/ui.lua
Normal file
58
.config/nvim/lua/plugins/ui.lua
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
return {
|
||||
{
|
||||
"catppuccin/nvim",
|
||||
name = "catppuccin",
|
||||
lazy = false,
|
||||
priority = 1000,
|
||||
opts = {
|
||||
flavour = "mocha",
|
||||
integrations = {
|
||||
gitsigns = true,
|
||||
telescope = true,
|
||||
which_key = true,
|
||||
cmp = true,
|
||||
treesitter = true,
|
||||
native_lsp = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("catppuccin").setup(opts)
|
||||
vim.cmd.colorscheme("catppuccin")
|
||||
end,
|
||||
},
|
||||
|
||||
{ "nvim-tree/nvim-web-devicons", lazy = true },
|
||||
|
||||
{
|
||||
"folke/which-key.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {},
|
||||
},
|
||||
|
||||
{
|
||||
"lewis6991/gitsigns.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
opts = {
|
||||
on_attach = function(buffer)
|
||||
local gs = package.loaded.gitsigns
|
||||
local map = function(mode, lhs, rhs, desc)
|
||||
vim.keymap.set(mode, lhs, rhs, { buffer = buffer, desc = desc })
|
||||
end
|
||||
|
||||
map("n", "]h", gs.next_hunk, "Next hunk")
|
||||
map("n", "[h", gs.prev_hunk, "Previous hunk")
|
||||
map("n", "<leader>gp", gs.preview_hunk, "Preview hunk")
|
||||
map("n", "<leader>gr", gs.reset_hunk, "Reset hunk")
|
||||
map("n", "<leader>gb", gs.blame_line, "Blame line")
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"numToStr/Comment.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {},
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue