From e3ee67531433843b593b966d050fd452b58c1ff4 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Tue, 27 Aug 2024 16:10:04 +0200 Subject: [PATCH] modularize nixvim configuration --- home/base/programs/nixvim/autocmds.nix | 17 + home/base/programs/nixvim/core.nix | 32 ++ home/base/programs/nixvim/default.nix | 290 +----------------- home/base/programs/nixvim/keymaps.nix | 45 +++ home/base/programs/nixvim/plugins/alpha.nix | 68 ++++ home/base/programs/nixvim/plugins/lsp.nix | 93 ++++++ home/base/programs/nixvim/plugins/lualine.nix | 9 + home/base/programs/nixvim/plugins/misc.nix | 9 + .../base/programs/nixvim/plugins/neo-tree.nix | 8 + .../programs/nixvim/plugins/project-nvim.nix | 8 + .../programs/nixvim/plugins/which-key.nix | 32 ++ 11 files changed, 333 insertions(+), 278 deletions(-) create mode 100644 home/base/programs/nixvim/autocmds.nix create mode 100644 home/base/programs/nixvim/core.nix create mode 100644 home/base/programs/nixvim/keymaps.nix create mode 100644 home/base/programs/nixvim/plugins/alpha.nix create mode 100644 home/base/programs/nixvim/plugins/lsp.nix create mode 100644 home/base/programs/nixvim/plugins/lualine.nix create mode 100644 home/base/programs/nixvim/plugins/misc.nix create mode 100644 home/base/programs/nixvim/plugins/neo-tree.nix create mode 100644 home/base/programs/nixvim/plugins/project-nvim.nix create mode 100644 home/base/programs/nixvim/plugins/which-key.nix diff --git a/home/base/programs/nixvim/autocmds.nix b/home/base/programs/nixvim/autocmds.nix new file mode 100644 index 0000000..1173c7e --- /dev/null +++ b/home/base/programs/nixvim/autocmds.nix @@ -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"; + }]; +} diff --git a/home/base/programs/nixvim/core.nix b/home/base/programs/nixvim/core.nix new file mode 100644 index 0000000..87b532b --- /dev/null +++ b/home/base/programs/nixvim/core.nix @@ -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; + }; + }; + }; + }; +} diff --git a/home/base/programs/nixvim/default.nix b/home/base/programs/nixvim/default.nix index d818c70..2676499 100644 --- a/home/base/programs/nixvim/default.nix +++ b/home/base/programs/nixvim/default.nix @@ -1,284 +1,18 @@ { ... }: { - programs.nixvim = { - enable = true; + imports = [ + ./core.nix + ./keymaps.nix + ./autocmds.nix - viAlias = true; - vimAlias = true; + ./plugins/alpha.nix + ./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 = "Telescope find_files"; - key = "ff"; - options = { - desc = "Find files"; - }; - } - { - action = "Telescope projects"; - key = "fp"; - options = { - desc = "Find projects"; - }; - } - { - action = "Neotree toggle"; - key = "ft"; - options = { - desc = "Toggle neo-tree"; - }; - } - { - action = '' - lua vim.lsp.buf.code_action({ apply = true }) - ''; - key = "lc"; - options = { - desc = "Apply code actions"; - }; - } - { - action = '' - lua vim.lsp.buf.format() - ''; - key = "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" ":Telescope find_files" " Find File" - "Operator") - (mkButton "p" ":Telescope projects" " Projects" - "Operator") - (mkButton "q" "qa" "󰈆 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 = { - "" = "cmp.mapping.complete()"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.close()"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.confirm({ select = true })"; - "" = '' - 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'}) - ''; - "" = '' - 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" ] - [ "<[cC][rR]>" "RETURN" ] - [ "<[tT][aA][bB]>" "TAB" ] - [ "<[bB][sS]>" "BACKSPACE" ] - ]; - }; - spec = [ - { - __unkeyed = "f"; - group = "Find"; - } - { - __unkeyed = "l"; - group = "LSP"; - } - ]; - }; - }; - tmux-navigator.enable = true; - }; - }; } diff --git a/home/base/programs/nixvim/keymaps.nix b/home/base/programs/nixvim/keymaps.nix new file mode 100644 index 0000000..c37e636 --- /dev/null +++ b/home/base/programs/nixvim/keymaps.nix @@ -0,0 +1,45 @@ +{ ... }: + +{ + programs.nixvim.keymaps = [ + { + action = "Telescope find_files"; + key = "ff"; + options = { + desc = "Find files"; + }; + } + { + action = "Telescope projects"; + key = "fp"; + options = { + desc = "Find projects"; + }; + } + { + action = "Neotree toggle"; + key = "ft"; + options = { + desc = "Toggle neo-tree"; + }; + } + { + action = '' + lua vim.lsp.buf.code_action({ apply = true }) + ''; + key = "lc"; + options = { + desc = "Apply code actions"; + }; + } + { + action = '' + lua vim.lsp.buf.format() + ''; + key = "lf"; + options = { + desc = "Format buffer"; + }; + } + ]; +} diff --git a/home/base/programs/nixvim/plugins/alpha.nix b/home/base/programs/nixvim/plugins/alpha.nix new file mode 100644 index 0000000..516ee67 --- /dev/null +++ b/home/base/programs/nixvim/plugins/alpha.nix @@ -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" ":Telescope find_files" " Find File" + "Operator") + (mkButton "p" ":Telescope projects" " Projects" + "Operator") + (mkButton "q" "qa" "󰈆 Quit" "Error") + ]; + } + ]; + }; + }; + }; +} diff --git a/home/base/programs/nixvim/plugins/lsp.nix b/home/base/programs/nixvim/plugins/lsp.nix new file mode 100644 index 0000000..8f733cb --- /dev/null +++ b/home/base/programs/nixvim/plugins/lsp.nix @@ -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 = { + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.confirm({ select = true })"; + "" = '' + 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'}) + ''; + "" = '' + 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; + }; + }; +} diff --git a/home/base/programs/nixvim/plugins/lualine.nix b/home/base/programs/nixvim/plugins/lualine.nix new file mode 100644 index 0000000..7624644 --- /dev/null +++ b/home/base/programs/nixvim/plugins/lualine.nix @@ -0,0 +1,9 @@ +{ ... }: + +{ + programs.nixvim.plugins.lualine = { + enable = true; + extensions = [ "neo-tree" ]; + globalstatus = true; + }; +} diff --git a/home/base/programs/nixvim/plugins/misc.nix b/home/base/programs/nixvim/plugins/misc.nix new file mode 100644 index 0000000..8f282a1 --- /dev/null +++ b/home/base/programs/nixvim/plugins/misc.nix @@ -0,0 +1,9 @@ +{ ... }: + +{ + programs.nixvim.plugins = { + nvim-autopairs.enable = true; + direnv.enable = true; + tmux-navigator.enable = true; + }; +} diff --git a/home/base/programs/nixvim/plugins/neo-tree.nix b/home/base/programs/nixvim/plugins/neo-tree.nix new file mode 100644 index 0000000..ac388e2 --- /dev/null +++ b/home/base/programs/nixvim/plugins/neo-tree.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + programs.nixvim.plugins.neo-tree = { + enable = true; + useDefaultMappings = true; + }; +} diff --git a/home/base/programs/nixvim/plugins/project-nvim.nix b/home/base/programs/nixvim/plugins/project-nvim.nix new file mode 100644 index 0000000..b96565e --- /dev/null +++ b/home/base/programs/nixvim/plugins/project-nvim.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + programs.nixvim.plugins.project-nvim = { + enable = true; + enableTelescope = true; + }; +} diff --git a/home/base/programs/nixvim/plugins/which-key.nix b/home/base/programs/nixvim/plugins/which-key.nix new file mode 100644 index 0000000..c80ecfd --- /dev/null +++ b/home/base/programs/nixvim/plugins/which-key.nix @@ -0,0 +1,32 @@ +{ ... }: + +{ + programs.nixvim.plugins.which-key = { + enable = true; + settings = { + delay = 200; + expand = 1; + notify = false; + preset = false; + replace = { + desc = [ + [ "" "SPACE" ] + [ "" "SPACE" ] + [ "<[cC][rR]>" "RETURN" ] + [ "<[tT][aA][bB]>" "TAB" ] + [ "<[bB][sS]>" "BACKSPACE" ] + ]; + }; + spec = [ + { + __unkeyed = "f"; + group = "Find"; + } + { + __unkeyed = "l"; + group = "LSP"; + } + ]; + }; + }; +}