From 0fa094845024d39d00e5e4b4c46fdc21e11afefb Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Wed, 4 Dec 2024 21:11:13 -0600 Subject: [PATCH] neovim configs --- home/modules/tui/neovim/autocmds.nix | 25 +++++++ home/modules/tui/neovim/completion.nix | 55 ++++++++++++++ home/modules/tui/neovim/default.nix | 18 +++++ home/modules/tui/neovim/keymaps.nix | 74 +++++++++++++++++++ home/modules/tui/neovim/options.nix | 46 ++++++++++++ home/modules/tui/neovim/plugins/barbar.nix | 10 +++ home/modules/tui/neovim/plugins/comment.nix | 10 +++ home/modules/tui/neovim/plugins/default.nix | 52 +++++++++++++ home/modules/tui/neovim/plugins/floaterm.nix | 12 +++ home/modules/tui/neovim/plugins/harpoon.nix | 20 +++++ home/modules/tui/neovim/plugins/lsp.nix | 38 ++++++++++ .../modules/tui/neovim/plugins/md-preview.nix | 20 +++++ home/modules/tui/neovim/plugins/neo-tree.nix | 22 ++++++ home/modules/tui/neovim/plugins/telescope.nix | 33 +++++++++ .../modules/tui/neovim/plugins/treesitter.nix | 26 +++++++ 15 files changed, 461 insertions(+) create mode 100644 home/modules/tui/neovim/autocmds.nix create mode 100644 home/modules/tui/neovim/completion.nix create mode 100644 home/modules/tui/neovim/keymaps.nix create mode 100644 home/modules/tui/neovim/options.nix create mode 100644 home/modules/tui/neovim/plugins/barbar.nix create mode 100644 home/modules/tui/neovim/plugins/comment.nix create mode 100644 home/modules/tui/neovim/plugins/default.nix create mode 100644 home/modules/tui/neovim/plugins/floaterm.nix create mode 100644 home/modules/tui/neovim/plugins/harpoon.nix create mode 100644 home/modules/tui/neovim/plugins/lsp.nix create mode 100644 home/modules/tui/neovim/plugins/md-preview.nix create mode 100644 home/modules/tui/neovim/plugins/neo-tree.nix create mode 100644 home/modules/tui/neovim/plugins/telescope.nix create mode 100644 home/modules/tui/neovim/plugins/treesitter.nix diff --git a/home/modules/tui/neovim/autocmds.nix b/home/modules/tui/neovim/autocmds.nix new file mode 100644 index 0000000..9761bf5 --- /dev/null +++ b/home/modules/tui/neovim/autocmds.nix @@ -0,0 +1,25 @@ +{ + programs.nixvim.autoCmd = [ + # Vertically center document when entering insert mode + { + event = "InsertEnter"; + command = "norm zz"; + } + + # Open help in a vertical split + { + event = "FileType"; + pattern = "help"; + command = "wincmd L"; + } + + # Enable spellcheck for some filetypes + { + event = "FileType"; + pattern = [ + "markdown" + ]; + command = "setlocal spell spelllang=en"; + } + ]; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/completion.nix b/home/modules/tui/neovim/completion.nix new file mode 100644 index 0000000..d7d9c81 --- /dev/null +++ b/home/modules/tui/neovim/completion.nix @@ -0,0 +1,55 @@ +{ + programs.nixvim = { + opts.completeopt = ["menu" "menuone" "noselect"]; + + plugins = { + luasnip.enable = true; + + lspkind = { + enable = true; + + cmp = { + enable = true; + menu = { + nvim_lsp = "[LSP]"; + nvim_lua = "[api]"; + path = "[path]"; + luasnip = "[snip]"; + buffer = "[buffer]"; + nixpkgs_maintainers = "[nixpkgs]"; + }; + }; + }; + + cmp = { + enable = true; + + settings = { + snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end"; + + mapping = { + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})"; + "" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})"; + "" = "cmp.mapping.confirm({ select = true })"; + }; + + sources = [ + {name = "path";} + {name = "nvim_lsp";} + {name = "luasnip";} + {name = "nixpkgs_maintainers";} + { + name = "buffer"; + # words from other open buffers can also be suggested + option.get_bufnrs.__raw = "vim.api.nvim_list_bufs"; + } + ]; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/default.nix b/home/modules/tui/neovim/default.nix index 3baffad..e8a0c02 100644 --- a/home/modules/tui/neovim/default.nix +++ b/home/modules/tui/neovim/default.nix @@ -2,9 +2,27 @@ imports = [ inputs.nixvim.homeManagerModules.nixvim + ./autocmds.nix + ./completion.nix + ./keymaps.nix + ./options.nix + ./plugins ]; programs.nixvim = { enable = true; + + performance = { + combinePlugins = { + enable = true; + standalonePlugins = [ + "hmts.nvim" + "nvim-treesitter" + ]; + }; + byteCompileLua.enable = true; + }; + + luaLoader.enable = true; }; } diff --git a/home/modules/tui/neovim/keymaps.nix b/home/modules/tui/neovim/keymaps.nix new file mode 100644 index 0000000..9acb8bc --- /dev/null +++ b/home/modules/tui/neovim/keymaps.nix @@ -0,0 +1,74 @@ +{ config, lib, ... }: { + programs.nixvim = { + globals = { + mapleader = " "; + maplocalleader = " "; + }; + + keymaps = let + normal = + lib.mapAttrsToList + (key: action: { + mode = "n"; + inherit action key; + }) + { + "" = ""; + + # Esc to clear search results + "" = ":noh"; + + # fix Y behavior + Y = "y$"; + + # toggle between two most recent files + "" = ":b#"; + + # close by Ctrl+x + "" = ":close"; + + # save by Space+s or Ctrl+s + "s" = ":w"; + "" = ":w"; + + # H, L to jump to start/end of line + L = "$"; + H = "^"; + + # resize with arrows + "" = ":resize -2"; + "" = ":resize +2"; + "" = ":vertical resize +2"; + "" = ":vertical resize -2"; + + # move current line up/down + # M = Alt + "" = ":move-2"; + "" = ":move+"; + }; + visual = + lib.mapAttrsToList + (key: action: { + mode = "v"; + inherit action key; + }) + { + # better indenting + ">" = ">gv"; + "<" = "" = ">gv"; + "" = "s" = ":sort"; + }; + in + config.lib.nixvim.keymaps.mkKeymaps + {options.silent = true;} + (normal ++ visual); + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/options.nix b/home/modules/tui/neovim/options.nix new file mode 100644 index 0000000..ac77128 --- /dev/null +++ b/home/modules/tui/neovim/options.nix @@ -0,0 +1,46 @@ +{ + programs.nixvim = { + clipboard = { + providers = { + wl-copy.enable = true; + xsel.enable = true; + }; + register = "unnamedplus"; + }; + + opts = { + updatetime = 100; # Faster completion + relativenumber = true; # Relative line numbers + number = true; # Display absolute line number of current line + hidden = true; # Keep closed buffer open in the background + mouse = "a"; # Enable mouse control + mousemodel = "extend"; # Mouse right-click extends the current selection + splitbelow = true; # A new window is put below the current one + splitright = true; # A new window is put right of the corrent one + swapfile = false; # Disable the swap file + modeline = true; # tags such as 'vim:ft=sh' + modelines = 5; # check first and last five lines for modelines + undofile = true; # save and restore undo history + incsearch = true; # incremental search: show match for partly typed search command + inccommand = "split"; # search and replace: preview changes in quickfix list + ignorecase = true; # when search query is lowercase match both lower and upper patterns + smartcase = true; # override ignorecase if search pattern containers upper case + scrolloff = 8; # number of lines to show around the cursor + cursorline = true; # highlight the screen line of the cursor + cursorcolumn = false; # highlight the screen column of the cursor + signcolumn = "yes"; # whether to show the signcolumn + colorcolumn = "100"; # columns to highlight + laststatus = 3; # when to use a status line for the last window + fileencoding = "utf-8"; # file-content encoding for the current buffer + termguicolors = true; # enables 24-bit colors + spell = false; # highlight spelling mistakes + wrap = false; # prevent wrapping text + tabstop = 2; # number of spaces a in the text stands for + shiftwidth = 2; # number of spaces used for each step of (auto)indent + expandtab = true; # expand to spaces in Insert mode + autoindent = true; # do clever autoindenting + textwidth = 0; # maximum width of text that is being inserted, a longer line will be broken after whitespace to this width + foldlevel = 99; # folds with a level higher than this number will be closed + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/barbar.nix b/home/modules/tui/neovim/plugins/barbar.nix new file mode 100644 index 0000000..02b8067 --- /dev/null +++ b/home/modules/tui/neovim/plugins/barbar.nix @@ -0,0 +1,10 @@ +{ + programs.nixvim.plugins.barbar = { + enable = true; + keymaps = { + next.key = ""; + previous.key = ""; + close.key = ""; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/comment.nix b/home/modules/tui/neovim/plugins/comment.nix new file mode 100644 index 0000000..0a688e9 --- /dev/null +++ b/home/modules/tui/neovim/plugins/comment.nix @@ -0,0 +1,10 @@ +{ + programs.nixvim.plugins.comment = { + enable = true; + + settings = { + opleader.line = ""; + toggler.line = ""; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/default.nix b/home/modules/tui/neovim/plugins/default.nix new file mode 100644 index 0000000..380785a --- /dev/null +++ b/home/modules/tui/neovim/plugins/default.nix @@ -0,0 +1,52 @@ +{ + imports = [ + ./barbar.nix + ./comment.nix + ./floaterm.nix + ./harpoon.nix + ./lsp.nix + ./md-preview.nix + ./neo-tree.nix + ./telescope.nix + ./treesitter.nix + ]; + + programs.nixvim = { + colorschemes.catppuccin.enable = true; + + plugins = { + web-devicons.enable = true; + + gitsigns = { + enable = true; + settings.signs = { + add.text = "+"; + change.text = "~"; + }; + }; + + nvim-autopairs.enable = true; + + nvim-colorizer = { + enable = true; + userDefaultOptions.names = false; + }; + + oil.enable = true; + + trim = { + enable = true; + settings = { + highlight = true; + ft_blocklist = [ + "checkhealth" + "floaterm" + "lsipinfo" + "neo-tree" + "TelescopePrompt" + ]; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/floaterm.nix b/home/modules/tui/neovim/plugins/floaterm.nix new file mode 100644 index 0000000..71df0cf --- /dev/null +++ b/home/modules/tui/neovim/plugins/floaterm.nix @@ -0,0 +1,12 @@ +{ + programs.nixvim.plugins.floaterm = { + enable = true; + + width = 0.8; + height = 0.8; + + title = ""; + + keymaps.toggle = ","; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/harpoon.nix b/home/modules/tui/neovim/plugins/harpoon.nix new file mode 100644 index 0000000..8f3560e --- /dev/null +++ b/home/modules/tui/neovim/plugins/harpoon.nix @@ -0,0 +1,20 @@ +{ + programs.nixvim = { + plugins.harpoon = { + enable = true; + + keymapsSilent = true; + + keymaps = { + addFile = "a"; + toggleQuickMenu = ""; + navFile = { + "1" = ""; + "2" = ""; + "3" = ""; + "4" = ""; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/lsp.nix b/home/modules/tui/neovim/plugins/lsp.nix new file mode 100644 index 0000000..7fb8e3d --- /dev/null +++ b/home/modules/tui/neovim/plugins/lsp.nix @@ -0,0 +1,38 @@ +{ + programs.nixvim = { + plugins = { + lsp-format = { + enable = true; + lspServersToEnable = "all"; + }; + + lsp = { + enable = true; + + inlayHints = true; + + keymaps = { + silent = true; + diagnostic = { + # navigate in diagnostics + "k" = "goto_prev"; + "j" = "goto_next"; + }; + + lspBuf = { + gd = "definition"; + gD = "references"; + gt = "type_definition"; + gi = "implementation"; + K = "hover"; + "" = "rename"; + }; + }; + + servers = { + clangd.enable = true; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/md-preview.nix b/home/modules/tui/neovim/plugins/md-preview.nix new file mode 100644 index 0000000..f8f4cc8 --- /dev/null +++ b/home/modules/tui/neovim/plugins/md-preview.nix @@ -0,0 +1,20 @@ +{ + programs.nixvim = { + plugins.markdown-preview = { + enable = true; + + settings = { + auto_close = 0; + theme = "dark"; + }; + }; + + files."after/ftplugin/markdown.lua".keymaps = [ + { + mode = "n"; + key = "m"; + action = ":MarkdownPreview"; + } + ]; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/neo-tree.nix b/home/modules/tui/neovim/plugins/neo-tree.nix new file mode 100644 index 0000000..c0d03dc --- /dev/null +++ b/home/modules/tui/neovim/plugins/neo-tree.nix @@ -0,0 +1,22 @@ +{ + programs.nixvim = { + keymaps = [ + { + mode = "n"; + key = "n"; + action = ":Neotree action=focus reveal toggle"; + options.silent = true; + } + ]; + + plugins.neo-tree = { + enable = true; + + closeIfLastWindow = true; + window = { + width = 30; + autoExpandWidth = true; + }; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/telescope.nix b/home/modules/tui/neovim/plugins/telescope.nix new file mode 100644 index 0000000..0eb680c --- /dev/null +++ b/home/modules/tui/neovim/plugins/telescope.nix @@ -0,0 +1,33 @@ +{ + programs.nixvim = { + plugins.telescope = { + enable = true; + + keymaps = { + # find files using telescope command-line sugar + "ff" = "find_files"; + "fg" = "live_grep"; + "b" = "buffers"; + "fh" = "help_tags"; + "fd" = "diagnostics"; + + # fzf like bindings + "" = "git_files"; + "p" = "oldfiles"; + "" = "live_grep"; + }; + + settings.defaults = { + file_ignore_patterns = [ + "^.git/" + "^.mypy_cache/" + "^__pycache__/" + "^output/" + "^data/" + "%.ipynb" + ]; + set_env.COLORTERM = "truecolor"; + }; + }; + }; +} \ No newline at end of file diff --git a/home/modules/tui/neovim/plugins/treesitter.nix b/home/modules/tui/neovim/plugins/treesitter.nix new file mode 100644 index 0000000..64cc1c1 --- /dev/null +++ b/home/modules/tui/neovim/plugins/treesitter.nix @@ -0,0 +1,26 @@ +{ + programs.nixvim.plugins = { + treesitter = { + enable = true; + + nixvimInjections = true; + + settings = { + highlight.enable = true; + indent.enable = true; + }; + folding = true; + }; + + treesitter-refactor = { + enable = true; + highlightDefinitions = { + enable = true; + # set to false if you have an updatetime of ~100 + clearOnCursorMove = false; + }; + }; + + hmts.enable = true; + }; +} \ No newline at end of file