with builtins; {pkgs, lib}: let mkSettings = s: concatStringsSep "\n" (attrValues (mapAttrs (k: v: if typeOf v == "bool" then if v then "set ${k}" else "set no${k}" else "set ${k}=${toString v}") s ) ); boolToString = b: if b then "true" else "false"; toLuaTable = as: "{" + ( concatStringsSep ", " ( filter (attr: !isNull attr) ( attrValues ( mapAttrs (k: v: if v then "${k}=true" else null) as ) ) ) ) + "}"; mkMapping = { mode, binding, command, nowait?false, silent?false, unique?false, expr?false }: "vim.api.nvim_set_keymap(${toJSON mode}, ${toJSON binding}, ${toJSON command}, ${toLuaTable {inherit nowait silent unique expr;}})"; mkMappings = m: "lua << END-OF-KEYBINDS\n" + (concatStringsSep "\n" (map mkMapping m)) + "\nEND-OF-KEYBINDS"; mkRuntimes = rs: if rs == [] then "" else "set runtimepath+=" + ( concatStringsSep "," (map (rt: "${rt}") rs) ); mkDigraph = {keys, code}: "dig " + keys + " " + (toString code) + "\n"; mkDigraphs = dgs: (concatStringsSep "" (map mkDigraph dgs)); mkVimHeader = h: "\"\"\"\"\"\"\"\" ${h} \"\"\"\"\"\"\"\"\""; mkVimSection = section: (concatStringsSep "\n\n\n" (filter (v: !isNull v) (attrValues (mapAttrs (k: v: if "" == v then null else (mkVimHeader k) + "\n" + v) section ) ) ) ); mkVimSections = sections: concatStringsSep "\n\n\n" (map mkVimSection sections); mkConfig = { settings?{}, mappings?[], digraphs?[], runtimes?[], extra?"" }: mkVimSections [ {"ADDITIONAL RUNTIME DIRS" = mkRuntimes runtimes;} {"SETTINGS" = mkSettings settings;} {"DIGRAPHS" = mkDigraphs digraphs;} {"KEY BINGINGS" = mkMappings mappings;} {"MANUAL SETTINGS" = extra;} ]; # Via https://gist.github.com/nat-418/d76586da7a5d113ab90578ed56069509 fromGitHub = ref: repo: pkgs.vimUtils.buildVimPluginFrom2Nix { pname = "${lib.strings.sanitizeDerivationName repo}"; version = ref; src = builtins.fetchGit { url = "https://github.com/${repo}.git"; ref = ref; }; }; in { enable = true; plugins = with pkgs.vimPlugins; [ editorconfig-nvim vim-airline vim-airline-themes lsp_signature-nvim nvim-colorizer-lua nnn-vim nvim-surround hop-nvim nvim-treesitter.withAllGrammars nvim-ts-rainbow nvim-lspconfig (fromGitHub "HEAD" "whonore/Coqtail") ]; extraConfig = mkConfig { settings = { number = true; expandtab = false; linebreak = true; display = "lastline"; comments = "s1:/*,mb:*,ex:*/,:///\\ #,:///,://!,://,b:#,:%,:XCOMM,n:>,b:-,b:*"; tgc = true; tw = 90; foldmethod = "expr"; foldexpr = "nvim_treesitter#foldexpr()"; foldminlines = 10; foldnestmax = 2; }; digraphs = [ { # Append keys = "<>"; code = 8853; } { # Multi Map keys = "-o"; code = 8888; } { # Degree Symbol keys = "'o"; code = 176; } { # Ring Operator keys = ".o"; code = 8728; } { # Integers keys = "ZZ"; code = 8484; } { # Naturals keys = "NN"; code = 8469; } { # Reals keys = "RR"; code = 8477; } { # Rationals keys = "QQ"; code = 8474; } ]; mappings = [ { # New tab mode = ""; binding = ""; command = ":tab split"; } { # File picker mode = "n"; binding = ""; command = "call nnn#pick(expand('%:p:h'))"; } { # Jump mode = "n"; binding = ""; command = "HopWord"; } { # Jump by characters mode = "n"; binding = ""; command = "HopChar2"; } { # Clear search mode = ""; binding = ""; command = "noh"; } { mode = "i"; binding = ""; command = "coc#pum#visible() ? coc#pum#next(1) : CheckBackspace() ? \"\\\" : coc#refresh()"; silent = true; expr = true; } { mode = "i"; binding = ""; command = "coc#pum#visible() ? coc#pum#prev(1) : \"\\\""; expr = true; } { mode = "n"; binding = ""; command = "coc#refresh()"; silent = true; } { mode = "n"; binding = "[g"; command = "(coc-diagnostic-prev)"; silent = true; } { mode = "n"; binding = "]g"; command = "(coc-diagnostic-next)"; silent = true; } { mode = "n"; binding = "gd"; command = "(coc-definition)"; silent = true; } { mode = "n"; binding = "gy"; command = "(coc-type-definition)"; silent = true; } { mode = "n"; binding = "gi"; command = "(coc-implementation)"; silent = true; } { mode = "n"; binding = "gr"; command = "(coc-references)"; silent = true; } { mode = "n"; binding = "K"; command = ":call ShowDocumentation()"; silent = true; } { mode = "n"; binding = "..."; command = "(coc-codeaction-cursor)"; silent = true; } { mode = "n"; binding = "rn"; command = "(coc-rename)"; silent = true; } { mode = "n"; binding = "cl"; command = "(coc-codelens-action)"; silent = true; } ]; runtimes = [neovim/laserwave]; extra = builtins.readFile neovim/init.vim; }; coc.enable = true; coc.settings = { "diagnostic-languageserver.filetypes" = { python = "mypy"; }; haskell = { command = "haskell-language-server-wrapper"; args = ["--lsp"]; rootPatterns = ["*.cabal" "stack.yaml" "cabal.project" "package.yaml" "hie.yaml"]; filetypes = ["hs" "lhs" "haskell" "lhaskell"]; }; }; }