Nix-Configs/configs/programs/neovim.nix

213 lines
4.2 KiB
Nix

with builtins;
let
mkSettings = s:
concatStringsSep
"\n"
(attrValues
(mapAttrs
(k: v:
if typeOf v == "bool" then
if v then "set ${k}" else "set no${k}"
else
"set ${k}=${toString v}")
s
)
);
boolToString = b: if b then "true" else "false";
toLuaTable = as:
"{" +
( concatStringsSep
", "
( filter
(attr: !isNull attr)
( attrValues
( mapAttrs
(k: v: if v then "${k}=true" else null)
as
)
)
)
) +
"}";
mkMapping = {
mode,
binding,
command,
nowait?false,
silent?false,
unique?false,
expr?false
}:
"vim.api.nvim_set_keymap(${toJSON mode}, ${toJSON binding}, ${toJSON command}, ${toLuaTable {inherit nowait silent unique expr;}})";
mkMappings =
m:
"lua << END-OF-KEYBINDS\n" +
(concatStringsSep "\n" (map mkMapping m)) +
"\nEND-OF-KEYBINDS";
mkRuntimes = rs:
if rs == [] then "" else
"set runtimepath+=" +
( concatStringsSep
","
(map (rt: "${rt}") rs)
);
mkVimHeader = h: "\"\"\"\"\"\"\"\" ${h} \"\"\"\"\"\"\"\"\"";
mkVimSection = section:
(concatStringsSep "\n\n\n"
(filter
(v: !isNull v)
(attrValues
(mapAttrs
(k: v: if "" == v then null else (mkVimHeader k) + "\n" + v)
section
)
)
)
);
mkVimSections = sections: concatStringsSep "\n\n\n" (map mkVimSection sections);
mkConfig = { settings?{}, mappings?[], runtimes?[], extra?"" }:
mkVimSections [
{"ADDITIONAL RUNTIME DIRS" = mkRuntimes runtimes;}
{"SETTINGS" = mkSettings settings;}
{"KEY BINGINGS" = mkMappings mappings;}
{"MANUAL SETTINGS" = extra;}
];
in
pkgs: {
enable = true;
plugins = with pkgs.vimPlugins; [
editorconfig-nvim
vim-airline
vim-airline-themes
lsp_signature-nvim
nvim-colorizer-lua
nnn-vim
nvim-surround
hop-nvim
nvim-treesitter.withAllGrammars
nvim-ts-rainbow
nvim-lspconfig
];
extraConfig = mkConfig {
settings = {
number = true;
expandtab = false;
linebreak = true;
display = "lastline";
comments = "s1:/*,mb:*,ex:*/,:///\\ #,:///,://!,://,b:#,:%,:XCOMM,n:>,b:-,b:*";
tgc = true;
tw = 90;
foldmethod = "expr";
foldexpr = "nvim_treesitter#foldexpr()";
foldminlines = 10;
foldnestmax = 2;
};
mappings = [
{
mode = "";
binding = "<C-t>";
command = "<Cmd>:tab split<CR>";
}
{
mode = "n";
binding = "<C-n>";
command = "<cmd>call nnn#pick(expand('%:p:h'))<CR>";
}
{
mode = "n";
binding = "<C-h>";
command = "<cmd>HopWord<CR>";
}
{
mode = "n";
binding = "<C-l>";
command = "<cmd>HopChar2<CR>";
}
{
mode = "i";
binding = "<Tab>";
command = "coc#pum#visible() ? coc#pum#next(1) : CheckBackspace() ? \"\\<Tab>\" : coc#refresh()";
silent = true;
expr = true;
}
{
mode = "i";
binding = "<S-Tab>";
command = "coc#pum#visible() ? coc#pum#prev(1) : \"\\<C-h>\"";
expr = true;
}
{
mode = "n";
binding = "<C-Space>";
command = "coc#refresh()";
silent = true;
}
{
mode = "n";
binding = "[g";
command = "<Plug>(coc-diagnostic-prev)";
silent = true;
}
{
mode = "n";
binding = "]g";
command = "<Plug>(coc-diagnostic-next)";
silent = true;
}
{
mode = "n";
binding = "gd";
command = "<Plug>(coc-definition)";
silent = true;
}
{
mode = "n";
binding = "gy";
command = "<Plug>(coc-type-definition)";
silent = true;
}
{
mode = "n";
binding = "gi";
command = "<Plug>(coc-implementation)";
silent = true;
}
{
mode = "n";
binding = "gr";
command = "<Plug>(coc-references)";
silent = true;
}
{
mode = "n";
binding = "K";
command = ":call ShowDocumentation()<CR>";
silent = true;
}
{
mode = "n";
binding = "...";
command = "<Plug>(coc-codeaction-cursor)";
silent = true;
}
{
mode = "n";
binding = "<Space>rn";
command = "<Plug>(coc-rename)";
silent = true;
}
{
mode = "n";
binding = "<Space>cl";
command = "<Plug>(coc-codelens-action)";
silent = true;
}
];
runtimes = [neovim/laserwave];
extra = builtins.readFile neovim/init.vim;
};
coc.enable = true;
coc.settings = {
};
}