From f1f8b4f01e026c75be08628791db1fb770c37d6d Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Mon, 20 May 2024 23:03:25 +0300 Subject: [PATCH] neovim: add some nix snippets --- flake.lock | 16 +++++++-------- neovim/dev.nix | 1 + neovim/snippets.nix | 49 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 neovim/snippets.nix diff --git a/flake.lock b/flake.lock index 1bbe812..2e97afb 100644 --- a/flake.lock +++ b/flake.lock @@ -255,11 +255,11 @@ }, "nix2lua": { "locked": { - "lastModified": 1715344083, - "narHash": "sha256-7UehRa7etk0oqSH4ty0nUsmeO3Z+Y1dbKwrGSlgaMIc=", + "lastModified": 1716215210, + "narHash": "sha256-GjwpjhNGdrGH0dElAvcKSFY3nbRw4JYOKtKMmhMsEWw=", "ref": "refs/heads/main", - "rev": "6a096bf9a22903c92f0065ba3316d3821ddd8b72", - "revCount": 41, + "rev": "4d3ae67617c2c1301a1a90601e20e15614d20319", + "revCount": 52, "type": "git", "url": "https://git.pleshevski.ru/mynix/nix2lua" }, @@ -279,11 +279,11 @@ ] }, "locked": { - "lastModified": 1715970214, - "narHash": "sha256-x9bHVtPmk5BfGmVLfUhFcpVJdQZ5SstBRFy19WBp/W0=", + "lastModified": 1716215872, + "narHash": "sha256-zjy9raJUx+14DVMDuVfZYbBOPcHgMBxk2vt+rmNn7uk=", "ref": "refs/heads/main", - "rev": "51fcb9d9e41d9ac540a9840081fdce328e2117e0", - "revCount": 73, + "rev": "463a4f2d43033dc75d4e84522d0ff670001622bb", + "revCount": 80, "type": "git", "url": "https://git.pleshevski.ru/pleshevskiy/nixeovim" }, diff --git a/neovim/dev.nix b/neovim/dev.nix index 573d313..7d7dcd0 100644 --- a/neovim/dev.nix +++ b/neovim/dev.nix @@ -18,6 +18,7 @@ in { imports = [ "${modulesPath}/profiles/recommended.nix" + ./snippets.nix ]; vim.opt = { diff --git a/neovim/snippets.nix b/neovim/snippets.nix new file mode 100644 index 0000000..7c67e63 --- /dev/null +++ b/neovim/snippets.nix @@ -0,0 +1,49 @@ +{ ... }: + +let + t = text: { inherit text; }; + i = jump: text: { inherit jump text; }; + c = jump: nodes: { inherit jump nodes; }; +in +{ + plugins.snippet.luasnip.snippetGroups = [ + { + filetype = "nix"; + snippets = { + "if".nodes = [ + (t "if ") + (i 1 "condition") + (t " then ") + (i 2 "trueBody") + (t " else ") + (i 3 "falseBody") + (t ";") + ]; + "var".nodes = [ + (i 1 "name") + (t " = ") + (c 2 [ + (i null "value") + { + snippet.nodes = [ + { insert = 1; } + (t "[") + { insert = 2; } + (t "]") + ]; + } + { + snippet.nodes = [ + { insert = 1; } + (t "{") + { insert = 2; } + (t "}") + ]; + } + ]) + (t ";") + ]; + }; + } + ]; +}