From 48bbb7951d5593e9cd168dd5a53773f6ea78ed9f Mon Sep 17 00:00:00 2001 From: Roel de Cort <63876068+dc-tec@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:57:29 +0200 Subject: [PATCH] feat: autopairs, cursor restore and rename option (#15) Add the nvim-autopairs so "'{[ characters will auto close. Add AutoCmd to restore the cursor position when re-opening file. Fix treesitter option name. --- config/auto_cmds.nix | 21 ++++++ config/default.nix | 1 + config/plugins/cmp/autopairs.nix | 8 +++ config/plugins/editor/treesitter.nix | 4 +- flake.lock | 103 +++++++++++++++++---------- 5 files changed, 98 insertions(+), 39 deletions(-) create mode 100644 config/plugins/cmp/autopairs.nix diff --git a/config/auto_cmds.nix b/config/auto_cmds.nix index b96bf56..d3017a1 100644 --- a/config/auto_cmds.nix +++ b/config/auto_cmds.nix @@ -3,6 +3,7 @@ highlight_yank = {}; vim_enter = {}; indentscope = {}; + restore_cursor = {}; }; autoCmd = [ @@ -50,5 +51,25 @@ ''; }; } + ## from NVChad https://nvchad.com/docs/recipes (this autocmd will restore the cursor position when opening a file) + { + group = "restore_cursor"; + event = ["BufReadPost"]; + pattern = "*"; + callback = { + __raw = '' + function() + if + vim.fn.line "'\"" > 1 + and vim.fn.line "'\"" <= vim.fn.line "$" + and vim.bo.filetype ~= "commit" + and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1 + then + vim.cmd "normal! g`\"" + end + end + ''; + }; + } ]; } diff --git a/config/default.nix b/config/default.nix index 392b4b7..6c1d3ee 100644 --- a/config/default.nix +++ b/config/default.nix @@ -13,6 +13,7 @@ _: { ./plugins/cmp/cmp.nix ./plugins/cmp/cmp-copilot.nix ./plugins/cmp/lspkind.nix + ./plugins/cmp/autopairs.nix # Snippets ./plugins/snippets/luasnip.nix diff --git a/config/plugins/cmp/autopairs.nix b/config/plugins/cmp/autopairs.nix new file mode 100644 index 0000000..ee5f518 --- /dev/null +++ b/config/plugins/cmp/autopairs.nix @@ -0,0 +1,8 @@ +{ + plugins.nvim-autopairs = { + enable = true; + settings = { + disable_filetype = ["TelescopePrompt" "vim"]; + }; + }; +} diff --git a/config/plugins/editor/treesitter.nix b/config/plugins/editor/treesitter.nix index 5726286..ae2d600 100644 --- a/config/plugins/editor/treesitter.nix +++ b/config/plugins/editor/treesitter.nix @@ -1,7 +1,9 @@ {pkgs, ...}: { plugins.treesitter = { enable = true; - indent = true; + settings = { + indent.enable = true; + }; folding = false; nixvimInjections = true; grammarPackages = pkgs.vimPlugins.nvim-treesitter.allGrammars; diff --git a/flake.lock b/flake.lock index f6be673..4978e2c 100644 --- a/flake.lock +++ b/flake.lock @@ -2,18 +2,22 @@ "nodes": { "devshell": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": [ + "nixvim", + "nuschtosSearch", + "flake-utils" + ], "nixpkgs": [ "nixvim", "nixpkgs" ] }, "locked": { - "lastModified": 1717408969, - "narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=", + "lastModified": 1721902368, + "narHash": "sha256-noQ5SghRPe0jzQEbFQb3fYbV6LZEzr7lIRQoxlU7fyI=", "owner": "numtide", "repo": "devshell", - "rev": "1ebbe68d57457c8cae98145410b164b5477761f4", + "rev": "cf8c7405479cfde7ea4dc815e195391d2328df10", "type": "github" }, "original": { @@ -78,11 +82,11 @@ ] }, "locked": { - "lastModified": 1719877454, - "narHash": "sha256-g5N1yyOSsPNiOlFfkuI/wcUjmtah+nxdImJqrSATjOU=", + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "4e3583423212f9303aa1a6337f8dffb415920e4f", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", "type": "github" }, "original": { @@ -96,11 +100,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -126,11 +130,11 @@ ] }, "locked": { - "lastModified": 1719259945, - "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", + "lastModified": 1721042469, + "narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", + "rev": "f451c19376071a90d8c58ab1a953c6e9840527fd", "type": "github" }, "original": { @@ -190,11 +194,11 @@ ] }, "locked": { - "lastModified": 1719827439, - "narHash": "sha256-tneHOIv1lEavZ0vQ+rgz67LPNCgOZVByYki3OkSshFU=", + "lastModified": 1721852138, + "narHash": "sha256-JH8N5uoqoVA6erV4O40VtKKHsnfmhvMGbxMNDLtim5o=", "owner": "nix-community", "repo": "home-manager", - "rev": "59ce796b2563e19821361abbe2067c3bb4143a7d", + "rev": "304a011325b7ac7b8c9950333cd215a7aa146b0e", "type": "github" }, "original": { @@ -211,11 +215,11 @@ ] }, "locked": { - "lastModified": 1719845423, - "narHash": "sha256-ZLHDmWAsHQQKnmfyhYSHJDlt8Wfjv6SQhl2qek42O7A=", + "lastModified": 1721719500, + "narHash": "sha256-nnkqjv4Y37Hydjh6HE9wW4kSkV5Q7q4iIXlL5lwUFOw=", "owner": "lnl7", "repo": "nix-darwin", - "rev": "ec12b88104d6c117871fad55e931addac4626756", + "rev": "884f3fe6d9bf056ba0017c132c39c1f0d07d4fec", "type": "github" }, "original": { @@ -226,11 +230,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1720031269, - "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "lastModified": 1721743106, + "narHash": "sha256-adRZhFpBTnHiK3XIELA3IBaApz70HwCYfv7xNrHjebA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "rev": "dc14ed91132ee3a26255d01d8fd0c1f5bff27b2f", "type": "github" }, "original": { @@ -254,27 +258,27 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1718811006, - "narHash": "sha256-0Y8IrGhRmBmT7HHXlxxepg2t8j1X90++qRN3lukGaIk=", + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "03d771e513ce90147b65fe922d87d3a0356fc125", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.11", + "ref": "nixos-24.05", "repo": "nixpkgs", "type": "github" } }, "nixpkgs_2": { "locked": { - "lastModified": 1719848872, - "narHash": "sha256-H3+EC5cYuq+gQW8y0lSrrDZfH71LB4DAf+TDFyvwCNA=", + "lastModified": 1721743106, + "narHash": "sha256-adRZhFpBTnHiK3XIELA3IBaApz70HwCYfv7xNrHjebA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "00d80d13810dbfea8ab4ed1009b09100cca86ba8", + "rev": "dc14ed91132ee3a26255d01d8fd0c1f5bff27b2f", "type": "github" }, "original": { @@ -309,14 +313,15 @@ "home-manager": "home-manager", "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs_2", + "nuschtosSearch": "nuschtosSearch", "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1720382751, - "narHash": "sha256-i+wpxx7NMEIoxAl0IQ3bNDX4faTcO13ZJ6j75SJUIzA=", + "lastModified": 1721931827, + "narHash": "sha256-4UZMHfe2k3WJvTaE29iUBu2tmLawg4Zb5w2yxYlr5Kg=", "owner": "nix-community", "repo": "nixvim", - "rev": "41794c222a5eaa966e5513c707c0b3f5e7abf5e0", + "rev": "c12e59ff7cba4f70b7428899d1af1d59666df1c6", "type": "github" }, "original": { @@ -325,6 +330,28 @@ "type": "github" } }, + "nuschtosSearch": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721548975, + "narHash": "sha256-agCbztdk1f7nCUz03R6xdbivuBRuqubP2RHW+MNuRTg=", + "owner": "NuschtOS", + "repo": "search", + "rev": "551b031e2bc0bcc9584347a8da6312e57169661d", + "type": "github" + }, + "original": { + "owner": "NuschtOS", + "repo": "search", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat_2", @@ -333,11 +360,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1719259945, - "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", + "lastModified": 1721042469, + "narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", + "rev": "f451c19376071a90d8c58ab1a953c6e9840527fd", "type": "github" }, "original": { @@ -377,11 +404,11 @@ ] }, "locked": { - "lastModified": 1719887753, - "narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=", + "lastModified": 1721769617, + "narHash": "sha256-6Pqa0bi5nV74IZcENKYRToRNM5obo1EQ+3ihtunJ014=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c", + "rev": "8db8970be1fb8be9c845af7ebec53b699fe7e009", "type": "github" }, "original": {