refactor: extract neovim config

This commit is contained in:
mandlm 2024-07-10 12:52:58 +02:00
parent f73b6206cd
commit 35550c6085
Signed by: mandlm
GPG Key ID: 088ED38F036C7AF2
45 changed files with 6 additions and 696 deletions

View File

@ -24,6 +24,7 @@
../eza.nix
../fzf.nix
../git.nix
../neovim
../picocom.nix
../podman.nix
../ripgrep.nix
@ -33,7 +34,6 @@
../tree.nix
../zoxide.nix
./gpg
./neovim
./ssh.nix
./zsh.nix
];

View File

@ -1,18 +1,15 @@
{ pkgs, theme, ... }:
let
pkg_src = pkgs;
in
{
# symlink for a stable path
home.file.".vscode-extensions/vscode-lldb".source = pkg_src.vscode-extensions.vadimcn.vscode-lldb;
home.file.".vscode-extensions/vscode-lldb".source = pkgs.vscode-extensions.vadimcn.vscode-lldb;
programs = {
neovim = {
enable = true;
package = pkg_src.neovim-unwrapped;
package = pkgs.neovim-unwrapped;
defaultEditor = true;
plugins = with pkg_src.vimPlugins; [
plugins = with pkgs.vimPlugins; [
# theme
nvim-solarized-lua
@ -93,7 +90,7 @@ in
withNodeJs = true;
extraPackages = with pkg_src; [
extraPackages = with pkgs; [
# language servers
lua-language-server
terraform-ls

View File

@ -62,6 +62,7 @@
../fzf.nix
../git.nix
../kitty.nix
../neovim
../nextcloud.nix
../ripgrep.nix
../shell_aliases.nix
@ -70,7 +71,6 @@
../tree.nix
../zoxide.nix
./gpg
./neovim
./zsh.nix
];
}

View File

@ -1,3 +0,0 @@
require("auto-session").setup {
log_level = "error",
}

View File

@ -1 +0,0 @@
vim.api.nvim_create_user_command("BufOnly", "%bd|e#|bd#", {})

View File

@ -1 +0,0 @@
require('Comment').setup({})

View File

@ -1,35 +0,0 @@
local dap = require("dap")
local dapui = require("dapui")
dapui.setup()
vim.fn.sign_define("DapBreakpoint", { text = "🔴", texthl = "", linehl = "", numhl = "" })
-- debugging keymaps
vim.keymap.set("n", "<F5>", dap.continue, { noremap = true, silent = true })
vim.keymap.set("n", "<F9>", dap.toggle_breakpoint, { noremap = true, silent = true })
vim.keymap.set("n", "<F10>", dap.step_over, { noremap = true, silent = true })
vim.keymap.set("n", "<F11>", dap.step_into, { noremap = true, silent = true })
vim.keymap.set("n", "<S-F11>", dap.step_out, { noremap = true, silent = true })
vim.keymap.set("n", "<F23>", dap.step_out, { noremap = true, silent = true }) -- <Shift-F11> in kitty
vim.keymap.set("n", "<M-k>", dapui.eval, { noremap = true, silent = true })
-- trigger auto-completion in repl
vim.cmd([[
augroup TriggerDapReplAutoCompletion
autocmd!
autocmd FileType dap-repl lua require("dap.ext.autocompl").attach()
augroup END
]])
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end

View File

@ -1,167 +0,0 @@
{ pkgs, theme, ... }:
{
# symlink for a stable path
home.file.".vscode-extensions/vscode-lldb".source = pkgs.vscode-extensions.vadimcn.vscode-lldb;
programs = {
neovim = {
enable = true;
package = pkgs.neovim-unwrapped;
defaultEditor = true;
plugins = with pkgs.vimPlugins; [
# theme
nvim-solarized-lua
delimitMate
vim-bbye
ansible-vim
# ui
dressing-nvim
# session handling
project-nvim
auto-session
# escape handling
better-escape-nvim
nvim-treesitter.withAllGrammars
markdown-preview-nvim # use({ "iamcco/markdown-preview.nvim", run = ":call mkdp#util#install()" })
toggleterm-nvim
nvim-notify
comment-nvim
lualine-nvim
tabline-nvim
indent-blankline-nvim
plenary-nvim
vim-illuminate
registers-nvim
vim-surround
editorconfig-nvim
# git
gitsigns-nvim
vim-fugitive
vim-flog
git-blame-nvim
nvim-web-devicons # used by diffview-nvim
# snippets
friendly-snippets
luasnip
# auto-completion
nvim-cmp
cmp-nvim-lsp
cmp-buffer
cmp-path
cmp-cmdline
cmp-nvim-lua
cmp_luasnip
cmp-calc
cmp-nvim-lsp-signature-help
# telescope
telescope-nvim
telescope-fzf-native-nvim
telescope-ui-select-nvim
# LSP
nvim-lspconfig
lsp-status-nvim
rustaceanvim
neodev-nvim
null-ls-nvim
lsp_lines-nvim
lsp-inlayhints-nvim
# debugging
nvim-dap
nvim-dap-ui
# neorg
neorg
neorg-telescope
];
withNodeJs = true;
extraPackages = with pkgs; [
# language servers
lua-language-server
terraform-ls
tflint
bash-language-server
nodePackages.dockerfile-language-server-nodejs
nodePackages.eslint_d
nodePackages.prettier
nodePackages.typescript
nodePackages.typescript-language-server
nodePackages.vscode-langservers-extracted
nodePackages.yaml-language-server
lldb
vscode-extensions.vadimcn.vscode-lldb
marksman
clang-tools
cmake-language-server
texlab
nixd
nixpkgs-fmt
];
extraLuaPackages = luaPackages: [
luaPackages.lua-utils-nvim
luaPackages.pathlib-nvim
];
extraConfig = ''
lua << EOF
vim.o.guifont = "DejaVu Sans Mono:h10"
if vim.g.neovide then
vim.g.neovide_fullscreen = true
vim.g.neovide_cursor_animation_length = 0.01
vim.g.neovide_cursor_trail_length = 0.01
end
${builtins.readFile ./keymaps.lua }
${builtins.readFile ./options.lua }
${builtins.readFile ./commands.lua }
${builtins.readFile ./treesitter.lua }
${builtins.readFile ./lspconfig.lua }
${builtins.readFile ./auto-session.lua }
${builtins.readFile ./toggleterm.lua }
${builtins.readFile ./notify.lua }
${builtins.readFile ./comment.lua }
${builtins.readFile ./lualine.lua }
${builtins.readFile ./tabline.lua }
${builtins.readFile ./indent-blankline.lua }
${builtins.readFile ./gitsigns.lua }
${builtins.readFile ./luasnip.lua }
${builtins.readFile ./nvim-cmp.lua }
${builtins.readFile ./telescope.lua }
${builtins.readFile ./themes.lua }
vim.opt.background = '${theme}'
${builtins.readFile ./project-nvim.lua }
${builtins.readFile ./dap.lua }
${builtins.readFile ./neorg.lua }
vim.g.gitblame_date_format = "%r"
-- setup illuminate highlight groups
vim.api.nvim_set_hl(0, "IlluminatedWordText", { bold = true })
vim.api.nvim_set_hl(0, "IlluminatedWordRead", { link = "IlluminatedWordText" })
vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { link = "IlluminatedWordText" })
EOF
'';
};
};
}

View File

@ -1 +0,0 @@
require('gitsigns').setup()

View File

@ -1,5 +0,0 @@
require("ibl").setup {
indent = {
char = "",
},
}

View File

@ -1,69 +0,0 @@
local function nnoremap(key, command)
vim.api.nvim_set_keymap("n", key, command, { noremap = true })
end
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Move around windows
nnoremap("<C-h>", ":wincmd h<CR>")
nnoremap("<C-j>", ":wincmd j<CR>")
nnoremap("<C-k>", ":wincmd k<CR>")
nnoremap("<C-l>", ":wincmd l<CR>")
-- Switch buffers
nnoremap("<C-PageDown>", ":TablineBufferNext<CR>")
nnoremap("<C-PageUp>", ":TablineBufferPrevious<CR>")
-- fugitive
nnoremap("<leader>g", ":0Git<CR>")
-- vim-flog
nnoremap("<leader>G", ":Flog -all -date=relative -open-cmd=new<CR>")
-- telescope
local telescope = require("telescope.builtin")
local telescope_themes = require("telescope.themes")
local telescope_projects = require("telescope").extensions.projects
local function map_telescope(key, telescope_function)
vim.api.nvim_set_keymap("n", key, "", {
noremap = true,
callback = function()
local theme = telescope_themes.get_dropdown({ layout_config = { width = 0.9 } })
telescope_function(theme)
end,
})
end
map_telescope("<leader>ff", telescope.find_files)
map_telescope("<leader>fb", telescope.buffers)
map_telescope("<leader>fg", telescope.git_files)
map_telescope("<leader>fp", telescope_projects.projects)
map_telescope("<leader>fs", telescope.lsp_document_symbols)
map_telescope("<leader>fS", telescope.lsp_dynamic_workspace_symbols)
map_telescope("<C-f>", telescope.grep_string)
map_telescope("<C-g>", telescope.live_grep)
-- terminal
vim.api.nvim_create_autocmd("TermOpen", {
pattern = "term://*",
callback = function()
local opts = { noremap = true }
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-h>', [[<C-\><C-n><C-W>h]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-j>', [[<C-\><C-n><C-W>j]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-k>', [[<C-\><C-n><C-W>k]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-l>', [[<C-\><C-n><C-W>l]], opts)
end,
desc = "Map terminal esc and window switch keys",
})
-- buffer closing
nnoremap("gq", ":Bdelete<CR>")
-- toggle search highlighting
vim.cmd('nnoremap <expr> * v:hlsearch ? ":nohlsearch<cr>" : "*"')
-- insert-map jj/jk to escape
require("better_escape").setup()

View File

@ -1,184 +0,0 @@
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local on_attach = function(client, bufnr)
local function nnoremap(key, command)
vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr })
end
local function format_buffer()
vim.lsp.buf.format({
timeout_ms = 3000,
async = false,
filter = function(formatter)
return formatter.name ~= "tsserver" and formatter.name ~= "volar"
end
})
end
require("lsp-inlayhints").on_attach(client, bufnr)
local telescope = require("telescope.builtin")
nnoremap("gD", vim.lsp.buf.declaration)
nnoremap("gd", telescope.lsp_definitions)
nnoremap("gt", telescope.lsp_type_definitions)
nnoremap("gi", telescope.lsp_implementations)
nnoremap("gr", telescope.lsp_references)
nnoremap("K", vim.lsp.buf.hover)
nnoremap("<leader>rn", vim.lsp.buf.rename)
nnoremap("<leader>ca", vim.lsp.buf.code_action)
nnoremap("<leader>f", format_buffer)
nnoremap("<leader>d", telescope.diagnostics)
nnoremap("<leader>D", require("lsp_lines").toggle)
nnoremap("<C-p>", vim.diagnostic.goto_prev)
nnoremap("<C-n>", vim.diagnostic.goto_next)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = format_buffer,
})
end
end
require("lsp-inlayhints").setup({})
local lsp_status = require("lsp-status")
lsp_status.config({
current_function = false,
show_filename = false,
diagnostics = true,
status_symbol = "",
})
lsp_status.register_progress()
-- setup lua language server for init.nvim and nvim plugin development
require("neodev").setup({
override = function(root_dir, options)
if require("neodev.util").has_file(root_dir, "/etc/nixos") then
options.enabled = true
options.plugins = true
end
end,
})
local capabilities = require("cmp_nvim_lsp").default_capabilities(lsp_status.capabilities)
local servers = {
["bashls"] = {},
["clangd"] = {},
["cmake"] = {},
["dockerls"] = {},
["eslint"] = {},
["html"] = {},
["jsonls"] = {},
["lua_ls"] = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
},
["marksman"] = {},
["nixd"] = {},
["pylsp"] = {
pylsp = {
plugins = {
pycodestyle = {
maxLineLength = 120
}
}
}
},
["pyright"] = {},
["terraformls"] = {},
["texlab"] = {},
["tflint"] = {},
["tsserver"] = {},
["yamlls"] = {
yaml = {
keyOrdering = false
}
},
}
local lspconfig = require("lspconfig")
for lsp, settings in pairs(servers) do
lspconfig[lsp].setup({
settings = settings,
on_attach = on_attach,
capabilities = capabilities,
})
end
-- setup rustaceanvim
vim.g.rustaceanvim = {
server = {
on_attach = on_attach,
settings = {
["rust-analyzer"] = {
cargo = {
loadOutDirsFromCheck = true,
},
checkOnSave = { command = "clippy" },
procMacro = {
enable = true,
},
},
},
},
}
-- setup null-ls for markdown formatting
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.prettier,
null_ls.builtins.diagnostics.tsc,
},
on_attach = on_attach,
})
-- setup lsp_lines
require("lsp_lines").setup()
-- setup vim diagnostics
vim.diagnostic.config({
virtual_text = false,
signs = true,
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
border = "rounded",
source = "always",
header = "",
prefix = "",
},
})
-- setup diagnostics signs
local diagnostics_signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(diagnostics_signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
-- setup volar
lspconfig["volar"].setup({
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' },
on_attach = on_attach,
capabilities = capabilities,
})

View File

@ -1,7 +0,0 @@
require('lualine').setup({
options = { globalstatus = true },
sections = {
lualine_c = { { "filename", path = 1 }, "require('lsp-status').status()" }
},
extensions = { "toggleterm" }
})

View File

@ -1 +0,0 @@
require("luasnip.loaders.from_vscode").lazy_load()

View File

@ -1,16 +0,0 @@
local neorg = require("neorg")
neorg.setup({
load = {
["core.defaults"] = {},
["core.concealer"] = {},
["core.dirman"] = {
config = {
workspaces = {
notes = "~/notes",
},
default_workspace = "notes",
},
},
}
})

View File

@ -1,2 +0,0 @@
require("notify").setup({ stages = "fade" })
vim.notify = require("notify")

View File

@ -1,87 +0,0 @@
local has_words_before = function()
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
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "nvim_lsp_signature_help" },
{ name = "luasnip" },
{ name = "path" },
{ name = "buffer" },
{ name = "nvim-lua" },
{ name = "calc" },
}),
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.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
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" }),
}),
experimental = { ghost_text = true },
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = { "menu", "abbr", "kind" },
format = function(entry, item)
local menu_icon = {
nvim_lsp = "λ",
luasnip = "",
buffer = "Ω",
path = "🖿",
}
item.menu = menu_icon[entry.source.name]
return item
end,
},
})
-- `/` cmdline setup.
cmp.setup.cmdline("/", {
sources = cmp.config.sources(
{ name = "buffer" }
)
})
-- `:` cmdline setup.
cmp.setup.cmdline(":", {
sources = cmp.config.sources(
{ name = "path" },
{ name = "cmdline" }
)
})

View File

@ -1,61 +0,0 @@
-- termguicolors
vim.opt.termguicolors = true
-- line numbers
vim.opt.number = true
-- tabwidth
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
-- indent with spaces
vim.opt.expandtab = true
-- scroll offset
vim.opt.scrolloff = 4
-- don't warp lines
vim.opt.wrap = false
-- split to right/below
vim.opt.splitright = true
vim.opt.splitbelow = true
-- presistent undo
vim.opt.undofile = true
-- searching
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- preview commands
vim.opt.inccommand = "split"
-- completion
vim.opt.completeopt = "menu,menuone,noselect"
-- folding
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
vim.opt.foldlevelstart = 99
-- disable mouse
vim.opt.mouse = ""
-- set cursorline in active window
vim.cmd([[
augroup CursorLine
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
]])
-- configure terminal
vim.cmd([[
augroup terminal_setup
autocmd!
autocmd TermOpen * startinsert
autocmd TermOpen * setlocal nonumber norelativenumber
augroup END
]])

View File

@ -1 +0,0 @@
require('project_nvim').setup({})

View File

@ -1 +0,0 @@
require('tabline').setup({ enable = true, options = { show_bufnr = true, show_filename_only = true } })

View File

@ -1,29 +0,0 @@
local telescope = require("telescope")
local actions = require("telescope.actions")
local themes = require("telescope.themes")
telescope.setup({
defaults = {
mappings = {
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<ESC>"] = actions.close,
["<C-c>"] = actions.close
},
n = {
["<ESC>"] = actions.close,
["<C-c>"] = actions.close
}
}
},
extensions = {
["ui-select"] = {
themes.get_dropdown({})
},
}
})
telescope.load_extension("fzf")
telescope.load_extension("ui-select")
telescope.load_extension("projects")

View File

@ -1 +0,0 @@
vim.cmd("colorscheme solarized")

View File

@ -1 +0,0 @@
require("toggleterm").setup({ size = 32, open_mapping = [[<F4>]] })

View File

@ -1,14 +0,0 @@
require('nvim-treesitter.configs').setup({
highlight = {
enable = true,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "v",
node_decremental = "<",
node_incremental = ">",
scope_incremental = false,
},
},
})