diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2025-03-02 17:47:10 -0500 |
|---|---|---|
| committer | Stefan Weigl-Bosker <stefan@s00.xyz> | 2025-03-02 17:47:10 -0500 |
| commit | 3fb87c7b8b2377a2cfc0f6e2b858a5b4f96f49d6 (patch) | |
| tree | 7efef9eec4b626cbcfd1d1396cb6dee4c73c7783 /modules/neovim | |
| parent | b5e3e6f12b41a9a1133744e139c5aa47d1bee006 (diff) | |
| download | home-3fb87c7b8b2377a2cfc0f6e2b858a5b4f96f49d6.tar.gz | |
update
Diffstat (limited to 'modules/neovim')
| -rw-r--r-- | modules/neovim/default.nix | 36 | ||||
| -rw-r--r-- | modules/neovim/lsp.lua | 57 | ||||
| -rw-r--r-- | modules/neovim/nvim/after/ftplugin/lua.lua | 2 | ||||
| -rw-r--r-- | modules/neovim/nvim/after/ftplugin/nix.lua | 2 | ||||
| -rw-r--r-- | modules/neovim/nvim/init.lua | 4 | ||||
| -rw-r--r-- | modules/neovim/nvim/lua/config/colorscheme.lua (renamed from modules/neovim/settings.lua) | 23 | ||||
| -rw-r--r-- | modules/neovim/nvim/lua/config/keybinds.lua (renamed from modules/neovim/keybinds.lua) | 15 | ||||
| -rw-r--r-- | modules/neovim/nvim/lua/config/lsp.lua | 55 | ||||
| -rw-r--r-- | modules/neovim/nvim/lua/config/settings.lua | 21 | ||||
| -rw-r--r-- | modules/neovim/terminal.lua | 7 |
10 files changed, 105 insertions, 117 deletions
diff --git a/modules/neovim/default.nix b/modules/neovim/default.nix index ce1e6e0..971e2f3 100644 --- a/modules/neovim/default.nix +++ b/modules/neovim/default.nix @@ -1,50 +1,48 @@ { config, lib, pkgs, ...}: let cfg = config.modules.neovim; - lua = str: "lua << EOF\n${str}\nEOF\n"; - luaImport = file: "lua << EOF\n${builtins.readFile file}\nEOF\n"; in { options.modules.neovim = { - enable = lib.mkEnableOption "neovim"; + enable = lib.mkEnableOption "neovim"; }; - config = { - programs.neovim = lib.mkIf cfg.enable { + config = lib.mkIf cfg.enable { + xdg.configFile."nvim/lua" = { + source = ./nvim/lua; + recursive = true; + }; + + xdg.configFile."nvim/after" = { + source = ./nvim/after; + recursive = true; + }; + + programs.neovim = { enable = true; defaultEditor = true; viAlias = true; vimAlias = true; vimdiffAlias = true; plugins = with pkgs.vimPlugins; [ - { - plugin = nvim-lspconfig; - config = let - servers = [ - { name = "clangd"; } - { name = "zls"; } - ]; - in lua (pkgs.lib.strings.concatStrings (pkgs.lib.lists.forEach servers (s: "require('lspconfig')['${s.name}'].setup(${s.config or "{}"})\n"))); - } - (nvim-treesitter.withPlugins (p: with p; [ tree-sitter-nix tree-sitter-c + tree-sitter-cpp tree-sitter-lua tree-sitter-zig tree-sitter-markdown tree-sitter-markdown-inline ])) + blink-cmp + nvim-lspconfig base16-nvim telescope-nvim telescope-fzf-native-nvim ]; extraLuaConfig = '' - ${builtins.readFile ./settings.lua} - ${builtins.readFile ./keybinds.lua} - ${builtins.readFile ./lsp.lua} - ${builtins.readFile ./terminal.lua} + ${builtins.readFile ./nvim/init.lua} ''; }; }; diff --git a/modules/neovim/lsp.lua b/modules/neovim/lsp.lua deleted file mode 100644 index ad6cddf..0000000 --- a/modules/neovim/lsp.lua +++ /dev/null @@ -1,57 +0,0 @@ --- builtin neovim lsp configuration -vim.opt.cot = "menu,menuone,noselect" ---vim.opt.cot = "menu,menuone" - -local methods = vim.lsp.protocol.Methods -local map = vim.keymap.set - --- hook that makes every floating window opened by nvim lsp rounded -local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview -function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) - opts = opts or {} - opts.border = opts.border or "rounded" - return orig_util_open_floating_preview(contents, syntax, opts, ...) -end - -vim.diagnostic.config({ --- virtual_text = { prefix = "", virt_text_pos = "eol_right_align", }, - virtual_text = false, - float = { border = "rounded" }, - signs = false, - underline = true, - update_in_insert = false, - float = true, - jump = { float = true } -}) - -local function pumvisible() - return tonumber(vim.fn.pumvisible()) ~= 0 -end - -vim.api.nvim_create_autocmd("LspAttach", { callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - --- fun but gets annoying --- if client:supports_method(methods.textDocument_inlayHint) then --- vim.lsp.inlay_hint.enable() --- end - - map('n', 'E', '<cmd>lua vim.lsp.buf.hover()<CR>', { silent = true }) - - if client:supports_method(methods.textDocument_completion) then - vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = false }) - vim.keymap.set('i', '<C-n>', function() - return pumvisible() and '<C-n>' or vim.lsp.completion.trigger() - end) - end - --- autoformat on save - if client:supports_method(methods.textDocument_formatting) then - vim.api.nvim_create_autocmd("BufWritePre", { - buffer = args.buf, - callback = function() - vim.lsp.buf.format({bufnr = args.buf, id = client_id}) - end - }) - end -end}) diff --git a/modules/neovim/nvim/after/ftplugin/lua.lua b/modules/neovim/nvim/after/ftplugin/lua.lua new file mode 100644 index 0000000..2d48451 --- /dev/null +++ b/modules/neovim/nvim/after/ftplugin/lua.lua @@ -0,0 +1,2 @@ +vim.o.tabstop=2 +vim.o.shiftwidth=2 diff --git a/modules/neovim/nvim/after/ftplugin/nix.lua b/modules/neovim/nvim/after/ftplugin/nix.lua new file mode 100644 index 0000000..2d48451 --- /dev/null +++ b/modules/neovim/nvim/after/ftplugin/nix.lua @@ -0,0 +1,2 @@ +vim.o.tabstop=2 +vim.o.shiftwidth=2 diff --git a/modules/neovim/nvim/init.lua b/modules/neovim/nvim/init.lua new file mode 100644 index 0000000..f2f8cff --- /dev/null +++ b/modules/neovim/nvim/init.lua @@ -0,0 +1,4 @@ +require("config.settings") +require("config.keybinds") +require("config.colorscheme") +require("config.lsp") diff --git a/modules/neovim/settings.lua b/modules/neovim/nvim/lua/config/colorscheme.lua index 816757c..0636088 100644 --- a/modules/neovim/settings.lua +++ b/modules/neovim/nvim/lua/config/colorscheme.lua @@ -1,25 +1,3 @@ -vim.g.mapleader = ' ' - -vim.o.number = true -vim.o.relativenumber = true -vim.o.splitright = true -vim.o.splitbelow = true -vim.o.scrolloff = 15 -vim.o.wrap = false -vim.o.lbr = true -vim.o.shortmess = vim.o.shortmess .. "I" -vim.o.termguicolors = true -vim.opt.fillchars = {eob = " "} ---vim.o.smd = false ---vim.opt.laststatus = 3 -vim.opt.pumheight = 6 -vim.opt.shiftwidth = 8 -vim.opt.tabstop = 8 -vim.opt.expandtab = true -vim.o.mouse="" -vim.o.guicursor="" -vim.o.swapfile=false - vim.cmd[[ colorscheme base16-mountain hi LineNr guifg=#ceb188 @@ -28,6 +6,7 @@ vim.cmd[[ hi CursorLineNr guifg=#ceb188 guibg=#191919 gui=bold hi FloatBorder guifg=#4c4c4c hi Pmenu guibg=#0d0d0d + hi BlinkCmpMenuBorder guifg=#4c4c4c hi PmenuSel guibg=#191919 guifg=#cacaca hi WinBar guifg=#4c4c4c hi WinSeparator guifg=#191919 diff --git a/modules/neovim/keybinds.lua b/modules/neovim/nvim/lua/config/keybinds.lua index 3f848b5..690a4d8 100644 --- a/modules/neovim/keybinds.lua +++ b/modules/neovim/nvim/lua/config/keybinds.lua @@ -5,7 +5,7 @@ local function nmap(lhs, rhs, opts) end local function swap(mode, bind1, bind2) - local tmp=bind1 + local tmp=bind1 map(mode, bind1, bind2) map(mode, bind2, tmp) end @@ -29,8 +29,8 @@ nmap('<leader>tc', ':tabc<CR>', { desc = "Close the current tab" }) nmap('<leader>tm', ':tabp<CR>', { desc = "Go to previous tab" }) nmap('<leader>ti', ':tabn<CR>', { desc = "Go to next tab" }) -nmap('<leader>wv', ':vne<CR>', { desc = "Create vertical split" }) -nmap('<leader>wh', ':new<CR>', { desc = "Create horizontal split" }) +nmap('<leader>wh', ':vne<CR>', { desc = "Create vertical split" }) +nmap('<leader>wv', ':new<CR>', { desc = "Create horizontal split" }) nmap('<leader>wc', ':clo<CR>', { desc = "Close current window" }) nmap('<leader>wm', '<C-w><C-h>', { desc = "Focus window left of the current one" }) @@ -42,12 +42,3 @@ nmap('<leader>fo', '<cmd>Telescope find_files<CR>', { silent = true }) nmap('<leader>?', '<cmd>Telescope live_grep<CR>', { silent = true }) nmap('<leader>to', '<cmd>te<CR>', { silent = true; desc = "Open a terminal buffer in the current window." }) - -map('n', 'grr', function() - vim.lsp.buf.references() -end, { desc = "Code references (LSP)" }) - -map('n', 'gd', function() - vim.lsp.buf.definition() -end, { desc = "Goto definition (LSP)" }) - diff --git a/modules/neovim/nvim/lua/config/lsp.lua b/modules/neovim/nvim/lua/config/lsp.lua new file mode 100644 index 0000000..62caa5d --- /dev/null +++ b/modules/neovim/nvim/lua/config/lsp.lua @@ -0,0 +1,55 @@ +local servers = { + clangd = {}, + zls = {} +} + +require('blink.cmp').setup({ + keymap = { + preset = 'default', + ['<C-n>'] = { function(cmp) cmp.show() end, 'select_next' }, + ['<Enter>'] = { 'accept', 'fallback' }, + }, + completion = { + list = { + selection = { preselect = true, auto_insert = false }, + }, + menu = { + border = "rounded", + auto_show = false, + }, + documentation = { window = { border = 'rounded' } }, + }, + signature = { window = { border = 'rounded' } }, +}) + +vim.diagnostic.config({ + virtual_text = false, + float = { border = "rounded" }, + signs = false, + underline = true, + update_in_insert = false, + float = true, + jump = { float = true }, +}) + +vim.api.nvim_create_autocmd("LspAttach", { callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + + map('n', 'E', '<cmd>lua vim.lsp.buf.hover()<CR>', { silent = true }) + + if client:supports_method(methods.textDocument_formatting) then + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = args.buf, + callback = function() + vim.lsp.buf.format({bufnr = args.buf, id = client_id}) + end + }) + end +end}) + +local lspconfig = require('lspconfig') + +for server, config in pairs(servers) do + config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) + lspconfig[server].setup(config) +end diff --git a/modules/neovim/nvim/lua/config/settings.lua b/modules/neovim/nvim/lua/config/settings.lua new file mode 100644 index 0000000..7893730 --- /dev/null +++ b/modules/neovim/nvim/lua/config/settings.lua @@ -0,0 +1,21 @@ +vim.g.mapleader = ' ' + +vim.o.number = true +vim.o.relativenumber = true +vim.o.splitright = true +vim.o.splitbelow = true +vim.o.scrolloff = 15 +vim.o.wrap = false +vim.o.lbr = true +vim.o.shortmess = vim.o.shortmess .. "I" +vim.o.termguicolors = true +vim.opt.fillchars = {eob = " "} +--vim.o.smd = false +--vim.opt.laststatus = 3 +vim.opt.pumheight = 6 +vim.opt.shiftwidth = 8 +vim.opt.tabstop = 8 +vim.opt.expandtab = true +vim.o.mouse="" +vim.o.guicursor="" +vim.o.swapfile=false diff --git a/modules/neovim/terminal.lua b/modules/neovim/terminal.lua deleted file mode 100644 index 6d8e70b..0000000 --- a/modules/neovim/terminal.lua +++ /dev/null @@ -1,7 +0,0 @@ ---vim.api.nvim_create_autocmd("TermOpen", { --- callback = function() --- vim.o.statusline = "%{b:term_title}" --- end ---}) - -vim.cmd[[autocmd TermOpen * setlocal statusline=%{b:term_title}]] |