From d47b04a887aea3426647c1980f6e2657fbad87c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Fri, 16 Feb 2024 20:10:20 +0100 Subject: [PATCH] feat: Init nvim from jalil-salame/nvim-config Step one of Issue #15 --- flake.lock | 132 +++++++++++++++---------------------- flake.nix | 31 +++++---- home/default.nix | 2 +- nvim/augroups.nix | 93 ++++++++++++++++++++++++++ nvim/default.nix | 90 +++++++++++++++++++++++++ nvim/mappings.nix | 91 +++++++++++++++++++++++++ nvim/options.nix | 22 +++++++ nvim/plugins/cmp.nix | 88 +++++++++++++++++++++++++ nvim/plugins/default.nix | 17 +++++ nvim/plugins/lspconfig.nix | 19 ++++++ nvim/plugins/lualine.nix | 50 ++++++++++++++ 11 files changed, 538 insertions(+), 97 deletions(-) create mode 100644 nvim/augroups.nix create mode 100644 nvim/default.nix create mode 100644 nvim/mappings.nix create mode 100644 nvim/options.nix create mode 100644 nvim/plugins/cmp.nix create mode 100644 nvim/plugins/default.nix create mode 100644 nvim/plugins/lspconfig.nix create mode 100644 nvim/plugins/lualine.nix diff --git a/flake.lock b/flake.lock index 53b763e..4846c04 100644 --- a/flake.lock +++ b/flake.lock @@ -2,9 +2,7 @@ "nodes": { "audiomenu": { "inputs": { - "flake-schemas": [ - "flake-schemas" - ], + "flake-schemas": "flake-schemas", "nixpkgs": [ "nixpkgs" ] @@ -221,7 +219,6 @@ "flake-parts": { "inputs": { "nixpkgs-lib": [ - "nvim-config", "neovim-nightly", "nixpkgs" ] @@ -243,7 +240,6 @@ "flake-parts_2": { "inputs": { "nixpkgs-lib": [ - "nvim-config", "neovim-nightly", "hercules-ci-effects", "nixpkgs" @@ -276,6 +272,20 @@ "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz" } }, + "flake-schemas_2": { + "locked": { + "lastModified": 1697467827, + "narHash": "sha256-j8SR19V1SRysyJwpOBF4TLuAvAjF5t+gMiboN4gYQDU=", + "rev": "764932025c817d4e500a8d2a4d8c565563923d29", + "revCount": 29, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.2/018b3da8-4cc3-7fbb-8ff7-1588413c53e2/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -386,7 +396,7 @@ }, "haumea": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs" }, "locked": { "lastModified": 1685133229, @@ -407,7 +417,6 @@ "inputs": { "flake-parts": "flake-parts_2", "nixpkgs": [ - "nvim-config", "neovim-nightly", "nixpkgs" ] @@ -448,9 +457,7 @@ }, "jpassmenu": { "inputs": { - "flake-schemas": [ - "flake-schemas" - ], + "flake-schemas": "flake-schemas_2", "nixpkgs": [ "nixpkgs" ] @@ -473,18 +480,17 @@ "inputs": { "flake-utils": "flake-utils", "nixpkgs": [ - "nvim-config", "neovim-nightly", "nixpkgs" ] }, "locked": { "dir": "contrib", - "lastModified": 1707941489, - "narHash": "sha256-S5KG+iYMFVHIEfeXSWYei2jcHs6kOfhM1pUoVQ9G/Lw=", + "lastModified": 1708040042, + "narHash": "sha256-8iloeE/jALIKcOcYKgTlI9i7iDW7n52Epqps27jGklU=", "owner": "neovim", "repo": "neovim", - "rev": "d09957e0a06f350443c750d9838b5f1016c0cccc", + "rev": "04dfa2eea914086a9f42a5a00a33e9524f9fded4", "type": "github" }, "original": { @@ -501,16 +507,15 @@ "hercules-ci-effects": "hercules-ci-effects", "neovim-flake": "neovim-flake", "nixpkgs": [ - "nvim-config", "nixpkgs" ] }, "locked": { - "lastModified": 1707955468, - "narHash": "sha256-ZVka2bcB1AQTiVWqp2yH9Rnsd4Tvpcf5NXXzJIp7QNE=", + "lastModified": 1708041826, + "narHash": "sha256-zW7F31gW4HCBYcImcXxold4ntZdlEr/NTlMVhEMA5dw=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "0b6b4afc71e14d7f17f4e4a367ce271b9d398432", + "rev": "1afaeebc41dab1029b855b17d78f2348e8dd49e3", "type": "github" }, "original": { @@ -537,7 +542,6 @@ "nix-github-actions": { "inputs": { "nixpkgs": [ - "nvim-config", "nixneovim", "nixneovimplugins", "poetry2nix", @@ -563,13 +567,11 @@ "flake-utils": "flake-utils_2", "haumea": "haumea", "home-manager": [ - "nvim-config", "home-manager" ], "nix-flake-tests": "nix-flake-tests", "nixneovimplugins": "nixneovimplugins", "nixpkgs": [ - "nvim-config", "nixpkgs" ], "nmd": "nmd", @@ -592,12 +594,10 @@ "nixneovimplugins": { "inputs": { "flake-utils": [ - "nvim-config", "nixneovim", "flake-utils" ], "nixpkgs": [ - "nvim-config", "nixneovim", "nixpkgs" ], @@ -619,30 +619,32 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1707842204, - "narHash": "sha256-M+HAq1qWQBi/gywaMZwX0odU+Qb/XeqVeANGKRBDOwU=", - "rev": "f1b2f71c86a5b1941d20608db0b1e88a07d31303", - "revCount": 1570, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixos-hardware/0.1.1570%2Brev-f1b2f71c86a5b1941d20608db0b1e88a07d31303/018da354-4a5c-7384-b2a6-d88f9fd65c1e/source.tar.gz" + "lastModified": 1708091350, + "narHash": "sha256-o28BJYi68qqvHipT7V2jkWxDiMS1LF9nxUsou+eFUPQ=", + "owner": "NixOS", + "repo": "nixos-hardware", + "rev": "106d3fec43bcea19cb2e061ca02531d54b542ce3", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://flakehub.com/f/NixOS/nixos-hardware/0.1.%2A.tar.gz" + "owner": "NixOS", + "repo": "nixos-hardware", + "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1707956935, - "narHash": "sha256-ZL2TrjVsiFNKOYwYQozpbvQSwvtV/3Me7Zwhmdsfyu4=", - "rev": "a4d4fe8c5002202493e87ec8dbc91335ff55552c", - "revCount": 584422, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.584422%2Brev-a4d4fe8c5002202493e87ec8dbc91335ff55552c/018dad59-c2e8-7e35-bb7c-808d295bb34a/source.tar.gz" + "lastModified": 1681001314, + "narHash": "sha256-5sDnCLdrKZqxLPK4KA8+f4A3YKO/u6ElpMILvX0g72c=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "367c0e1086a4eb4502b24d872cea2c7acdd557f4", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz" + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" } }, "nixpkgs-stable": { @@ -663,17 +665,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1681001314, - "narHash": "sha256-5sDnCLdrKZqxLPK4KA8+f4A3YKO/u6ElpMILvX0g72c=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "367c0e1086a4eb4502b24d872cea2c7acdd557f4", + "lastModified": 1707956935, + "narHash": "sha256-ZL2TrjVsiFNKOYwYQozpbvQSwvtV/3Me7Zwhmdsfyu4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a4d4fe8c5002202493e87ec8dbc91335ff55552c", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" } }, "nmd": { @@ -709,45 +711,15 @@ "type": "github" } }, - "nvim-config": { - "inputs": { - "flake-schemas": [ - "flake-schemas" - ], - "home-manager": [ - "home-manager" - ], - "neovim-nightly": "neovim-nightly", - "nixneovim": "nixneovim", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1707972311, - "narHash": "sha256-vbDgWhmGuw6x1WTbdlroNG6ufWq7qsCI/hCsvs9FxG4=", - "owner": "jalil-salame", - "repo": "nvim-config", - "rev": "2a106ae6aaa425a3841aecb6f882b45bc2747102", - "type": "github" - }, - "original": { - "owner": "jalil-salame", - "repo": "nvim-config", - "type": "github" - } - }, "poetry2nix": { "inputs": { "flake-utils": [ - "nvim-config", "nixneovim", "nixneovimplugins", "flake-utils" ], "nix-github-actions": "nix-github-actions", "nixpkgs": [ - "nvim-config", "nixneovim", "nixneovimplugins", "nixpkgs" @@ -794,12 +766,12 @@ "root": { "inputs": { "audiomenu": "audiomenu", - "flake-schemas": "flake-schemas", "home-manager": "home-manager", "jpassmenu": "jpassmenu", + "neovim-nightly": "neovim-nightly", + "nixneovim": "nixneovim", "nixos-hardware": "nixos-hardware", - "nixpkgs": "nixpkgs", - "nvim-config": "nvim-config", + "nixpkgs": "nixpkgs_2", "pre-commit-hooks": "pre-commit-hooks", "stylix": "stylix" } diff --git a/flake.nix b/flake.nix index 27c0afa..b43a837 100644 --- a/flake.nix +++ b/flake.nix @@ -8,29 +8,27 @@ inputs.stylix.inputs.nixpkgs.follows = "nixpkgs"; inputs.stylix.inputs.home-manager.follows = "home-manager"; - inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; inputs.jpassmenu.url = "github:jalil-salame/jpassmenu"; inputs.jpassmenu.inputs.nixpkgs.follows = "nixpkgs"; - inputs.jpassmenu.inputs.flake-schemas.follows = "flake-schemas"; inputs.audiomenu.url = "github:jalil-salame/audiomenu"; inputs.audiomenu.inputs.nixpkgs.follows = "nixpkgs"; - inputs.audiomenu.inputs.flake-schemas.follows = "flake-schemas"; - inputs.nvim-config.url = "github:jalil-salame/nvim-config"; - inputs.nvim-config.inputs.nixpkgs.follows = "nixpkgs"; - inputs.nvim-config.inputs.home-manager.follows = "home-manager"; - inputs.nvim-config.inputs.flake-schemas.follows = "flake-schemas"; + inputs.nixneovim.url = "github:NixNeovim/NixNeovim"; + inputs.nixneovim.inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixneovim.inputs.home-manager.follows = "home-manager"; # WARN: Flakehub is outdated (39 days out of date) # inputs.home-manager.url = "https://flakehub.com/f/nix-community/home-manager/0.1.*.tar.gz"; inputs.home-manager.url = "github:nix-community/home-manager"; inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz"; + inputs.nixos-hardware.url = "github:NixOS/nixos-hardware"; - inputs.nixos-hardware.url = "https://flakehub.com/f/NixOS/nixos-hardware/0.1.*.tar.gz"; + inputs.neovim-nightly.url = "github:nix-community/neovim-nightly-overlay"; + inputs.neovim-nightly.inputs.nixpkgs.follows = "nixpkgs"; inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; @@ -38,7 +36,6 @@ # Flake outputs that other flakes can use outputs = { self - , flake-schemas , nixpkgs , stylix , home-manager @@ -46,7 +43,8 @@ , pre-commit-hooks , jpassmenu , audiomenu - , nvim-config + , nixneovim + , neovim-nightly }: let inherit (nixpkgs) lib; @@ -60,9 +58,6 @@ doc = forEachSupportedSystem ({ pkgs, system }: import ./docs { inherit pkgs lib; }); in { - # Schemas tell Nix about the structure of your flake's outputs - inherit (flake-schemas) schemas; - checks = forEachSupportedSystem ({ pkgs, system }: { pre-commit-check = pre-commit-hooks.lib.${system}.run { src = builtins.path { path = ./.; name = "configuration.nix"; }; @@ -75,8 +70,8 @@ # Provide necessary overlays overlays = { - nixneovim = nvim-config.overlays.nixneovim; - neovim-nightly = nvim-config.overlays.neovim-nightly; + nixneovim = nixneovim.overlays.default; + neovim-nightly = neovim-nightly.overlays.default; jpassmenu = jpassmenu.overlays.default; audiomenu = audiomenu.overlays.default; }; @@ -128,6 +123,10 @@ nixosModules = let + nvim-config.imports = [ + nixneovim.nixosModules.homeManager + ./nvim + ]; overlays = builtins.attrValues self.overlays; homeManagerModuleSandalone = import ./home { inherit overlays nvim-config stylix; }; homeManagerModuleNixOS = import ./home { inherit overlays nvim-config; }; diff --git a/home/default.nix b/home/default.nix index ccaae87..2c709f6 100644 --- a/home/default.nix +++ b/home/default.nix @@ -7,7 +7,7 @@ in imports = [ # Apply overlays { nixpkgs = { inherit overlays; }; } - nvim-config.nixosModules.default + nvim-config ./options.nix ./gui ./users.nix diff --git a/nvim/augroups.nix b/nvim/augroups.nix new file mode 100644 index 0000000..edfe0cc --- /dev/null +++ b/nvim/augroups.nix @@ -0,0 +1,93 @@ +{ + highlightOnYank.name = "highlightOnYank"; + highlightOnYank.autocmds = [ + { + event = "TextYankPost"; + pattern = "*"; + luaCallback = '' + vim.highlight.on_yank { + higroup = ( + vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch' + ), + timeout = 200, + } + ''; + } + ]; + + runLinter.name = "runLinter"; + runLinter.autocmds = [ + { + event = "BufWritePost"; + pattern = "*"; + luaCallback = '' + require("lint").try_lint() + ''; + } + ]; + + restoreCursorPosition.name = "restoreCursorPosition"; + restoreCursorPosition.autocmds = [ + { + event = "BufReadPost"; + pattern = "*"; + luaCallback = '' + if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then + vim.cmd [[execute "normal! g'\""]] + end + ''; + } + ]; + + lspConfig.name = "lspConfig"; + lspConfig.autocmds = [ + { + event = "LspAttach"; + pattern = "*"; + luaCallback = + let + opts = "noremap = true, buffer = bufnr"; + in + '' + local bufnr = opts.buf + local client = vim.lsp.get_client_by_id(opts.data.client_id) + local capabilities = client.server_capabilities + -- Set Omnifunc if supported + if capabilities.completionProvider then + vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc" + end + -- Enable inlay hints if supported + if capabilities.inlayHintProvider then + vim.lsp.inlay_hint.enable(bufnr, true) + end + vim.keymap.set('n', -- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless + 'ht', + function() + vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled()) + end, + { desc = '[H]ints [T]oggle', ${opts} } + ) + -- Enable hover if supported + if capabilities.hoverProvider then + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', ${opts} }) + end + -- Enable rename if supported + if capabilities.renameProvider then + vim.keymap.set('n', 'r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} }) + end + -- Enable code actions if supported + if capabilities.codeActionProvider then + vim.keymap.set({ 'n', 'v' }, 'fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} }) + end + -- Enable formatting if supported + if capabilities.documentFormattingProvider then + vim.keymap.set('n', 'w', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Buffer', ${opts} }) + end + -- Other keybinds + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} }) + vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} }) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} }) + ''; + } + ]; +} diff --git a/nvim/default.nix b/nvim/default.nix new file mode 100644 index 0000000..4828531 --- /dev/null +++ b/nvim/default.nix @@ -0,0 +1,90 @@ +{ pkgs, ... }: { + + programs.nixneovim = { + enable = true; + package = pkgs.neovim-nightly; + defaultEditor = true; + colorschemes.gruvbox-nvim = { + enable = true; + bold = true; + transparentBg = true; + trueColor = true; + }; + globals.mapleader = " "; + options = import ./options.nix; + plugins = import ./plugins; + mappings = import ./mappings.nix; + augroups = import ./augroups.nix; + extraPlugins = builtins.attrValues { + inherit (pkgs.vimExtraPlugins) dressing-nvim rustaceanvim idris2-nvim nui-nvim nvim-lint; + inherit (pkgs.vimPlugins) lualine-lsp-progress nvim-web-devicons FTerm-nvim cmp-cmdline formatter-nvim; + }; + # Formatting + extraPackages = builtins.attrValues { + # Formatters + inherit (pkgs) stylua shfmt taplo yamlfmt alejandra; + }; + extraLuaPreConfig = '' + -- Lua Pre Config + if vim.fn.has 'termguicolors' then + -- Enable RGB colors + vim.g.termguicolors = true + end + + -- Useful function + local has_words_before = function() + -- unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil + end + -- END: Lua Pre Config + ''; + extraLuaPostConfig = '' + do -- Setup cmp-cmdline + local cmp = require "cmp" + cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources { {name = "rg" }, { name = "buffer" } }, + }) + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) + }) + end + + do -- Setup dressing.nvim + -- require("dressing").setup() + end + + do -- Setup formatter.nvim + -- local util = require "formatter.util" + require("formatter").setup { + logging = true, + log_level = vim.log.levels.WARN, + ["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace }, + -- Filetype Formatting + c = { require("formatter.filetypes.c").clangformat }, + sh = { require("formatter.filetypes.sh").shfmt }, + cpp = { require("formatter.filetypes.cpp").clangformat }, + lua = { require("formatter.filetypes.lua").stylua }, + nix = { require("formatter.filetypes.nix").alejandra }, + zig = { require("formatter.filetypes.zig").zigfmt }, + rust = { require("formatter.filetypes.rust").rustfmt }, + toml = { require("formatter.filetypes.toml").taplo }, + yaml = { require("formatter.filetypes.yaml").yamlfmt }, + } + end + + do -- Setup idris2-nvim + require("idris2").setup { } + end + + do -- Setup nvim-lint + require("lint").linters_by_ft = { + latex = { "chktex", "typos" }, + } + end + ''; + }; +} diff --git a/nvim/mappings.nix b/nvim/mappings.nix new file mode 100644 index 0000000..df41583 --- /dev/null +++ b/nvim/mappings.nix @@ -0,0 +1,91 @@ +{ + # Quickfix + normal."qo" = { + action = "'Copen'"; + desc = "Quickfix Open"; + }; + normal."qq" = { + action = "'cclose'"; + desc = "Quickfix Quit"; + }; + normal."qj" = { + action = "'cnext'"; + desc = "Quickfix next [J]"; + }; + normal."qk" = { + action = "'cprev'"; + desc = "Quickfix previous [K]"; + }; + # Open or create file + normal."gf" = { + action = "'e '"; + desc = "Go to File"; + }; + # Keep Selection when indenting + visualOnly.">" = { + action = "'>gv'"; + desc = "Indent Selection"; + }; + visualOnly."<" = { + action = "'dj" = { + action = "vim.diagnostic.goto_next"; + desc = "Diagnostics next [J]"; + }; + normal."dk" = { + action = "vim.diagnostic.goto_prev"; + desc = "Diagnostics previous [K]"; + }; + normal."xx" = { + action = "require('trouble').toggle"; + desc = "Toggle trouble"; + }; + normal."xw" = { + action = "function() require('trouble').toggle('workspace_diagnostics') end"; + desc = "Toggle Workspace trouble"; + }; + normal."xd" = { + action = "function() require('trouble').toggle('document_diagnostics') end"; + desc = "Toggle Document trouble"; + }; + normal."xq" = { + action = "function() require('trouble').toggle('quickfix') end"; + desc = "Toggle Quickfix trouble"; + }; + normal."xl" = { + action = "function() require('trouble').toggle('loclist') end"; + desc = "Toggle Loclist trouble"; + }; + normal."gR" = { + action = "function() require('trouble').toggle('lsp_references') end"; + desc = "Toggle lsp References trouble"; + }; + # Telescope + normal."ff" = { + action = "require('telescope.builtin').find_files"; + desc = "Find Files"; + }; + normal."fg" = { + action = "require('telescope.builtin').live_grep"; + desc = "Find Grep"; + }; + normal."fh" = { + action = "require('telescope.builtin').help_tags"; + desc = "Find Help"; + }; + normal."fb" = { + action = "require('telescope.builtin').buffers"; + desc = "Find Buffer"; + }; + normal."fd" = { + action = "require('telescope.builtin').diagnostics"; + desc = "Find Diagnostics"; + }; + normal."fq" = { + action = "require('telescope.builtin').quickfix"; + desc = "Find Quickfix"; + }; +} diff --git a/nvim/options.nix b/nvim/options.nix new file mode 100644 index 0000000..f4b1449 --- /dev/null +++ b/nvim/options.nix @@ -0,0 +1,22 @@ +{ + # Appearance + number = true; + relativenumber = true; + colorcolumn = "+1"; + cursorline = true; + wrap = false; + splitright = true; + # Tabs & indentation + smarttab = true; + autoindent = true; + smartindent = true; + # Search path + path = ".,/usr/include,**"; + wildmenu = true; + hlsearch = true; + incsearch = true; + ignorecase = true; # Search ignores cases + smartcase = true; # Unless it has a capital letter + # Enable local configuration :h 'exrc' + exrc = true; # safe since nvim 0.9 +} diff --git a/nvim/plugins/cmp.nix b/nvim/plugins/cmp.nix new file mode 100644 index 0000000..681990e --- /dev/null +++ b/nvim/plugins/cmp.nix @@ -0,0 +1,88 @@ +{ + enable = true; + # Snippets + snippet.luasnip.enable = true; + # Completion Sources + sources = { + buffer.enable = true; + buffer.groupIndex = 3; + calc.enable = true; + calc.groupIndex = 2; + conventionalcommits.enable = true; + conventionalcommits.groupIndex = 1; + # cmdline.enable = true; + crates.enable = true; + crates.groupIndex = 1; + digraphs.enable = true; + digraphs.groupIndex = 3; + # emoji.enable = true; + # fuzzy_buffer.enable = true; + # fuzzy_path.enable = true; + luasnip.enable = true; + luasnip.groupIndex = 1; + nvim_lsp.enable = true; + nvim_lsp.groupIndex = 1; + nvim_lsp_document_symbol.enable = true; + nvim_lsp_document_symbol.groupIndex = 1; + nvim_lsp_signature_help.enable = true; + nvim_lsp_signature_help.groupIndex = 1; + path.enable = true; + path.groupIndex = 2; + # rg.enable = true; + spell.enable = true; + spell.groupIndex = 2; + treesitter.enable = true; + treesitter.groupIndex = 2; + zsh.enable = true; + zsh.groupIndex = 1; + }; + # Menu Icons + formatting.format = "require('lspkind').cmp_format { mode = 'symbol', maxwidth = 50 }"; + mappingPresets = [ "insert" ]; + mapping = { + "" = { + modes = [ "i" "s" ]; + action = '' + function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end + ''; + }; + "" = { + modes = [ "i" "s" ]; + action = '' + function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end + ''; + }; + "" = '' + cmp.mapping(function(fallback) + if require("luasnip").choice_active() then + require("luasnip").next_choice() + else + fallback() + end + end) + ''; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete {}"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping.confirm { select = true }"; + }; +} diff --git a/nvim/plugins/default.nix b/nvim/plugins/default.nix new file mode 100644 index 0000000..d0b0e4d --- /dev/null +++ b/nvim/plugins/default.nix @@ -0,0 +1,17 @@ +{ + colorizer.enable = true; + colorizer.userDefaultOptions.names = false; # disable named colors (i.e. red) + gitsigns.enable = true; + lspconfig = import ./lspconfig.nix; + lspkind.enable = true; + lualine = import ./lualine.nix; + luasnip.enable = true; + luasnip.extraConfig = { update_events = "TextChanged,TextChangedI"; }; + nvim-cmp = import ./cmp.nix; + telescope.enable = true; + treesitter.enable = true; + treesitter.indent = true; + treesitter.incrementalSelection.enable = true; + treesitter-context.enable = true; + trouble.enable = true; +} diff --git a/nvim/plugins/lspconfig.nix b/nvim/plugins/lspconfig.nix new file mode 100644 index 0000000..6813b78 --- /dev/null +++ b/nvim/plugins/lspconfig.nix @@ -0,0 +1,19 @@ +{ + enable = true; + servers.bashls.enable = true; + servers.clangd.enable = true; + servers.html.enable = true; + # servers.lua-language-server.enable = true; + servers.jsonls.enable = true; + servers.nil.enable = true; + servers.ocamllsp.enable = true; + servers.pyright.enable = true; + servers.rnix-lsp.enable = true; + servers.ruff-lsp.enable = true; + # servers.rust-analyzer.enable = true; + # servers.serve_d.enable = true; + servers.taplo.enable = true; + servers.texlab.enable = true; + servers.typst-lsp.enable = true; + # servers.vimls.enable = true; +} diff --git a/nvim/plugins/lualine.nix b/nvim/plugins/lualine.nix new file mode 100644 index 0000000..14c88e5 --- /dev/null +++ b/nvim/plugins/lualine.nix @@ -0,0 +1,50 @@ +{ + enable = true; + theme = "gruvbox"; + sections = { + lualine_a = [ "mode" ]; + lualine_b = [ "filename" "branch" ]; + lualine_c = [ + { + lsp_progress = { + separators = { + component = " "; + progress = " | "; + percentage = { + pre = ""; + post = "%% "; + }; + title = { + pre = ""; + post = ": "; + }; + lsp_client_name = { + pre = "["; + post = "]"; + }; + spinner = { + pre = ""; + post = ""; + }; + message = { + pre = "("; + post = ")"; + commenced = "In Progress"; + completed = "Completed"; + }; + }; + display_components = [ "lsp_client_name" "spinner" "title" "percentage" "message" ]; + timer = { + progress_enddelay = 500; + spinner = 1000; + lsp_client_name_enddelay = 1000; + }; + spinner_symbols = [ "🌑 " "🌒 " "🌓 " "🌔 " "🌕 " "🌖 " "🌗 " "🌘 " ]; + }; + } + ]; + lualine_x = [ ]; + lualine_y = [ "encoding" "fileformat" "filetype" ]; + lualine_z = [ "location" ]; + }; +}