fix(snippets): move snippets configuration to nvf module

This commit is contained in:
Mohammad Rafiq 2025-06-17 13:45:19 +08:00
parent d0714f8bff
commit ad0d5ed0f8
No known key found for this signature in database
4 changed files with 26 additions and 64 deletions

View file

@ -4,5 +4,26 @@
enable = true;
setupOpts.enable_autosnippets = true;
providers = with pkgs.vimPlugins; [ vim-snippets ];
customSnippets.snipmate = {
all = [
{
trigger = "if";
body = "if $1 else $2";
}
];
nix = [
{
trigger = "mkOption";
body = ''
mkOption {
type = $1;
default = $2;
description = $3;
example = $4;
}
'';
}
];
};
};
}

View file

@ -1,66 +1,13 @@
{ lib, pkgs, ... }:
let
inherit (lib) singleton replicate;
inherit (lib.strings)
concatMapStringsSep
removeSuffix
concatStrings
stringAsChars
;
inherit (lib.attrsets) mapAttrsToList;
inherit (pkgs) writeTextFile;
indent =
n: s:
let
indentString = concatStrings (replicate n " ");
sep = "\n" + indentString;
in
indentString + stringAsChars (c: if c == "\n" then sep else c) (removeSuffix "\n" s);
inherit (lib) singleton;
in
{
home.sessionVariables.EDITOR = "nvim";
persistDirs = singleton ".local/share/nvf";
programs.nvf.enable = true;
programs.nvf.settings.vim = {
startPlugins =
[ pkgs.pantheon.snippets ]
++ (mapAttrsToList
(
name: value:
writeTextFile {
name = "${name}.snippets";
text = concatMapStringsSep "\n" (x: ''
snippet ${x.trigger} ${x.description}
${indent 2 x.body}
'') value;
destination = "/snippets/${name}.snippets";
}
)
{
all = [
{
trigger = "if";
description = "";
body = "if $1 else $2";
}
];
nix = [
{
trigger = "mkOption";
description = "";
body = ''
mkOption {
type = $1;
default = $2;
description = $3;
example = $4;
}
'';
}
];
}
);
startPlugins = [ pkgs.pantheon.snippets ];
hideSearchHighlight = true;
syntaxHighlighting = true;