diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2025-03-02 13:30:28 -0500 |
|---|---|---|
| committer | Stefan Weigl-Bosker <stefan@s00.xyz> | 2025-03-02 13:30:28 -0500 |
| commit | b5e3e6f12b41a9a1133744e139c5aa47d1bee006 (patch) | |
| tree | 460b2222c3823258eed2af239d3f78905141a538 /modules/neovim | |
| parent | cfa595c7264a3618759d8382de0996017c558e26 (diff) | |
| download | home-b5e3e6f12b41a9a1133744e139c5aa47d1bee006.tar.gz | |
update before i break everything
Diffstat (limited to 'modules/neovim')
| -rw-r--r-- | modules/neovim/default.nix | 3 | ||||
| -rw-r--r-- | modules/neovim/keybinds.lua | 12 | ||||
| -rw-r--r-- | modules/neovim/lsp.lua | 57 | ||||
| -rw-r--r-- | modules/neovim/terminal.lua | 7 |
4 files changed, 79 insertions, 0 deletions
diff --git a/modules/neovim/default.nix b/modules/neovim/default.nix index fd77085..ce1e6e0 100644 --- a/modules/neovim/default.nix +++ b/modules/neovim/default.nix @@ -22,6 +22,7 @@ in 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"))); } @@ -42,6 +43,8 @@ in extraLuaConfig = '' ${builtins.readFile ./settings.lua} ${builtins.readFile ./keybinds.lua} + ${builtins.readFile ./lsp.lua} + ${builtins.readFile ./terminal.lua} ''; }; }; diff --git a/modules/neovim/keybinds.lua b/modules/neovim/keybinds.lua index cbd46c5..3f848b5 100644 --- a/modules/neovim/keybinds.lua +++ b/modules/neovim/keybinds.lua @@ -39,3 +39,15 @@ nmap('<leader>we', '<C-w><C-k>', { desc = "Focus window above the current one" } nmap('<leader>wi', '<C-w><C-l>', { desc = "Focus window right of the current one" }) 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/lsp.lua b/modules/neovim/lsp.lua new file mode 100644 index 0000000..ad6cddf --- /dev/null +++ b/modules/neovim/lsp.lua @@ -0,0 +1,57 @@ +-- 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/terminal.lua b/modules/neovim/terminal.lua new file mode 100644 index 0000000..6d8e70b --- /dev/null +++ b/modules/neovim/terminal.lua @@ -0,0 +1,7 @@ +--vim.api.nvim_create_autocmd("TermOpen", { +-- callback = function() +-- vim.o.statusline = "%{b:term_title}" +-- end +--}) + +vim.cmd[[autocmd TermOpen * setlocal statusline=%{b:term_title}]] |