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"; + "" = "