diff --git a/common/nvim/lsp_autocmd.lua b/common/nvim/lsp_autocmd.lua new file mode 100644 index 0000000..abd777f --- /dev/null +++ b/common/nvim/lsp_autocmd.lua @@ -0,0 +1,74 @@ +function(event) + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local map = function(keys, func, desc) + vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + end + +-- Jump to the definition of the word under your cursor. +-- This is where a variable was first declared, or where a function is defined, etc. +-- To jump back, press . +map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") + +-- Find references for the word under your cursor. +map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + +-- Jump to the implementation of the word under your cursor. +-- Useful when your language has ways of declaring types without an actual implementation. +map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") + +-- Jump to the type of the word under your cursor. +-- Useful when you're not sure what type a variable is and you want to see +-- the definition of its *type*, not where it was *defined*. +map("D", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") + +-- Fuzzy find all the symbols in your current document. +-- Symbols are things like variables, functions, types, etc. +map("ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]ymbols") + +-- Fuzzy find all the symbols in your current workspace +-- Similar to document symbols, except searches over your whole project. +map( + "ws", + require("telescope.builtin").lsp_dynamic_workspace_symbols, + "[W]orkspace [S]ymbols" +) + +-- Rename the variable under your cursor +-- Most Language Servers support renaming across files, etc. +map("rn", vim.lsp.buf.rename, "[R]e[n]ame") + +-- Execute a code action, usually your cursor needs to be on top of an error +-- or a suggestion from your LSP for this to activate. +map("ca", vim.lsp.buf.code_action, "[C]ode [A]ction") + +-- Opens a popup that displays documentation about the word under your cursor +-- See `:help K` for why this keymap +map("K", vim.lsp.buf.hover, "Hover Documentation") + +-- WARN: This is not Goto Definition, this is Goto Declaration. +-- For example, in C this would take you to the header +map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + +-- The following two autocommands are used to highlight references of the +-- word under your cursor when your cursor rests there for a little while. +-- See `:help CursorHold` for information about when this is executed +-- +-- When you move your cursor, the highlights will be cleared (the second autocommand). +local client = vim.lsp.get_client_by_id(event.data.client_id) +if client and client.server_capabilities.documentHighlightProvider then + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + buffer = event.buf, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + buffer = event.buf, + callback = vim.lsp.buf.clear_references, + }) +end +end diff --git a/common/nvim/nvim.nix b/common/nvim/nvim.nix index bee1f70..213375c 100644 --- a/common/nvim/nvim.nix +++ b/common/nvim/nvim.nix @@ -5,16 +5,188 @@ # needed for the nvim config, neovim itself is a system package already ripgrep ]; - programs.neovim = { + # programs.neovim = { + # enable = true; + # defaultEditor = true; + # + # viAlias = true; + # vimAlias = true; + # vimdiffAlias = true; + # + # extraLuaConfig = '' + # ${builtins.readFile ./init.lua} + # ''; + # }; + programs.nixvim = { enable = true; defaultEditor = true; - viAlias = true; vimAlias = true; - vimdiffAlias = true; - extraLuaConfig = '' - ${builtins.readFile ./init.lua} - ''; + colorschemes.tokyonight = { + enable = true; + style = "night"; + }; + + globals = { + mapleader = " "; + maplocalleader = " "; + }; + + options = { + hlsearch = true; + number = true; + relativenumber = true; + mouse = "a"; + showmode = false; + breakindent = true; + undofile = true; + ignorecase = true; + smartcase = true; + signcolumn = "yes"; + updatetime = 250; + timeoutlen = 300; + splitright = true; + splitbelow = true; + + list = true; + listchars = { tab = "» "; trail = "·"; nbsp = "␣"; }; + + inccommand = "split"; + cursorline = true; + + scrolloff = 10; + foldmethod = "expr"; + foldexpr = "nvim_treesitter#foldexpr()"; + + autoGroups = { + "kickstart-highlight-yank" = { clear = true; }; + "kickstart-lsp-attach" = {clear = true; }; + }; + + autoCmd = [ + { + event = "TextYankPost"; + group = "kickstart-highlight-yank"; + callback = ''function() vim.highlight.on_yank() end''; + } + { + event = "LspAttach"; + group = "kickstart-lsp-attach"; + callback = builtins.readFile ./lsp_autocmd.lua; + } + ]; + }; + + keymaps = [ + { mode = "n"; key = ""; action = "nohlsearch";} + { mode = "n"; key = "[d"; lua = true; action = "vim.diagnostic.goto_prev"; options.desc = "Go to previous [D]iagnostic message" ;} + { mode = "n"; key = "]d"; lua = true; action = "vim.diagnostic.goto_next"; options.desc = "Go to next [D]iagnostic message" ;} + { mode = "n"; key = "e"; lua = true; action = "vim.diagnostic.open_float"; options.desc = "Show diagnostic [E]rror messages" ;} + { mode = "n"; key = "q"; lua = true; action = "vim.diagnostic.setloclist"; options.desc = "Open diagnostic [Q]uickfix list" ;} + { mode = "t"; key = ""; action = ""; options.desc = "Exit terminal mode" ;} + { mode = "n"; key = ""; action = ""; options.desc = "Move focus to the left window" ;} + { mode = "n"; key = ""; action = ""; options.desc = "Move focus to the right window" ;} + { mode = "n"; key = ""; action = ""; options.desc = "Move focus to the lower window" ;} + { mode = "n"; key = ""; action = ""; options.desc = "Move focus to the upper window" ;} + { mode = "n"; key = "pv"; lua = true; action = "vim.cmd.Ex";} + { mode = "x"; key = "p"; action = ''[["_dP]]'';} + { mode = [ "n" "v" ]; key = "y"; action = ''[["+y]]'';} + { mode = "n"; key = "Y"; action = ''[["+Y]]'';} + { mode = [ "n" "v" ]; key = "d"; action = ''[["_d]]'';} + { mode = "v"; key = "J"; action = ":m '>+1gv=gv";} + { mode = "v"; key = "K"; action = ":m '<-2gv=gv";} + ]; + + plugins = { + fugitive.enable = true; + nvim-colorizer.enable = true; + comment-nvim.enable = true; + gitsigns = { + enable = true; + signs = { + add.text = "+"; + change.text = "~"; + delete.text = "_"; + topdelete.text = "‾"; + changedelete.text = "~"; + untracked.text = "┆"; + }; + }; + which-key = { + enable = true; + registrations = { + "c" = "[C]ode"; + "d" = "[D]ocument"; + "r" = "[R]ename"; + "s" = "[S]earch"; + "w" = "[W]orkspace"; + }; + }; + telescope = { + enable = true; + extensions = { + fzf-native.enable = true; + ui-select.enable = true; + }; + keymaps = { + "sh" = { + action = "help_tags"; + desc = "[S]earch [H]elp"; + }; + "sk" = { action = "keymaps"; desc = "[S]earch [K]eymaps"; }; + "sf" = { action = "find_files"; desc = "[S]earch [F]iles"; }; + "ss" = { action = "builtin"; desc = "[S]earch [S]elect Telescope"; }; + "sw" = { action = "grep_string"; desc = "[S]earch current [W]ord"; }; + "sg" = { action = "live_grep"; desc = "[S]earch by [G]rep"; }; + "sd" = { action = "diagnostics"; desc = "[S]earch [D]iagnostics"; }; + "sr" = { action = "resume"; desc = "[S]earch [R]esume"; }; + "s." = { action = "oldfiles"; desc = ''[S]earch Recent Files ("." for repeat)''; }; + "" = { action = "buffers"; desc = "[ ] Find existing buffers"; }; + }; + }; + conform-nvim = { + enable = true; + formatOnSave = { + timeoutMs = 500; + lspFallback = true; + }; + formattersByFt = { + lua = [ "stylua" ]; + python = [ "black" ]; + }; + }; + cmp = { + enable = true; + # TODO: find out how cmp works + }; + todo-comments = { + enable = true; + signs = false; + }; + mini = { + enable = true; + modules = { + ai = { + n_lines = 500; + }; + surround = {}; + statusline = {}; + }; + }; + treesitter = { + enable = true; + indent = true; + folding = true; + nixvimInjections = true; + }; + treesitter-context = { + enable = true; + maxLines = 8; + }; + }; + extraPlugins = with pkgs.vimPlugins; [ + vim-sleuth + ]; }; } diff --git a/flake.lock b/flake.lock index 5901dce..9f1df8d 100644 --- a/flake.lock +++ b/flake.lock @@ -194,11 +194,11 @@ ] }, "locked": { - "lastModified": 1710527391, - "narHash": "sha256-3uM8+g/nb7ROgzSmJwOrKefctZpjR5uBJtUz4lpwWJI=", + "lastModified": 1710532761, + "narHash": "sha256-SUXGZNrXX05YA9G6EmgupxhOr3swI1gcxLUeDMUhrEY=", "owner": "nix-community", "repo": "home-manager", - "rev": "c781b28add41b74423ab2e64496d4fc91192e13a", + "rev": "206f457fffdb9a73596a4cb2211a471bd305243d", "type": "github" }, "original": { @@ -265,11 +265,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1710528257, - "narHash": "sha256-DpKAky4UH1hovUq35MxIHikBKVxIw6KXrXkyFjn8I74=", + "lastModified": 1710547119, + "narHash": "sha256-xLxbGRsKs40j+4tKeHydW1VUpCPOizYcduYQvBUitoY=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "72d78eff95948a3eb3260791cfdf625c0102d33a", + "rev": "19c90048d65a5660384d2fb865926a366696d6be", "type": "github" }, "original": { diff --git a/hosts/default/configuration.nix b/hosts/default/configuration.nix index 0374bbe..4486052 100644 --- a/hosts/default/configuration.nix +++ b/hosts/default/configuration.nix @@ -111,7 +111,6 @@ sddm git zsh - neovim ]; # TODO find list of fonts to install diff --git a/hosts/server/configuration.nix b/hosts/server/configuration.nix index e0e83e5..b0aec06 100644 --- a/hosts/server/configuration.nix +++ b/hosts/server/configuration.nix @@ -90,7 +90,6 @@ sddm git zsh - neovim ]; # Some programs need SUID wrappers, can be configured further or are