From 49e373fe9a07480d9ea683d81772c05ce5da2f32 Mon Sep 17 00:00:00 2001 From: iofq Date: Mon, 6 Oct 2025 22:52:22 -0500 Subject: [PATCH] remove unused nix code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit flake.lock: Update Flake lock file updates: • Updated input 'neovim-nightly-overlay': 'github:nix-community/neovim-nightly-overlay/b7b3632fab34541543373254c265da03c1d0f240?narHash=sha256-SDLZMha2miaChOBGBkQJlTtk2kvcB7WIVVZ2l0/9byc%3D' (2025-10-01) → 'github:nix-community/neovim-nightly-overlay/7ff73a295b0065bde2f8b43b31558136ca77bd98?narHash=sha256-39JFRb006AOsIcOq%2B03H3y6YcGyaphk1CW5DRi14cOE%3D' (2025-10-13) • Updated input 'neovim-nightly-overlay/flake-parts': 'github:hercules-ci/flake-parts/4524271976b625a4a605beefd893f270620fd751?narHash=sha256-%2BuWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw%3D' (2025-09-01) → 'github:hercules-ci/flake-parts/758cf7296bee11f1706a574c77d072b8a7baa881?narHash=sha256-wfG0S7pltlYyZTM%2BqqlhJ7GMw2fTF4mLKCIVhLii/4M%3D' (2025-10-01) • Updated input 'neovim-nightly-overlay/git-hooks': 'github:cachix/git-hooks.nix/54df955a695a84cd47d4a43e08e1feaf90b1fd9b?narHash=sha256-ytw7ROXaWZ7OfwHrQ9xvjpUWeGVm86pwnEd1QhzawIo%3D' (2025-09-17) → 'github:cachix/git-hooks.nix/cfc9f7bb163ad8542029d303e599c0f7eee09835?narHash=sha256-PTod9NG%2Bi3XbbnBKMl/e5uHDBYpwIWivQ3gOWSEuIEM%3D' (2025-10-03) • Updated input 'neovim-nightly-overlay/neovim-src': 'github:neovim/neovim/198c9e9bca7549cf7110be8c6f1df1c38d4e747f?narHash=sha256-oc1pPeoe8458X0r/Wum8CucVcJLlIp4mg%2B1HiOSVRgA%3D' (2025-09-30) → 'github:neovim/neovim/72b0bfa1fb7e897e5126aabae718a5480f466b9e?narHash=sha256-RnB%2BoJcP37YT9pjr1osUQtJc%2B1qcVyaaeSbiSyXwm1Y%3D' (2025-10-12) • Updated input 'neovim-nightly-overlay/nixpkgs': 'github:NixOS/nixpkgs/647e5c14cbd5067f44ac86b74f014962df460840?narHash=sha256-JVZl8NaVRYb0%2B381nl7LvPE%2BA774/dRpif01FKLrYFQ%3D' (2025-09-28) → 'github:NixOS/nixpkgs/362791944032cb532aabbeed7887a441496d5e6e?narHash=sha256-gKl2Gtro/LNf8P%2B4L3S2RsZ0G390ccd5MyXYrTdMCFE%3D' (2025-10-11) • Updated input 'neovim-nightly-overlay/treefmt-nix': 'github:numtide/treefmt-nix/5eda4ee8121f97b218f7cc73f5172098d458f1d1?narHash=sha256-ySNJ008muQAds2JemiyrWYbwbG%2BV7S5wg3ZVKGHSFu8%3D' (2025-09-24) → 'github:numtide/treefmt-nix/761ae7aff00907b607125b2f57338b74177697ed?narHash=sha256-gq9rdocpmRZCwLS5vsHozwB6b5nrOBDNc2kkEaTXHfg%3D' (2025-10-10) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/d48b56f4899ee1d5377291576284969c9e37acc2?narHash=sha256-7G5fSMPNVwWNlFpZLwvKB8PUOaqPzFQbrtZ7RAzg2nw%3D' (2025-10-01) → 'github:NixOS/nixpkgs/09c05674757a82f32b67f70f702e56c4901a3cdd?narHash=sha256-IzUhHp/jU06jBW6S%2Bd12AO3sgq5yehYVTCBH7J6re5c%3D' (2025-10-13) flake.lock: Update Flake lock file updates: • Updated input 'neovim-nightly-overlay/nixpkgs': 'github:NixOS/nixpkgs/362791944032cb532aabbeed7887a441496d5e6e?narHash=sha256-gKl2Gtro/LNf8P%2B4L3S2RsZ0G390ccd5MyXYrTdMCFE%3D' (2025-10-11) → follows 'nixpkgs' --- flake.lock | 95 +++---- flake.nix | 46 ++-- nix/mkNeovim.nix | 165 ++---------- nix/neovim-overlay.nix | 28 +- nvim/{ => after}/colors/iofq.lua | 0 nvim/{ => after}/ftplugin/go.lua | 0 nvim/{ => after}/ftplugin/php.lua | 0 nvim/{ => after}/lsp/gopls.lua | 0 nvim/{ => after}/lsp/lua_ls.lua | 0 .../lib => after/lua/iofq}/minidiff_jj.lua | 0 .../{lua/lib => after/lua/iofq}/snacks_jj.lua | 0 nvim/after/plugin/autocmd.lua | 139 ++++++++++ nvim/{ => after/plugin}/init.lua | 25 +- nvim/{lua => after/plugin}/mini.lua | 55 ++-- nvim/after/plugin/plugins.lua | 153 +++++++++++ nvim/lua/autocmd.lua | 97 ------- nvim/lua/keymaps.lua | 18 -- nvim/lua/plugins.lua | 253 ------------------ 18 files changed, 431 insertions(+), 643 deletions(-) rename nvim/{ => after}/colors/iofq.lua (100%) rename nvim/{ => after}/ftplugin/go.lua (100%) rename nvim/{ => after}/ftplugin/php.lua (100%) rename nvim/{ => after}/lsp/gopls.lua (100%) rename nvim/{ => after}/lsp/lua_ls.lua (100%) rename nvim/{lua/lib => after/lua/iofq}/minidiff_jj.lua (100%) rename nvim/{lua/lib => after/lua/iofq}/snacks_jj.lua (100%) create mode 100644 nvim/after/plugin/autocmd.lua rename nvim/{ => after/plugin}/init.lua (67%) rename nvim/{lua => after/plugin}/mini.lua (54%) create mode 100644 nvim/after/plugin/plugins.lua delete mode 100644 nvim/lua/autocmd.lua delete mode 100644 nvim/lua/keymaps.lua delete mode 100644 nvim/lua/plugins.lua diff --git a/flake.lock b/flake.lock index a89f66c..6e5f8e8 100644 --- a/flake.lock +++ b/flake.lock @@ -6,17 +6,14 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1757895736, - "narHash": "sha256-BBjs+YCOzgb6N2lew4vEmyS6s70y0z5xStKjGQaf55g=", - "owner": "iofq", - "repo": "dart.nvim", - "rev": "f059335a22811374d5a7e22c97889ea712db58d7", - "type": "github" + "lastModified": 1760318820, + "narHash": "sha256-3ETm+AZ/UEU0OYFSYviMSv/Ov4BN1cEsBH6KNGuTYS4=", + "path": "/home/e/dev/dart.nvim", + "type": "path" }, "original": { - "owner": "iofq", - "repo": "dart.nvim", - "type": "github" + "path": "/home/e/dev/dart.nvim", + "type": "path" } }, "flake-compat": { @@ -93,11 +90,11 @@ ] }, "locked": { - "lastModified": 1756770412, - "narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=", + "lastModified": 1759362264, + "narHash": "sha256-wfG0S7pltlYyZTM+qqlhJ7GMw2fTF4mLKCIVhLii/4M=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "4524271976b625a4a605beefd893f270620fd751", + "rev": "758cf7296bee11f1706a574c77d072b8a7baa881", "type": "github" }, "original": { @@ -198,11 +195,11 @@ ] }, "locked": { - "lastModified": 1758108966, - "narHash": "sha256-ytw7ROXaWZ7OfwHrQ9xvjpUWeGVm86pwnEd1QhzawIo=", + "lastModified": 1759523803, + "narHash": "sha256-PTod9NG+i3XbbnBKMl/e5uHDBYpwIWivQ3gOWSEuIEM=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "54df955a695a84cd47d4a43e08e1feaf90b1fd9b", + "rev": "cfc9f7bb163ad8542029d303e599c0f7eee09835", "type": "github" }, "original": { @@ -303,15 +300,17 @@ "git-hooks": "git-hooks_2", "hercules-ci-effects": "hercules-ci-effects", "neovim-src": "neovim-src", - "nixpkgs": "nixpkgs_2", + "nixpkgs": [ + "nixpkgs" + ], "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1759277111, - "narHash": "sha256-SDLZMha2miaChOBGBkQJlTtk2kvcB7WIVVZ2l0/9byc=", + "lastModified": 1760313895, + "narHash": "sha256-39JFRb006AOsIcOq+03H3y6YcGyaphk1CW5DRi14cOE=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "b7b3632fab34541543373254c265da03c1d0f240", + "rev": "7ff73a295b0065bde2f8b43b31558136ca77bd98", "type": "github" }, "original": { @@ -323,11 +322,11 @@ "neovim-src": { "flake": false, "locked": { - "lastModified": 1759210115, - "narHash": "sha256-oc1pPeoe8458X0r/Wum8CucVcJLlIp4mg+1HiOSVRgA=", + "lastModified": 1760312166, + "narHash": "sha256-RnB+oJcP37YT9pjr1osUQtJc+1qcVyaaeSbiSyXwm1Y=", "owner": "neovim", "repo": "neovim", - "rev": "198c9e9bca7549cf7110be8c6f1df1c38d4e747f", + "rev": "72b0bfa1fb7e897e5126aabae718a5480f466b9e", "type": "github" }, "original": { @@ -381,27 +380,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1759070547, - "narHash": "sha256-JVZl8NaVRYb0+381nl7LvPE+A774/dRpif01FKLrYFQ=", + "lastModified": 1760326837, + "narHash": "sha256-z+C6KRPRjwqEsTEAwUavapBWcbR7YOlQP91O+W5L1ek=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "647e5c14cbd5067f44ac86b74f014962df460840", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1759300078, - "narHash": "sha256-7G5fSMPNVwWNlFpZLwvKB8PUOaqPzFQbrtZ7RAzg2nw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d48b56f4899ee1d5377291576284969c9e37acc2", + "rev": "cfe6b045750c3aa5127817bc3f44f2909b1ee175", "type": "github" }, "original": { @@ -411,13 +394,13 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_3": { "locked": { - "lastModified": 1759381078, - "narHash": "sha256-gTrEEp5gEspIcCOx9PD8kMaF1iEmfBcTbO0Jag2QhQs=", + "lastModified": 1760038930, + "narHash": "sha256-Oncbh0UmHjSlxO7ErQDM3KM0A5/Znfofj2BSzlHLeVw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7df7ff7d8e00218376575f0acdcc5d66741351ee", + "rev": "0b4defa2584313f3b781240b29d61f6f9f7e0df3", "type": "github" }, "original": { @@ -430,11 +413,11 @@ "nvim-treesitter": { "flake": false, "locked": { - "lastModified": 1759376029, - "narHash": "sha256-Cu6Wg9SKJpYAkp8DPAXe4Rf9OSSWW2wNdmCkYtl//fw=", + "lastModified": 1760260935, + "narHash": "sha256-To/syCZPs7vKA0WkuBz7ZxCGT/wzj705QfxZng6Nsjo=", "owner": "nvim-treesitter", "repo": "nvim-treesitter", - "rev": "99bd52ba56a4b7c9a8cc50a6140180755e76fac6", + "rev": "0606c7a9dcaa5c5beee0b0f09043e9fdd1ba0a68", "type": "github" }, "original": { @@ -446,16 +429,16 @@ }, "nvim-treesitter-main": { "inputs": { - "nixpkgs": "nixpkgs_4", + "nixpkgs": "nixpkgs_3", "nvim-treesitter": "nvim-treesitter", "nvim-treesitter-textobjects": "nvim-treesitter-textobjects" }, "locked": { - "lastModified": 1759559567, - "narHash": "sha256-cNu8MIRumBeW1HJK8c8IM6ge1yalz4xS5j5RCDbhf0Y=", + "lastModified": 1760324917, + "narHash": "sha256-ZlVGaUbxHf4DNR4GWhF1mvlMhP8IBbwF0g8WO1SL+Yw=", "owner": "iofq", "repo": "nvim-treesitter-main", - "rev": "1f19cc0a907328d8dbf467ee9fe216277628d366", + "rev": "da2262419eb66cfa426aa62ccf1fc8fdea33b4a0", "type": "github" }, "original": { @@ -487,7 +470,7 @@ "flake-utils": "flake-utils_2", "gen-luarc": "gen-luarc", "neovim-nightly-overlay": "neovim-nightly-overlay", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_2", "nvim-treesitter-main": "nvim-treesitter-main" } }, @@ -529,11 +512,11 @@ ] }, "locked": { - "lastModified": 1758728421, - "narHash": "sha256-ySNJ008muQAds2JemiyrWYbwbG+V7S5wg3ZVKGHSFu8=", + "lastModified": 1760120816, + "narHash": "sha256-gq9rdocpmRZCwLS5vsHozwB6b5nrOBDNc2kkEaTXHfg=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "5eda4ee8121f97b218f7cc73f5172098d458f1d1", + "rev": "761ae7aff00907b607125b2f57338b74177697ed", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index a2231e4..ed8d02c 100644 --- a/flake.nix +++ b/flake.nix @@ -4,27 +4,23 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/master"; flake-utils.url = "github:numtide/flake-utils"; - neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay"; + neovim-nightly-overlay = { + url = "github:nix-community/neovim-nightly-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; gen-luarc = { url = "github:mrcjkb/nix-gen-luarc-json"; inputs.nixpkgs.follows = "nixpkgs"; }; dart = { - url = "github:iofq/dart.nvim"; + url = "path:/home/e/dev/dart.nvim"; }; nvim-treesitter-main = { url = "github:iofq/nvim-treesitter-main"; }; - # Add bleeding-edge plugins here. - # They can be updated with `nix flake update` (make sure to commit the generated flake.lock) - # wf-nvim = { - # url = "github:Cassin01/wf.nvim"; - # flake = false; - # }; }; outputs = inputs@{ - self, nixpkgs, flake-utils, ... @@ -34,20 +30,28 @@ # This is where the Neovim derivation is built. neovim-overlay = import ./nix/neovim-overlay.nix { inherit inputs; }; + finalOverlays = [ + inputs.neovim-nightly-overlay.overlays.default + inputs.nvim-treesitter-main.overlays.default + (final: prev: { + vimPlugins = prev.vimPlugins.extend ( + f: p: { + nvim-treesitter = p.nvim-treesitter.withAllGrammars; + nvim-treesitter-textobjects = p.nvim-treesitter-textobjects.overrideAttrs { + dependencies = [ f.nvim-treesitter ]; + }; + } + ); + }) + neovim-overlay + ]; in flake-utils.lib.eachSystem systems ( system: let pkgs = import nixpkgs { inherit system; - config.allowUnfree = true; - overlays = [ - inputs.neovim-nightly-overlay.overlays.default - inputs.nvim-treesitter-main.overlays.default - neovim-overlay - # This adds a function can be used to generate a .luarc.json - # containing the Neovim API all plugins in the workspace directory. - # The generated file can be symlinked in the devShell's shellHook. + overlays = finalOverlays ++ [ inputs.gen-luarc.overlays.default ]; }; @@ -55,16 +59,13 @@ name = "nvim-devShell"; buildInputs = with pkgs; [ lua-language-server - nil + nixd stylua luajitPackages.luacheck - nvim-dev ]; shellHook = '' # symlink the .luarc.json generated in the overlay ln -fs ${pkgs.nvim-luarc-json} .luarc.json - # allow quick iteration of lua configs - ln -Tfns $PWD/nvim ~/.config/nvim-dev ''; }; in @@ -73,7 +74,6 @@ default = nvim; nvim = pkgs.nvim-pkg; nvim-min = pkgs.nvim-min-pkg; - nvim-dev = pkgs.nvim-dev; }; devShells = { default = shell; @@ -81,6 +81,6 @@ } ) // { - overlays.default = final: prev: (neovim-overlay final prev); + overlays.default = nixpkgs.lib.composeManyExtensions finalOverlays; }; } diff --git a/nix/mkNeovim.nix b/nix/mkNeovim.nix index 1ba7e54..83baf98 100644 --- a/nix/mkNeovim.nix +++ b/nix/mkNeovim.nix @@ -1,150 +1,23 @@ -# Function for creating a Neovim derivation +{ pkgs, lib }: { - pkgs, - lib, - stdenv, - # Set by the overlay to ensure we use a compatible version of `wrapNeovimUnstable` - pkgs-wrapNeovim ? pkgs, -}: -with lib; -{ - # NVIM_APPNAME - Defaults to 'nvim' if not set. - # If set to something else, this will also rename the binary. - appName ? "nvim", - # The Neovim package to wrap - neovim-unwrapped ? pkgs-wrapNeovim.neovim-unwrapped, - plugins ? [ ], # List of plugins - # List of dev plugins (will be bootstrapped) - useful for plugin developers - # { name = ; url = ; } - devPlugins ? [ ], - # Regexes for config files to ignore, relative to the nvim directory. - # e.g. [ "^plugin/neogit.lua" "^ftplugin/.*.lua" ] - ignoreConfigRegexes ? [ ], - extraPackages ? [ ], # Extra runtime dependencies (e.g. ripgrep, ...) - # The below arguments can typically be left as their defaults - # Additional lua packages (not plugins), e.g. from luarocks.org. - # e.g. p: [p.jsregexp] - extraLuaPackages ? p: [ ], - extraPython3Packages ? p: [ ], # Additional python 3 packages - withPython3 ? false, # Build Neovim with Python 3 support? - withRuby ? false, # Build Neovim with Ruby support? - withNodeJs ? false, # Build Neovim with NodeJS support? - withSqlite ? true, # Add sqlite? This is a dependency for some plugins - # You probably don't want to create vi or vim aliases - # if the appName is something different than "nvim" - viAlias ? appName == "nvim", # Add a "vi" binary to the build output as an alias? - vimAlias ? appName == "nvim", # Add a "vim" binary to the build output as an alias? - wrapRc ? true, + plugins ? [ ], + packages ? [ ], }: let - # This is the structure of a plugin definition. - # Each plugin in the `plugins` argument list can also be defined as this attrset - defaultPlugin = { - plugin = null; # e.g. nvim-lspconfig - config = null; # plugin config - # If `optional` is set to `false`, the plugin is installed in the 'start' packpath - # set to `true`, it is installed in the 'opt' packpath, and can be lazy loaded with - # ':packadd! {plugin-name} - optional = false; - runtime = { }; - }; - - externalPackages = extraPackages ++ (optionals withSqlite [ pkgs.sqlite ]); - - # Map all plugins to an attrset { plugin = ; config = ; optional = ; ... } - - # This nixpkgs util function creates an attrset - # that pkgs.wrapNeovimUnstable uses to configure the Neovim build. - neovimConfig = pkgs-wrapNeovim.neovimUtils.makeNeovimConfig { - inherit - extraPython3Packages - withPython3 - withRuby - withNodeJs - viAlias - vimAlias - ; - - plugins = (pkgs.neovimUtils.normalizePlugins plugins); - }; - - packDir = pkgs.neovimUtils.packDir { - iofq = pkgs.neovimUtils.normalizedPluginsToVimPackage (pkgs.neovimUtils.normalizePlugins plugins); - }; - - nvimRtp = stdenv.mkDerivation { - name = "nvim-rtp"; - src = ../nvim; - - installPhase = '' - mkdir -p $out/ - cp -r . $out/ - ''; - }; - - # The final init.lua content that we pass to the Neovim wrapper. - # It wraps the user init.lua, prepends the lua lib directory to the RTP - # and prepends the nvim and after directory to the RTP - initLua = '' - vim.opt.rtp:prepend('${nvimRtp}') - '' - + builtins.readFile ../nvim/init.lua; - - # Add arguments to the Neovim wrapper script - extraMakeWrapperArgs = builtins.concatStringsSep " " ( - # Set the NVIM_APPNAME environment variable - (optional ( - appName != "nvim" && appName != null && appName != "" - ) ''--set NVIM_APPNAME "${appName}"'') - # Add external packages to the PATH - ++ (optional (externalPackages != [ ]) ''--prefix PATH : "${makeBinPath externalPackages}"'') - # Set the LIBSQLITE_CLIB_PATH if sqlite is enabled - ++ (optional withSqlite ''--set LIBSQLITE_CLIB_PATH "${pkgs.sqlite.out}/lib/libsqlite3.so"'') - # Set the LIBSQLITE environment variable if sqlite is enabled - ++ (optional withSqlite ''--set LIBSQLITE "${pkgs.sqlite.out}/lib/libsqlite3.so"'') - ); - - luaPackages = neovim-unwrapped.lua.pkgs; - resolvedExtraLuaPackages = extraLuaPackages luaPackages; - - # Native Lua libraries - extraMakeWrapperLuaCArgs = - optionalString (resolvedExtraLuaPackages != [ ]) - ''--suffix LUA_CPATH ";" "${ - concatMapStringsSep ";" luaPackages.getLuaCPath resolvedExtraLuaPackages - }"''; - - # Lua libraries - extraMakeWrapperLuaArgs = - optionalString (resolvedExtraLuaPackages != [ ]) - ''--suffix LUA_PATH ";" "${ - concatMapStringsSep ";" luaPackages.getLuaPath resolvedExtraLuaPackages - }"''; - - # wrapNeovimUnstable is the nixpkgs utility function for building a Neovim derivation. - neovim-wrapped = pkgs-wrapNeovim.wrapNeovimUnstable neovim-unwrapped ( - neovimConfig - // { - luaRcContent = initLua; - wrapperArgs = - escapeShellArgs neovimConfig.wrapperArgs - + " " - + extraMakeWrapperArgs - + " " - + extraMakeWrapperLuaCArgs - + " " - + extraMakeWrapperLuaArgs; - wrapRc = wrapRc; - } - ); - - isCustomAppName = appName != null && appName != "nvim"; + finalPlugins = plugins ++ [ + (pkgs.vimUtils.buildVimPlugin { + pname = "iofq-nvim"; + src = lib.cleanSource ../nvim; + version = "0.1"; + doCheck = false; + }) + ]; + wrapperArgs = ''--prefix PATH : "${lib.makeBinPath packages}"''; in -neovim-wrapped.overrideAttrs (oa: { - buildPhase = - oa.buildPhase - # If a custom NVIM_APPNAME has been set, rename the `nvim` binary - + lib.optionalString isCustomAppName '' - mv $out/bin/nvim $out/bin/${lib.escapeShellArg appName} - ''; -}) +pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped { + inherit wrapperArgs; + plugins = finalPlugins; + withPython3 = false; + withRuby = false; + vimAlias = true; +} diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 5a2684e..430c345 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -1,21 +1,20 @@ # This overlay, when applied to nixpkgs, adds the final neovim derivation to nixpkgs. { inputs }: final: prev: -with final.pkgs.lib; let - mkNeovim = prev.callPackage ./mkNeovim.nix { pkgs-wrapNeovim = prev; }; + mkNeovim = prev.callPackage ./mkNeovim.nix { pkgs = final; }; dart-nvim = inputs.dart.packages.x86_64-linux.default; - plugins = with final.vimPlugins; [ + plugins = with prev.vimPlugins; [ blink-cmp blink-ripgrep-nvim conform-nvim dart-nvim - diffview-nvim mini-nvim + nvim-autopairs nvim-lint nvim-lspconfig - nvim-treesitter.withAllGrammars + nvim-treesitter nvim-treesitter-textobjects quicker-nvim refactoring-nvim @@ -23,12 +22,12 @@ let snacks-nvim ]; - basePackages = with final; [ + basePackages = with prev; [ ripgrep fd ]; # Extra packages that should be included on nixos but don't need to be bundled - extraPackages = with final; [ + extraPackages = with prev; [ # linters yamllint jq @@ -47,25 +46,14 @@ in { nvim-pkg = mkNeovim { inherit plugins; - extraPackages = basePackages ++ extraPackages; + packages = basePackages ++ extraPackages; }; nvim-min-pkg = mkNeovim { inherit plugins; - extraPackages = basePackages; + packages = basePackages; }; - # This is meant to be used within a devshell. - # Instead of loading the lua Neovim configuration from - # the Nix store, it is loaded from $XDG_CONFIG_HOME/nvim-dev - nvim-dev = mkNeovim { - inherit plugins; - extraPackages = basePackages ++ extraPackages; - appName = "nvim-dev"; - wrapRc = false; - }; - - # This can be symlinked in the devShell's shellHook nvim-luarc-json = final.mk-luarc-json { inherit plugins; }; diff --git a/nvim/colors/iofq.lua b/nvim/after/colors/iofq.lua similarity index 100% rename from nvim/colors/iofq.lua rename to nvim/after/colors/iofq.lua diff --git a/nvim/ftplugin/go.lua b/nvim/after/ftplugin/go.lua similarity index 100% rename from nvim/ftplugin/go.lua rename to nvim/after/ftplugin/go.lua diff --git a/nvim/ftplugin/php.lua b/nvim/after/ftplugin/php.lua similarity index 100% rename from nvim/ftplugin/php.lua rename to nvim/after/ftplugin/php.lua diff --git a/nvim/lsp/gopls.lua b/nvim/after/lsp/gopls.lua similarity index 100% rename from nvim/lsp/gopls.lua rename to nvim/after/lsp/gopls.lua diff --git a/nvim/lsp/lua_ls.lua b/nvim/after/lsp/lua_ls.lua similarity index 100% rename from nvim/lsp/lua_ls.lua rename to nvim/after/lsp/lua_ls.lua diff --git a/nvim/lua/lib/minidiff_jj.lua b/nvim/after/lua/iofq/minidiff_jj.lua similarity index 100% rename from nvim/lua/lib/minidiff_jj.lua rename to nvim/after/lua/iofq/minidiff_jj.lua diff --git a/nvim/lua/lib/snacks_jj.lua b/nvim/after/lua/iofq/snacks_jj.lua similarity index 100% rename from nvim/lua/lib/snacks_jj.lua rename to nvim/after/lua/iofq/snacks_jj.lua diff --git a/nvim/after/plugin/autocmd.lua b/nvim/after/plugin/autocmd.lua new file mode 100644 index 0000000..18af3e9 --- /dev/null +++ b/nvim/after/plugin/autocmd.lua @@ -0,0 +1,139 @@ +local cmd = vim.api.nvim_create_autocmd +-- open :h in buffers +cmd('FileType', { + group = vim.api.nvim_create_augroup('help', { clear = true }), + pattern = 'help', + callback = function(_) + vim.cmd.only() + vim.keymap.set('n', 'q', vim.cmd.bdelete, { noremap = true }) + vim.bo.buflisted = false + end, +}) + +-- resize splits if window got resized +cmd({ 'VimResized' }, { + group = vim.api.nvim_create_augroup('resize_splits', { clear = true }), + callback = function() + vim.cmd('tabdo wincmd =') + vim.cmd('tabnext ' .. vim.fn.tabpagenr()) + end, +}) + +-- Check if we need to reload the file when it changed +cmd({ 'FocusGained', 'TermClose', 'TermLeave' }, { + group = vim.api.nvim_create_augroup('check_reload', { clear = true }), + callback = function() + if vim.o.buftype ~= 'nofile' then + vim.cmd('checktime') + end + end, +}) + +-- Configure difftool buffers +vim.api.nvim_create_autocmd('FileType', { + pattern = 'qf', + group = vim.api.nvim_create_augroup('difftool', { clear = true }), + callback = function(event) + local function exec(fmt, str) + os.execute(string.format(fmt, str)) + end + local function refresh() + local qf = vim.fn.getqflist() + + local entry = qf[1] + if not entry or not entry.user_data.diff then + return nil + end + + local ns = vim.api.nvim_create_namespace('nvim.difftool.hl') + vim.api.nvim_buf_clear_namespace(event.buf, ns, 0, -1) + for i, item in ipairs(qf) do + local path = vim.fn.fnamemodify(item.user_data.right, ':t') + local hl = 'Added' + if + exec('git diff --quiet -- %s', path) ~= 0 + or exec('git ls-files --error-unmatch -- %s > /dev/null 2>&1', path) ~= 0 + then + hl = 'Removed' + end + vim.hl.range(event.buf, ns, hl, { i - 1, 0 }, { i - 1, -1 }) + end + end + vim.keymap.set('n', 'gh', function() + local idx = vim.api.nvim_win_get_cursor(0)[1] + local qf = vim.fn.getqflist() + local filename = qf[idx].user_data.rel + + if exec('git diff --quiet --cached -- %s', filename) ~= 0 then + exec('git restore --quiet --staged -- %s', filename) + else + exec('git add -- %s', filename) + end + refresh() + end) + vim.schedule(refresh) + end, +}) + +-- Init treesitter +cmd('FileType', { + group = vim.api.nvim_create_augroup('treesitter', { clear = true }), + callback = function(event) + local bufnr = event.buf + + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + pcall(vim.treesitter.start, bufnr) + + vim.keymap.set({ 'v', 'n' }, ']]', function() + require('nvim-treesitter-textobjects.move').goto_next_start('@function.outer', 'textobjects') + end, { buffer = bufnr }) + vim.keymap.set({ 'v', 'n' }, '[[', function() + require('nvim-treesitter-textobjects.move').goto_previous_start('@function.outer', 'textobjects') + end, { buffer = bufnr }) + vim.keymap.set({ 'v', 'n' }, ']a', function() + require('nvim-treesitter-textobjects.move').goto_next_start('@parameter.inner', 'textobjects') + end, { buffer = bufnr }) + vim.keymap.set({ 'v', 'n' }, '[a', function() + require('nvim-treesitter-textobjects.move').goto_previous_start('@parameter.inner', 'textobjects') + end, { buffer = bufnr }) + vim.keymap.set({ 'v', 'n' }, ']A', function() + require('nvim-treesitter-textobjects.swap').swap_next('@parameter.inner') + end, { buffer = bufnr }) + vim.keymap.set({ 'v', 'n' }, '[A', function() + require('nvim-treesitter-textobjects.swap').swap_previous('@parameter.inner') + end, { buffer = bufnr }) + end, +}) + +-- Init LSP +cmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if not client then + return + end + vim.keymap.set('n', 'gO', function() + Snacks.picker.lsp_symbols { focus = 'list' } + end, { buffer = ev.buf }) + + vim.keymap.set('n', 'grh', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) + end, { buffer = ev.buf }) + vim.keymap.set('n', 'grl', vim.lsp.codelens.run, { buffer = ev.buf }) + + vim.keymap.set('n', 'gre', vim.diagnostic.setloclist, { buffer = ev.buf }) + vim.keymap.set('n', 'grE', vim.diagnostic.setqflist, { buffer = ev.buf }) + + -- Auto-refresh code lenses + if client:supports_method('textDocument/codeLens') or client.server_capabilities.codeLensProvider then + vim.lsp.codelens.refresh { bufnr = ev.buf } + cmd({ 'InsertLeave', 'TextChanged' }, { + callback = function() + vim.lsp.codelens.refresh { bufnr = ev.buf } + end, + buffer = ev.buf, + }) + end + end, +}) diff --git a/nvim/init.lua b/nvim/after/plugin/init.lua similarity index 67% rename from nvim/init.lua rename to nvim/after/plugin/init.lua index 708198b..b2afa6a 100644 --- a/nvim/init.lua +++ b/nvim/after/plugin/init.lua @@ -1,3 +1,5 @@ +vim.cmd('colorscheme iofq') + vim.g.mapleader = ' ' vim.opt.autowrite = true vim.opt.backspace = 'indent,eol,start' @@ -42,8 +44,21 @@ vim.lsp.enable { 'basedpyright', } -vim.cmd('colorscheme iofq') -require('keymaps') -require('autocmd') -require('mini') -require('plugins') +local map = vim.keymap.set +map('n', '\\t', function() -- Switch tab length on the fly + vim.o.tabstop = vim.o.tabstop == 8 and 2 or 2 * vim.o.tabstop + vim.notify('tabstop: ' .. vim.o.tabstop) +end) +map({ 'v', 'i' }, 'wq', 'l') +map('v', '<', '', '>gv') +map('n', 'n', 'nzz', { noremap = true }) +map('n', 'N', 'Nzz', { noremap = true }) +map('n', '', 'zz', { noremap = true }) +map('n', '', 'zz', { noremap = true }) +map('n', 'gq', vim.cmd.bdelete, { noremap = true }) +map('n', 'gQ', function() + vim.cmd('bufdo bdelete') +end, { noremap = true }) + +vim.cmd.packadd('nvim.difftool') diff --git a/nvim/lua/mini.lua b/nvim/after/plugin/mini.lua similarity index 54% rename from nvim/lua/mini.lua rename to nvim/after/plugin/mini.lua index b1810d5..c60ec00 100644 --- a/nvim/lua/mini.lua +++ b/nvim/after/plugin/mini.lua @@ -1,9 +1,7 @@ -require('mini.basics').setup { mappings = { windows = true } } -require('mini.icons').setup() +local map = vim.keymap.set vim.schedule(function() require('mini.align').setup() - require('mini.pairs').setup() require('mini.surround').setup() require('mini.splitjoin').setup { detect = { separator = '[,;\n]' } } @@ -12,19 +10,23 @@ vim.schedule(function() n_lines = 300, custom_textobjects = { i = require('mini.extra').gen_ai_spec.indent(), + b = require('mini.extra').gen_ai_spec.buffer(), a = ai.gen_spec.treesitter { a = '@parameter.outer', i = '@parameter.inner' }, f = ai.gen_spec.treesitter { a = '@function.outer', i = '@function.inner' }, }, } require('mini.git').setup() - vim.keymap.set('n', 'go', function() + map('n', 'gb', 'Git blame -- %') + map('n', 'go', function() return MiniGit.show_at_cursor() - end, { noremap = true, desc = 'git show at cursor' }) - vim.keymap.set('n', 'gb', 'Git blame -- %', { desc = 'git blame' }) + end) local jump = require('mini.jump2d') jump.setup { + mappings = { + start_jumping = 's', + }, view = { n_steps_ahead = 1, dim = true }, spotter = jump.gen_spotter.vimpattern(), } @@ -32,39 +34,42 @@ vim.schedule(function() local diff = require('mini.diff') diff.setup { source = { - require('lib.minidiff_jj').gen_source(), + require('iofq.minidiff_jj').gen_source(), diff.gen_source.git(), }, } - vim.keymap.set('n', 'gp', function() - MiniDiff.toggle_overlay(0) - end, { noremap = true, desc = 'git diff overlay' }) + map('n', 'gp', MiniDiff.toggle_overlay) - local files = require('mini.files') - files.setup { - mappings = { - go_in_plus = '', - }, + require('mini.files').setup { + mappings = { go_in_plus = '' }, windows = { preview = true, width_preview = 50, }, } - vim.keymap.set('n', 'nc', function() + map('n', 'nc', function() MiniFiles.open(vim.api.nvim_buf_get_name(0), false) -- open current buffer's dir - MiniFiles.reveal_cwd() - end, { desc = 'minifiles open' }) - - vim.keymap.set('n', '`', function() - local _, cur_entry_path = pcall(MiniFiles.get_fs_entry().path) - local cur_directory = vim.fs.dirname(cur_entry_path) - if cur_directory ~= '' then - vim.fn.chdir(cur_directory) - end end) + vim.api.nvim_create_autocmd('User', { + pattern = 'MiniFilesBufferCreate', + callback = function(args) + map('n', 'nc', function() + MiniFiles.synchronize() + MiniFiles.close() + end, { buffer = args.data.buf_id }) + map('n', '`', function() + local _, cur_entry_path = pcall(MiniFiles.get_fs_entry().path) + local cur_directory = vim.fs.dirname(cur_entry_path) + if cur_directory ~= '' then + vim.fn.chdir(cur_directory) + end + end, { buffer = args.data.buf_id }) + end, + }) -- pass file rename events to LSP vim.api.nvim_create_autocmd('User', { + group = vim.api.nvim_create_augroup('snacks_rename', { clear = true }), pattern = 'MiniFilesActionRename', callback = function(event) Snacks.rename.on_rename_file(event.data.from, event.data.to) diff --git a/nvim/after/plugin/plugins.lua b/nvim/after/plugin/plugins.lua new file mode 100644 index 0000000..58dae3e --- /dev/null +++ b/nvim/after/plugin/plugins.lua @@ -0,0 +1,153 @@ +local map = vim.keymap.set + +require('mini.basics').setup { mappings = { windows = true } } +require('mini.icons').setup() + +require('dart').setup { + tabline = { + icons = false, + label_marked_fg = 'cyan', + }, +} + +require('snacks').setup { + bigfile = { enabled = true }, + terminal = { enabled = true }, + indent = { enabled = true }, + input = { enabled = true }, + notifier = { enabled = true }, + styles = { notification = { wo = { wrap = true } } }, + picker = { + enabled = true, + matcher = { + frecency = true, + cwd_bonus = true, + }, + layout = 'ivy_split', + sources = { + grep = { hidden = true }, + lsp_symbols = { + filter = { default = true }, + layout = { + preset = 'left', + layout = { width = 90, min_width = 90 }, + }, + }, + smart = { + multi = { + 'buffers', + { source = 'files', hidden = true }, + { source = 'git_files', untracked = true }, + }, + }, + }, + }, +} + +map({ 'n', 't' }, '', Snacks.terminal.toggle) +map('n', 'ff', Snacks.picker.smart) +map('n', '', Snacks.picker.smart) +map('n', 'fa', Snacks.picker.grep) +map('n', 'f8', Snacks.picker.grep_word) +map('n', 'f?', Snacks.picker.pickers) +map('n', 'fu', Snacks.picker.undo) +map('n', 'fj', Snacks.picker.jumps) +map('n', 'f.', Snacks.picker.resume) +map('n', 'fb', Snacks.picker.buffers) +map('n', 'fq', Snacks.picker.qflist) +map('n', 'jf', require('iofq.snacks_jj').status) + +vim.schedule(function() + require('nvim-treesitter').setup() + require('nvim-treesitter-textobjects').setup() + require('render-markdown').setup() + require('nvim-autopairs').setup() + + require('refactoring').setup() + map('n', 'rr', require('refactoring').select_refactor) + map('n', 'rv', function() + require('refactoring').refactor('Inline Variable') + end) + + require('quicker').setup() + map('n', 'qf', function() + require('quicker').toggle { max_height = 20 } + end) + + require('conform').setup { + notify_no_formatters = false, + formatters_by_ft = { + json = { 'jq' }, + lua = { 'stylua' }, + python = { 'ruff' }, + nix = { 'nixfmt' }, + fish = { 'fish_indent' }, + ['*'] = { 'trim_whitespace' }, + }, + format_on_save = function(bufnr) + -- Disable with a global or buffer-local variable + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + return { timeout_ms = 1500, lsp_format = 'fallback' } + end, + } + map('n', '\\f', function() + vim.b.disable_autoformat = not vim.b.disable_autoformat + vim.notify(string.format('Buffer formatting disabled: %s', vim.b.disable_autoformat)) + end) + map('n', '\\F', function() + vim.g.disable_autoformat = not vim.g.disable_autoformat + vim.notify(string.format('Global formatting disabled: %s', vim.g.disable_autoformat)) + end) + + require('lint').linters_by_ft = { + docker = { 'hadolint' }, + yaml = { 'yamllint' }, + sh = { 'shellcheck' }, + go = { 'golangcilint' }, + ruby = { 'rubocop' }, + fish = { 'fish' }, + bash = { 'bash' }, + nix = { 'nix' }, + php = { 'php' }, + } + vim.api.nvim_create_autocmd({ 'BufWritePost' }, { + callback = function() + require('lint').try_lint(nil, { ignore_errors = true }) + end, + }) + + vim.treesitter.language.register('markdown', 'blink-cmp-documentation') + require('blink.cmp').setup { + enabled = function() + return not vim.tbl_contains({ 'snacks_picker_input' }, vim.bo.filetype) + end, + sources = { + default = { 'lsp', 'path', 'snippets', 'ripgrep', 'buffer' }, + providers = { + lsp = { fallbacks = {} }, -- include buffer even when LSP is active + path = { opts = { get_cwd = vim.fn.getcwd } }, -- use nvim pwd instead of current file pwd + ripgrep = { + module = 'blink-ripgrep', + name = 'rg', + score_offset = -10, + async = true, + }, + }, + }, + cmdline = { completion = { menu = { auto_show = true } } }, + completion = { + documentation = { auto_show = true }, + menu = { + draw = { + columns = { + { 'label', 'label_description', gap = 1 }, + { 'source_name', 'kind', gap = 1 }, + }, + }, + }, + }, + signature = { enabled = true, trigger = { show_on_insert = true } }, + } +end) diff --git a/nvim/lua/autocmd.lua b/nvim/lua/autocmd.lua deleted file mode 100644 index a5e566d..0000000 --- a/nvim/lua/autocmd.lua +++ /dev/null @@ -1,97 +0,0 @@ --- open :h in buffers -vim.api.nvim_create_autocmd('BufWinEnter', { - pattern = '*', - callback = function(event) - if vim.bo[event.buf].filetype == 'help' then - vim.cmd.only() - vim.keymap.set('n', 'q', vim.cmd.bdelete, { noremap = true, silent = true }) - vim.bo.buflisted = false - end - end, -}) - --- resize splits if window got resized -vim.api.nvim_create_autocmd({ 'VimResized' }, { - group = vim.api.nvim_create_augroup('resize_splits', { clear = true }), - callback = function() - local current_tab = vim.fn.tabpagenr() - vim.cmd('tabdo wincmd =') - vim.cmd('tabnext ' .. current_tab) - end, -}) - --- Check if we need to reload the file when it changed -vim.api.nvim_create_autocmd({ 'FocusGained', 'TermClose', 'TermLeave' }, { - group = vim.api.nvim_create_augroup('check_reload', { clear = true }), - callback = function() - if vim.o.buftype ~= 'nofile' then - vim.cmd('checktime') - end - end, -}) - --- Init treesitter -vim.api.nvim_create_autocmd('FileType', { - callback = function(event) - local bufnr = event.buf - - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" - pcall(vim.treesitter.start, bufnr) - - vim.keymap.set({'v','n'}, ']]', function() - require('nvim-treesitter-textobjects.move').goto_next_start('@function.outer', 'textobjects') - end, { buffer = bufnr, desc = 'next function def' }) - vim.keymap.set({'v','n'}, '[[', function() - require('nvim-treesitter-textobjects.move').goto_previous_start('@function.outer', 'textobjects') - end, { buffer = bufnr, desc = 'prev function def' }) - vim.keymap.set({'v','n'}, ']a', function() - require('nvim-treesitter-textobjects.move').goto_next_start('@parameter.inner', 'textobjects') - end, { buffer = bufnr, desc = 'next param def' }) - vim.keymap.set({'v','n'}, '[a', function() - require('nvim-treesitter-textobjects.move').goto_previous_start('@parameter.inner', 'textobjects') - end, { buffer = bufnr, desc = 'prev param def' }) - vim.keymap.set({'v','n'}, ']A', function() - require('nvim-treesitter-textobjects.swap').swap_next('@parameter.inner') - end, { buffer = bufnr, desc = 'swap next arg' }) - vim.keymap.set({'v','n'}, '[A', function() - require('nvim-treesitter-textobjects.swap').swap_previous('@parameter.inner') - end, { buffer = bufnr, desc = 'swap prev arg' }) - end, -}) - --- Init LSP -vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('UserLspConfig', {}), - callback = function(ev) - local client = vim.lsp.get_client_by_id(ev.data.client_id) - if not client then - return - end - vim.keymap.set('n', 'gO', function() - Snacks.picker.lsp_symbols { focus = 'list' } - end, { buffer = ev.buf, desc = 'LSP symbols' }) - - vim.keymap.set('n', 'grh', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) - end, { buffer = ev.buf, desc = 'LSP hints toggle' }) - vim.keymap.set('n', 'grl', vim.lsp.codelens.run, { buffer = ev.buf, desc = 'vim.lsp.codelens.run()' }) - - vim.keymap.set('n', 'gre', function() - vim.diagnostic.setloclist() - end, { buffer = ev.buf, desc = 'LSP buffer diagnostics' }) - vim.keymap.set('n', 'grE', function() - vim.diagnostic.setqflist() - end, { buffer = ev.buf, desc = 'LSP diagnostics' }) - - -- Auto-refresh code lenses - if client:supports_method('textDocument/codeLens') or client.server_capabilities.codeLensProvider then - vim.lsp.codelens.refresh { bufnr = ev.buf } - vim.api.nvim_create_autocmd({ 'InsertLeave', 'TextChanged' }, { - callback = function() - vim.lsp.codelens.refresh { bufnr = ev.buf } - end, - buffer = ev.buf, - }) - end - end, -}) diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua deleted file mode 100644 index 62c630c..0000000 --- a/nvim/lua/keymaps.lua +++ /dev/null @@ -1,18 +0,0 @@ --- Switch tab length on the fly -vim.keymap.set('n', '\\t', function() - vim.o.tabstop = vim.o.tabstop == 8 and 2 or 2 * vim.o.tabstop - vim.notify('tabstop: ' .. vim.o.tabstop) -end, { silent = true, desc = 'toggle tabstop' }) -vim.keymap.set({ 'v', 'i' }, 'wq', 'l', { noremap = true, silent = true }) -vim.keymap.set('v', '<', '', '>gv') -vim.keymap.set('n', 'n', 'nzz', { noremap = true }) -vim.keymap.set('n', 'N', 'Nzz', { noremap = true }) -vim.keymap.set('n', '', 'zz', { noremap = true }) -vim.keymap.set('n', '', 'zz', { noremap = true }) -vim.keymap.set('v', '', ":m '>+1gv=gv", { desc = 'move selection down' }) -vim.keymap.set('v', '', ":m '<-2gv=gv", { desc = 'move selection up' }) -vim.keymap.set('n', 'gq', vim.cmd.bdelete, { noremap = true, silent = true, desc = 'close buffer' }) -vim.keymap.set('n', 'gQ', function() - vim.cmd('bufdo bdelete') -end, { noremap = true, silent = true, desc = 'close all buffers' }) diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua deleted file mode 100644 index b00a3e4..0000000 --- a/nvim/lua/plugins.lua +++ /dev/null @@ -1,253 +0,0 @@ -require('dart').setup { - tabline = { - label_marked_fg = 'cyan', - }, -} - -require('snacks').setup { - bigfile = { enabled = true }, - terminal = { enabled = true }, - indent = { enabled = true }, - input = { enabled = true }, - notifier = { enabled = true }, - styles = { - notification = { - wo = { wrap = true }, - }, - }, - picker = { - enabled = true, - matcher = { - frecency = true, - cwd_bonus = true, - }, - layout = 'ivy_split', - sources = { - grep = { hidden = true }, - lsp_symbols = { - filter = { default = true }, - layout = 'left', - }, - smart = { - multi = { - { source = 'files', hidden = true }, - { source = 'git_files', untracked = true }, - }, - }, - }, - }, -} - -vim.keymap.set({ 'n', 't' }, '', function() - Snacks.terminal.toggle() -end, { desc = 'terminal open' }) - -vim.keymap.set('n', 'ff', function() - Snacks.picker.smart() -end, { desc = 'Fuzzy find smart' }) - -vim.keymap.set('n', 'fa', function() - Snacks.picker.grep() -end, { desc = 'Fuzzy find grep' }) - -vim.keymap.set('n', 'f8', function() - Snacks.picker.grep_word() -end, { desc = 'Fuzzy find grep word' }) - -vim.keymap.set('n', 'f?', function() - Snacks.picker.pickers() -end, { desc = 'See all pickers' }) - -vim.keymap.set('n', 'fu', function() - Snacks.picker.undo() -end, { desc = 'Pick undotree' }) - -vim.keymap.set('n', 'fj', function() - Snacks.picker.jumps() -end, { desc = 'Pick jumps' }) - -vim.keymap.set('n', 'f.', function() - Snacks.picker.resume() -end, { desc = 'Fuzzy find resume' }) - -vim.keymap.set('n', 'fb', function() - Snacks.picker.buffers() -end, { desc = 'Fuzzy find buffers' }) - -vim.keymap.set('n', 'fq', function() - Snacks.picker.qflist() -end, { desc = 'pick quickfix list' }) - -vim.keymap.set('n', 'jf', function() - require('lib.snacks_jj').status() -end, { desc = 'pick notifications' }) -vim.schedule(function() - require('nvim-treesitter').setup() - require('nvim-treesitter-textobjects').setup() - require('render-markdown').setup() - - require('refactoring').setup() - vim.keymap.set('n', 'rr', function() - require('refactoring').select_refactor() - end, { desc = 'Refactor' }) - vim.keymap.set('n', 'rv', function() - require('refactoring').refactor('Inline Variable') - end, { desc = 'Inline Variable' }) - - require('quicker').setup() - vim.keymap.set('n', 'qf', function() - require('quicker').toggle { max_height = 20 } - end, { desc = 'Toggle qflist' }) - - require('diffview').setup { - use_icons = false, - enhanced_diff_hl = true, - default_args = { - DiffviewOpen = { '--imply-local' }, - }, - view = { - merge_tool = { - layout = 'diff4_mixed', - disable_diagnostics = true, - }, - }, - keymaps = { - view = { - { { 'n' }, 'q', vim.cmd.DiffviewClose, { desc = 'Close Diffview' } }, - }, - file_panel = { - { { 'n' }, 'q', vim.cmd.DiffviewClose, { desc = 'Close Diffview' } }, - }, - file_history_panel = { - { { 'n' }, 'q', vim.cmd.DiffviewClose, { desc = 'Close Diffview' } }, - }, - }, - } - - vim.keymap.set('n', 'nb', vim.cmd.DiffviewOpen, { desc = 'diffview open' }) - vim.keymap.set('n', 'nH', vim.cmd.DiffviewFileHistory, { desc = 'diffview history' }) - vim.keymap.set('n', 'nh', 'DiffviewFileHistory %', { desc = 'diffview history' }) - - require('conform').setup { - notify_no_formatters = false, - formatters_by_ft = { - json = { 'jq' }, - lua = { 'stylua' }, - python = { 'ruff' }, - nix = { 'nixfmt' }, - fish = { 'fish_indent' }, - ['*'] = { 'trim_whitespace' }, - }, - format_on_save = function(bufnr) - -- Disable with a global or buffer-local variable - if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then - return - end - return { timeout_ms = 1500, lsp_format = 'fallback' } - end, - } - vim.keymap.set('n', '\\f', function() - vim.b.disable_autoformat = not vim.b.disable_autoformat - vim.notify(string.format('Buffer formatting disabled: %s', vim.b.disable_autoformat)) - end, { desc = 'toggle buffer formatting' }) - vim.keymap.set('n', '\\F', function() - vim.g.disable_autoformat = not vim.g.disable_autoformat - vim.notify(string.format('Global formatting disabled: %s', vim.g.disable_autoformat)) - end, { desc = 'toggle global formatting' }) - - require('lint').linters_by_ft = { - docker = { 'hadolint' }, - yaml = { 'yamllint' }, - sh = { 'shellcheck' }, - go = { 'golangcilint' }, - ruby = { 'rubocop' }, - fish = { 'fish' }, - bash = { 'bash' }, - nix = { 'nix' }, - php = { 'php' }, - } - vim.api.nvim_create_autocmd({ 'BufWritePost', 'InsertLeave' }, { - group = vim.api.nvim_create_augroup('lint', { clear = true }), - callback = function() - if vim.bo.modifiable then - require('lint').try_lint(nil, { ignore_errors = true }) - end - end, - }) - - vim.treesitter.language.register('markdown', 'blink-cmp-documentation') - require('blink.cmp').setup { - enabled = function() - return not vim.tbl_contains({ 'snacks_picker_input' }, vim.bo.filetype) - end, - fuzzy = { - sorts = { - 'exact', - 'score', - 'sort_text', - }, - }, - sources = { - default = { - 'lsp', - 'path', - 'snippets', - 'ripgrep', - 'buffer', - }, - providers = { - lsp = { - fallbacks = {}, -- include buffer even when LSP is active - score_offset = 10, - }, - snippets = { - score_offset = -10, - }, - path = { - opts = { - get_cwd = function(_) - return vim.fn.getcwd() -- use nvim pwd instead of current file pwd - end, - }, - }, - ripgrep = { - module = 'blink-ripgrep', - name = 'rg', - score_offset = -10, - async = true, - }, - }, - }, - cmdline = { - completion = { - menu = { - auto_show = true, - }, - }, - }, - completion = { - documentation = { - auto_show = true, - auto_show_delay_ms = 500, - }, - menu = { - draw = { - treesitter = { 'lsp' }, - columns = { - { 'label', 'label_description', gap = 1 }, - { 'source_name', 'kind', gap = 1 }, - }, - }, - }, - trigger = { - show_on_keyword = true, - }, - }, - signature = { - enabled = true, - trigger = { - show_on_insert = true, - }, - }, - } -end)