From 996a3c64d2d142b9200fb44b3ed37956483242b7 Mon Sep 17 00:00:00 2001 From: cnst Date: Sun, 14 Jul 2024 19:22:54 +0200 Subject: [PATCH] testing nixvim --- flake.nix | 4 + home/extra/neovim/autocommands.nix | 27 ++++ home/extra/neovim/completion.nix | 55 ++++++++ home/extra/neovim/default.nix | 73 +++-------- home/extra/neovim/keymappings.nix | 81 ++++++++++++ home/extra/neovim/nvim/lua/cnst/set.lua | 0 home/extra/neovim/options.nix | 63 ++++++++++ home/extra/neovim/plugins/barbar.nix | 10 ++ home/extra/neovim/plugins/comment.nix | 10 ++ home/extra/neovim/plugins/default.nix | 56 +++++++++ home/extra/neovim/plugins/efm.nix | 22 ++++ home/extra/neovim/plugins/floaterm.nix | 12 ++ home/extra/neovim/plugins/harpoon.nix | 20 +++ home/extra/neovim/plugins/lsp.nix | 33 +++++ home/extra/neovim/plugins/lualine.nix | 46 +++++++ .../extra/neovim/plugins/markdown-preview.nix | 20 +++ home/extra/neovim/plugins/neo-tree.nix | 22 ++++ home/extra/neovim/plugins/startify.nix | 32 +++++ home/extra/neovim/plugins/tagbar.nix | 17 +++ home/extra/neovim/plugins/telescope.nix | 33 +++++ home/extra/neovim/plugins/treesitter.nix | 26 ++++ home/extra/neovim/plugins/vimtex.nix | 77 ++++++++++++ home/extra/neovim/todo.nix | 26 ++++ home/extra/neovimbak/default.nix | 62 +++++++++ .../{neovim => neovimbak}/default.nixnew | 0 .../extra/{neovim => neovimbak}/nvim/init.lua | 0 .../nvim/lua/cnst/remap.lua | 0 home/extra/neovimbak/nvim/lua/cnst/set.lua | 118 ++++++++++++++++++ .../nvim/lua/plugins/alpha.lua | 0 .../nvim/lua/plugins/autopairs.lua | 0 .../nvim/lua/plugins/better-escape.lua | 0 .../nvim/lua/plugins/devicons.lua | 0 .../nvim/lua/plugins/gitsigns.lua | 0 .../nvim/lua/plugins/hmts.lua | 0 .../nvim/lua/plugins/init.lua | 0 .../nvim/lua/plugins/lsp.lua | 4 +- .../nvim/lua/plugins/lualine.lua | 2 +- .../nvim/lua/plugins/neo-tree.lua | 0 .../nvim/lua/plugins/notify.lua | 0 .../nvim/lua/plugins/rust.lua | 0 .../nvim/lua/plugins/telescope.lua | 0 .../nvim/lua/plugins/treesitter.lua | 0 .../nvim/lua/plugins/which-key.lua | 0 43 files changed, 892 insertions(+), 59 deletions(-) create mode 100644 home/extra/neovim/autocommands.nix create mode 100644 home/extra/neovim/completion.nix create mode 100644 home/extra/neovim/keymappings.nix delete mode 100644 home/extra/neovim/nvim/lua/cnst/set.lua create mode 100644 home/extra/neovim/options.nix create mode 100644 home/extra/neovim/plugins/barbar.nix create mode 100644 home/extra/neovim/plugins/comment.nix create mode 100644 home/extra/neovim/plugins/default.nix create mode 100644 home/extra/neovim/plugins/efm.nix create mode 100644 home/extra/neovim/plugins/floaterm.nix create mode 100644 home/extra/neovim/plugins/harpoon.nix create mode 100644 home/extra/neovim/plugins/lsp.nix create mode 100644 home/extra/neovim/plugins/lualine.nix create mode 100644 home/extra/neovim/plugins/markdown-preview.nix create mode 100644 home/extra/neovim/plugins/neo-tree.nix create mode 100644 home/extra/neovim/plugins/startify.nix create mode 100644 home/extra/neovim/plugins/tagbar.nix create mode 100644 home/extra/neovim/plugins/telescope.nix create mode 100644 home/extra/neovim/plugins/treesitter.nix create mode 100644 home/extra/neovim/plugins/vimtex.nix create mode 100644 home/extra/neovim/todo.nix create mode 100644 home/extra/neovimbak/default.nix rename home/extra/{neovim => neovimbak}/default.nixnew (100%) rename home/extra/{neovim => neovimbak}/nvim/init.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/cnst/remap.lua (100%) create mode 100644 home/extra/neovimbak/nvim/lua/cnst/set.lua rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/alpha.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/autopairs.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/better-escape.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/devicons.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/gitsigns.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/hmts.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/init.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/lsp.lua (97%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/lualine.lua (96%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/neo-tree.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/notify.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/rust.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/telescope.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/treesitter.lua (100%) rename home/extra/{neovim => neovimbak}/nvim/lua/plugins/which-key.lua (100%) diff --git a/flake.nix b/flake.nix index 88c0b53c..ef53408f 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,10 @@ url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; + nixvim = { + url = "github:nix-community/nixvim"; + inputs.nixpkgs.follows = "nixpkgs"; + }; #nix-gl = { # url = "github:nix-community/nixgl"; # inputs.nixpkgs.follows = "nixpkgs"; diff --git a/home/extra/neovim/autocommands.nix b/home/extra/neovim/autocommands.nix new file mode 100644 index 00000000..e8487c96 --- /dev/null +++ b/home/extra/neovim/autocommands.nix @@ -0,0 +1,27 @@ +{ + 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 = [ + "tex" + "latex" + "markdown" + ]; + command = "setlocal spell spelllang=en,fr"; + } + ]; +} diff --git a/home/extra/neovim/completion.nix b/home/extra/neovim/completion.nix new file mode 100644 index 00000000..5539bbf1 --- /dev/null +++ b/home/extra/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]"; + neorg = "[neorg]"; + }; + }; + }; + + 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 = "buffer"; + # Words from other open buffers can also be suggested. + option.get_bufnrs.__raw = "vim.api.nvim_list_bufs"; + } + {name = "neorg";} + ]; + }; + }; + }; + }; +} diff --git a/home/extra/neovim/default.nix b/home/extra/neovim/default.nix index 92d656af..7145f842 100644 --- a/home/extra/neovim/default.nix +++ b/home/extra/neovim/default.nix @@ -1,62 +1,23 @@ -{pkgs, ...}: let - treesitterWithGrammars = pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ - p.bash - p.comment - p.css - p.dockerfile - p.fish - p.gitattributes - p.gitignore - p.go - p.gomod - p.gowork - p.hcl - p.javascript - p.jq - p.json5 - p.json - p.lua - p.make - p.markdown - p.nix - p.python - p.rust - p.toml - p.typescript - p.vue - p.yaml - ]); +{inputs, ...}: { + imports = [ + inputs.nixvim.homeManagerModules.nixvim + ./autocommands.nix + ./completion.nix + ./keymappings.nix + ./options.nix + ./plugins + ./todo.nix + ]; - treesitter-parsers = pkgs.symlinkJoin { - name = "treesitter-parsers"; - paths = treesitterWithGrammars.dependencies; - }; -in { - programs.neovim = { + home.shellAliases.v = "nvim"; + + programs.nixvim = { enable = true; defaultEditor = true; - package = pkgs.neovim-unwrapped; + + viAlias = true; vimAlias = true; - coc.enable = false; - withNodeJs = true; - #package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default; - plugins = [ - treesitterWithGrammars - ]; - }; - home.file."./.config/nvim/" = { - source = ./nvim; - recursive = true; - }; - home.file."./.config/nvim/lua/cnst/init.lua".text = '' - require("cnst.set") - require("cnst.remap") - vim.opt.runtimepath:append("${treesitter-parsers}") - ''; - # Treesitter is configured as a locally developed module in lazy.nvim - # we hardcode a symlink here so that we can refer to it in our lazy config - home.file."./.local/share/nvim/nix/nvim-treesitter/" = { - recursive = true; - source = treesitterWithGrammars; + + luaLoader.enable = true; }; } diff --git a/home/extra/neovim/keymappings.nix b/home/extra/neovim/keymappings.nix new file mode 100644 index 00000000..785cffd2 --- /dev/null +++ b/home/extra/neovim/keymappings.nix @@ -0,0 +1,81 @@ +{ + 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 behaviour + Y = "y$"; + + # back and fourth between the two most recent files + "" = ":b#"; + + # close by Ctrl+x + "" = ":close"; + + # save by Space+s or Ctrl+s + "s" = ":w"; + "" = ":w"; + + # navigate to left/right window + "h" = "h"; + "l" = "l"; + + # Press 'H', 'L' to jump to start/end of a line (first/last character) + L = "$"; + H = "^"; + + # resize with arrows + "" = ":resize -2"; + "" = ":resize +2"; + "" = ":vertical resize +2"; + "" = ":vertical resize -2"; + + # move current line up/down + # M = Alt key + "" = ":move-2"; + "" = ":move+"; + + "rp" = ":!remi push"; + }; + visual = + lib.mapAttrsToList + (key: action: { + mode = "v"; + inherit action key; + }) + { + # better indenting + ">" = ">gv"; + "<" = "" = ">gv"; + "" = "