modularize nixvim configuration

This commit is contained in:
Anthony Rodriguez 2024-08-27 16:10:04 +02:00
parent bdd725ee71
commit e3ee675314
Signed by: nezia
GPG key ID: EE3BE97C040A86CE
11 changed files with 333 additions and 278 deletions

View file

@ -0,0 +1,17 @@
{ ... }:
{
programs.nixvim.autoCmd = [{
event = [ "BufWritePre" ];
callback = {
__raw = ''
function()
vim.lsp.buf.format { async = false }
end
'';
};
desc = "Auto format buffer before save using LSP";
}];
}

View file

@ -0,0 +1,32 @@
{ ... }:
{
programs.nixvim = {
enable = true;
viAlias = true;
vimAlias = true;
performance.byteCompileLua.enable = true;
clipboard.providers.wl-copy.enable = true;
globals.mapleader = " ";
opts = {
smartindent = false;
relativenumber = true;
clipboard = "unnamedplus";
};
files = {
"ftplugin/nix.lua" = {
opts = {
expandtab = true;
shiftwidth = 2;
tabstop = 2;
};
};
};
};
}

View file

@ -1,284 +1,18 @@
{ ... }: { ... }:
{ {
programs.nixvim = { imports = [
enable = true; ./core.nix
./keymaps.nix
./autocmds.nix
viAlias = true; ./plugins/alpha.nix
vimAlias = true; ./plugins/lsp.nix
./plugins/lualine.nix
./plugins/neo-tree.nix
./plugins/which-key.nix
./plugins/project-nvim.nix
./plugins/misc.nix
];
performance.byteCompileLua.enable = true;
clipboard.providers.wl-copy.enable = true;
globals.mapleader = " ";
opts = {
smartindent = false;
relativenumber = true;
clipboard = "unnamedplus";
};
files = {
"ftplugin/nix.lua" = {
opts = {
expandtab = true;
shiftwidth = 2;
tabstop = 2;
};
};
};
autoCmd = [{
event = [ "BufWritePre" ];
callback = {
__raw = ''
function()
vim.lsp.buf.format { async = false }
end
'';
};
desc = "Auto format buffer before save using LSP";
}];
keymaps = [
{
action = "<cmd>Telescope find_files<CR>";
key = "<leader>ff";
options = {
desc = "Find files";
};
}
{
action = "<cmd>Telescope projects<CR>";
key = "<leader>fp";
options = {
desc = "Find projects";
};
}
{
action = "<cmd>Neotree toggle<CR>";
key = "<leader>ft";
options = {
desc = "Toggle neo-tree";
};
}
{
action = ''
<cmd>lua vim.lsp.buf.code_action({ apply = true })<CR>
'';
key = "<leader>lc";
options = {
desc = "Apply code actions";
};
}
{
action = ''
<cmd>lua vim.lsp.buf.format()<CR>
'';
key = "<leader>lf";
options = {
desc = "Format buffer";
};
}
];
plugins = {
alpha = {
enable = true;
layout = [
{
type = "padding";
val = 2;
}
{
opts = {
hl = "Keyword";
position = "center";
};
type = "text";
val = [
""
""
""
""
""
""
""
""
""
""
""
""
""
""
];
}
{
type = "padding";
val = 2;
}
{
type = "group";
val = let
mkButton = shortcut: cmd: val: hl: {
type = "button";
inherit val;
opts = {
inherit hl shortcut;
keymap = [ "n" shortcut cmd { } ];
position = "center";
cursor = 0;
width = 40;
align_shortcut = "right";
hl_shortcut = "Keyword";
};
};
in [
(mkButton "f" "<CMD>:Telescope find_files<CR>" " Find File"
"Operator")
(mkButton "p" "<CMD>:Telescope projects<CR>" " Projects"
"Operator")
(mkButton "q" "<CMD>qa<CR>" "󰈆 Quit" "Error")
];
}
];
};
lualine = {
enable = true;
extensions = [ "neo-tree" ];
globalstatus = true;
};
treesitter = {
enable = true;
settings = {
auto_install = true;
highlight = {
additional_vim_regex_highlighting = true;
custom_captures = { };
enable = true;
};
incremental_selection = {
enable = true;
keymaps = {
init_selection = false;
node_decremental = "grm";
node_incremental = "grn";
scope_incremental = "grc";
};
};
indent = {
enable = true;
};
parser_install_dir = {
__raw = "vim.fs.joinpath(vim.fn.stdpath('data'), 'treesitter')";
};
};
};
treesitter-context.enable = true;
indent-blankline.enable = true;
lsp = {
enable = true;
servers = {
gopls.enable = true;
nixd.enable = true;
lua-ls.enable = true;
};
};
cmp = {
enable = true;
autoEnableSources = true;
settings = {
mapping = {
"<C-Space>" = "cmp.mapping.complete()";
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
"<C-e>" = "cmp.mapping.close()";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<CR>" = "cmp.mapping.confirm({ select = true })";
"<S-Tab>" = ''
cmp.mapping(function (fallback)
local luasnip = require('luasnip')
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {'i', 's'})
'';
"<Tab>" = ''
cmp.mapping(function (fallback)
local luasnip = require('luasnip')
if luasnip.expandable() then
luasnip.expand()
elseif cmp.visible() then
cmp.select_next_item()
elseif luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, {'i', 's'})
'';
};
sources =
[ { name = "nvim_lsp"; } { name = "path"; } { name = "buffer"; } { name = "luasnip"; } ];
};
};
cmp-nvim-lsp.enable = true;
cmp-nvim-lsp-signature-help.enable = true;
telescope = {
enable = true;
};
luasnip.enable = true;
friendly-snippets.enable = true;
neo-tree = {
enable = true;
useDefaultMappings = true;
};
nvim-autopairs.enable = true;
project-nvim = {
enable = true;
enableTelescope = true;
};
direnv.enable = true;
which-key = {
enable = true;
settings = {
delay = 200;
expand = 1;
notify = false;
preset = false;
replace = {
desc = [
[ "<space>" "SPACE" ]
[ "<leader>" "SPACE" ]
[ "<[cC][rR]>" "RETURN" ]
[ "<[tT][aA][bB]>" "TAB" ]
[ "<[bB][sS]>" "BACKSPACE" ]
];
};
spec = [
{
__unkeyed = "<leader>f";
group = "Find";
}
{
__unkeyed = "<leader>l";
group = "LSP";
}
];
};
};
tmux-navigator.enable = true;
};
};
} }

View file

@ -0,0 +1,45 @@
{ ... }:
{
programs.nixvim.keymaps = [
{
action = "<cmd>Telescope find_files<CR>";
key = "<leader>ff";
options = {
desc = "Find files";
};
}
{
action = "<cmd>Telescope projects<CR>";
key = "<leader>fp";
options = {
desc = "Find projects";
};
}
{
action = "<cmd>Neotree toggle<CR>";
key = "<leader>ft";
options = {
desc = "Toggle neo-tree";
};
}
{
action = ''
<cmd>lua vim.lsp.buf.code_action({ apply = true })<CR>
'';
key = "<leader>lc";
options = {
desc = "Apply code actions";
};
}
{
action = ''
<cmd>lua vim.lsp.buf.format()<CR>
'';
key = "<leader>lf";
options = {
desc = "Format buffer";
};
}
];
}

View file

@ -0,0 +1,68 @@
{ ... }:
{
programs.nixvim = {
plugins = {
alpha = {
enable = true;
layout = [
{
type = "padding";
val = 2;
}
{
opts = {
hl = "Keyword";
position = "center";
};
type = "text";
val = [
""
""
""
""
""
""
""
""
""
""
""
""
""
""
];
}
{
type = "padding";
val = 2;
}
{
type = "group";
val = let
mkButton = shortcut: cmd: val: hl: {
type = "button";
inherit val;
opts = {
inherit hl shortcut;
keymap = [ "n" shortcut cmd { } ];
position = "center";
cursor = 0;
width = 40;
align_shortcut = "right";
hl_shortcut = "Keyword";
};
};
in [
(mkButton "f" "<CMD>:Telescope find_files<CR>" " Find File"
"Operator")
(mkButton "p" "<CMD>:Telescope projects<CR>" " Projects"
"Operator")
(mkButton "q" "<CMD>qa<CR>" "󰈆 Quit" "Error")
];
}
];
};
};
};
}

View file

@ -0,0 +1,93 @@
{ ... }:
{
programs.nixvim = {
plugins = {
treesitter = {
enable = true;
settings = {
auto_install = true;
highlight = {
additional_vim_regex_highlighting = true;
custom_captures = { };
enable = true;
};
incremental_selection = {
enable = true;
keymaps = {
init_selection = false;
node_decremental = "grm";
node_incremental = "grn";
scope_incremental = "grc";
};
};
indent = {
enable = true;
};
parser_install_dir = {
__raw = "vim.fs.joinpath(vim.fn.stdpath('data'), 'treesitter')";
};
};
};
treesitter-context.enable = true;
indent-blankline.enable = true;
lsp = {
enable = true;
servers = {
gopls.enable = true;
nixd.enable = true;
lua-ls.enable = true;
};
};
cmp = {
enable = true;
autoEnableSources = true;
settings = {
mapping = {
"<C-Space>" = "cmp.mapping.complete()";
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
"<C-e>" = "cmp.mapping.close()";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<CR>" = "cmp.mapping.confirm({ select = true })";
"<S-Tab>" = ''
cmp.mapping(function (fallback)
local luasnip = require('luasnip')
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {'i', 's'})
'';
"<Tab>" = ''
cmp.mapping(function (fallback)
local luasnip = require('luasnip')
if luasnip.expandable() then
luasnip.expand()
elseif cmp.visible() then
cmp.select_next_item()
elseif luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, {'i', 's'})
'';
};
sources =
[ { name = "nvim_lsp"; } { name = "path"; } { name = "buffer"; } { name = "luasnip"; } ];
};
};
cmp-nvim-lsp.enable = true;
cmp-nvim-lsp-signature-help.enable = true;
telescope = {
enable = true;
};
luasnip.enable = true;
friendly-snippets.enable = true;
};
};
}

View file

@ -0,0 +1,9 @@
{ ... }:
{
programs.nixvim.plugins.lualine = {
enable = true;
extensions = [ "neo-tree" ];
globalstatus = true;
};
}

View file

@ -0,0 +1,9 @@
{ ... }:
{
programs.nixvim.plugins = {
nvim-autopairs.enable = true;
direnv.enable = true;
tmux-navigator.enable = true;
};
}

View file

@ -0,0 +1,8 @@
{ ... }:
{
programs.nixvim.plugins.neo-tree = {
enable = true;
useDefaultMappings = true;
};
}

View file

@ -0,0 +1,8 @@
{ ... }:
{
programs.nixvim.plugins.project-nvim = {
enable = true;
enableTelescope = true;
};
}

View file

@ -0,0 +1,32 @@
{ ... }:
{
programs.nixvim.plugins.which-key = {
enable = true;
settings = {
delay = 200;
expand = 1;
notify = false;
preset = false;
replace = {
desc = [
[ "<space>" "SPACE" ]
[ "<leader>" "SPACE" ]
[ "<[cC][rR]>" "RETURN" ]
[ "<[tT][aA][bB]>" "TAB" ]
[ "<[bB][sS]>" "BACKSPACE" ]
];
};
spec = [
{
__unkeyed = "<leader>f";
group = "Find";
}
{
__unkeyed = "<leader>l";
group = "LSP";
}
];
};
};
}