From ac7f8ef19b645af5afe8f5f8044868a0cf25a620 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 28 Sep 2024 15:17:50 +0200 Subject: nixvim: refactor --- common/home/programs/nixvim/default.nix | 195 +-------------------- common/home/programs/nixvim/plugins/cmp.nix | 45 +++++ common/home/programs/nixvim/plugins/dashboard.nix | 68 +++++++ common/home/programs/nixvim/plugins/default.nix | 27 +++ .../programs/nixvim/plugins/friendly-snippets.nix | 4 + common/home/programs/nixvim/plugins/lsp-format.nix | 4 + common/home/programs/nixvim/plugins/lsp.nix | 39 +++++ common/home/programs/nixvim/plugins/lualine.nix | 4 + common/home/programs/nixvim/plugins/luasnip.nix | 4 + common/home/programs/nixvim/plugins/nvim-tree.nix | 7 + common/home/programs/nixvim/plugins/telescope.nix | 4 + common/home/programs/nixvim/plugins/treesitter.nix | 24 +++ 12 files changed, 231 insertions(+), 194 deletions(-) create mode 100644 common/home/programs/nixvim/plugins/cmp.nix create mode 100644 common/home/programs/nixvim/plugins/dashboard.nix create mode 100644 common/home/programs/nixvim/plugins/default.nix create mode 100644 common/home/programs/nixvim/plugins/friendly-snippets.nix create mode 100644 common/home/programs/nixvim/plugins/lsp-format.nix create mode 100644 common/home/programs/nixvim/plugins/lsp.nix create mode 100644 common/home/programs/nixvim/plugins/lualine.nix create mode 100644 common/home/programs/nixvim/plugins/luasnip.nix create mode 100644 common/home/programs/nixvim/plugins/nvim-tree.nix create mode 100644 common/home/programs/nixvim/plugins/telescope.nix create mode 100644 common/home/programs/nixvim/plugins/treesitter.nix (limited to 'common/home/programs/nixvim') diff --git a/common/home/programs/nixvim/default.nix b/common/home/programs/nixvim/default.nix index 80de5a1..f8ec8c6 100644 --- a/common/home/programs/nixvim/default.nix +++ b/common/home/programs/nixvim/default.nix @@ -54,200 +54,7 @@ colorscheme = "gruvbox-dark-pale"; }; - plugins = { - web-devicons.enable = true; - - dashboard = { - enable = true; - settings = { - change_to_vcs_root = true; - config = { - footer = [ "" ]; - - header = [ - "███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗" - "████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║" - "██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║" - "██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║" - "██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║" - "╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝" - ]; - - mru = { - limit = 10; - }; - - project = { - enable = true; - }; - - packages.enable = false; - - shortcut = [ - { - action = { - __raw = '' - function(path) - vim.cmd('Telescope find_files') - end - ''; - }; - desc = "Files"; - group = "Label"; - icon = " "; - icon_hl = "@variable"; - key = "f"; - } - { - action = { - __raw = '' - function() - vim.cmd('cd ~/global/system/config'); vim.cmd('Telescope find_files') - end - ''; - }; - icon = "󱄅 "; - icon_hl = "@variable"; - desc = "System Config"; - group = "Number"; - key = "c"; - } - ]; - - hide = [ - "statusline" - "tabline" - "winbar" - ]; - }; - theme = "hyper"; - }; - }; - - nvim-tree = { - enable = true; - autoClose = true; - disableNetrw = true; - hijackCursor = true; - }; - - telescope = { - enable = true; - }; - - lualine = { - enable = true; - }; - - treesitter = { - enable = true; - settings = { - auto_install = true; - highlight = { - additional_vim_regex_highlighting = true; - enable = true; - }; - incremental_selection = { - enable = true; - keymaps = { - init_selection = false; - node_decremental = "grm"; - node_incremental = "grn"; - scope_incremental = "grc"; - }; - }; - indent = { - enable = true; - }; - sync_install = false; - }; - }; - - luasnip = { - enable = true; - }; - - friendly-snippets = { - enable = true; - }; - - cmp = { - enable = true; - autoEnableSources = true; - settings = { - mapping = { - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.complete()"; - "" = "cmp.mapping.abort()"; - "" = "cmp.mapping.confirm({ select = true })"; - "" = '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - else - fallback() - end - end, { "i", "s" }) - ''; - "" = '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, { "i", "s" }) - ''; - }; - snippet = { - expand = "function(args) require('luasnip').lsp_expand(args.body) end"; - }; - sources = [ - { name = "nvim_lsp"; } - { name = "luasnip"; } - { name = "path"; } - { name = "buffer"; } - ]; - }; - }; - - lsp = { - enable = true; - servers = { - bashls = { - enable = true; - package = pkgs.unstable.bash-language-server; - }; - clangd.enable = true; - nixd = { - enable = true; - settings.formatting.command = [ "nixfmt" ]; - }; - rust-analyzer = { - enable = true; - installCargo = true; - installRustc = true; - }; - pyright.enable = true; - ocamllsp.enable = true; - }; - keymaps.lspBuf = { - "gd" = "definition"; - "gD" = "references"; - "gt" = "type_definition"; - "gi" = "implementation"; - "K" = "hover"; - "rn" = "rename"; - "ca" = "code_action"; - "f" = "format"; - }; - }; - - lsp-format = { - enable = true; - }; - }; + plugins = import ./plugins/default.nix; globals = { mapleader = ","; diff --git a/common/home/programs/nixvim/plugins/cmp.nix b/common/home/programs/nixvim/plugins/cmp.nix new file mode 100644 index 0000000..27cca04 --- /dev/null +++ b/common/home/programs/nixvim/plugins/cmp.nix @@ -0,0 +1,45 @@ +{ ... }: +{ + enable = true; + autoEnableSources = true; + settings = { + mapping = { + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.abort()"; + "" = "cmp.mapping.confirm({ select = true })"; + "" = '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { "i", "s" }) + ''; + "" = '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { "i", "s" }) + ''; + }; + snippet = { + expand = '' + function(args) + require('luasnip').lsp_expand(args.body) + end + ''; + }; + sources = [ + { name = "nvim_lsp"; } + { name = "luasnip"; } + { name = "path"; } + { name = "buffer"; } + ]; + }; +} diff --git a/common/home/programs/nixvim/plugins/dashboard.nix b/common/home/programs/nixvim/plugins/dashboard.nix new file mode 100644 index 0000000..77a9f3e --- /dev/null +++ b/common/home/programs/nixvim/plugins/dashboard.nix @@ -0,0 +1,68 @@ +{ ... }: +{ + enable = true; + settings = { + change_to_vcs_root = true; + config = { + footer = [ "" ]; + + header = [ + "███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗" + "████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║" + "██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║" + "██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║" + "██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║" + "╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝" + ]; + + mru = { + limit = 10; + }; + + project = { + enable = true; + }; + + packages.enable = false; + + shortcut = [ + { + action = { + __raw = '' + function(path) + vim.cmd('Telescope find_files') + end + ''; + }; + desc = "Files"; + group = "Label"; + icon = " "; + icon_hl = "@variable"; + key = "f"; + } + { + action = { + __raw = '' + function() + vim.cmd('cd ~/global/system/config'); vim.cmd('Telescope find_files') + end + ''; + }; + icon = "󱄅 "; + icon_hl = "@variable"; + desc = "System Config"; + group = "Number"; + key = "c"; + } + ]; + + hide = [ + "statusline" + "tabline" + "winbar" + ]; + }; + theme = "hyper"; + }; + }; + diff --git a/common/home/programs/nixvim/plugins/default.nix b/common/home/programs/nixvim/plugins/default.nix new file mode 100644 index 0000000..6005c57 --- /dev/null +++ b/common/home/programs/nixvim/plugins/default.nix @@ -0,0 +1,27 @@ +{ pkgs, ... }: +let + plugins = [ + "web-devicons" + "dashboard" + "nvim-tree" + "telescope" + "lualine" + "treesitter" + "luasnip" + "friendly-snippets" + "cmp" + "lsp" + ]; +in +{ + plugins = builtins.listToAttrs ( + map (n: { + name = n; + value = + if builtins.pathExists ./${n}.nix then + (import ./${n}.nix { inherit pkgs; }) + else + { enable = true; }; + }) plugins + ); +} diff --git a/common/home/programs/nixvim/plugins/friendly-snippets.nix b/common/home/programs/nixvim/plugins/friendly-snippets.nix new file mode 100644 index 0000000..3887830 --- /dev/null +++ b/common/home/programs/nixvim/plugins/friendly-snippets.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + enable = true; +} diff --git a/common/home/programs/nixvim/plugins/lsp-format.nix b/common/home/programs/nixvim/plugins/lsp-format.nix new file mode 100644 index 0000000..3887830 --- /dev/null +++ b/common/home/programs/nixvim/plugins/lsp-format.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + enable = true; +} diff --git a/common/home/programs/nixvim/plugins/lsp.nix b/common/home/programs/nixvim/plugins/lsp.nix new file mode 100644 index 0000000..578518f --- /dev/null +++ b/common/home/programs/nixvim/plugins/lsp.nix @@ -0,0 +1,39 @@ +{ pkgs, ... }: +{ + enable = true; + servers = { + + bashls = { + enable = true; + package = pkgs.unstable.bash-language-server; + }; + + clangd.enable = true; + + nixd = { + enable = true; + settings.formatting.command = [ "nixfmt" ]; + }; + + rust-analyzer = { + enable = true; + installCargo = true; + installRustc = true; + }; + + pyright.enable = true; + + ocamllsp.enable = true; + }; + + keymaps.lspBuf = { + "gd" = "definition"; + "gD" = "references"; + "gt" = "type_definition"; + "gi" = "implementation"; + "K" = "hover"; + "rn" = "rename"; + "ca" = "code_action"; + "f" = "format"; + }; +} diff --git a/common/home/programs/nixvim/plugins/lualine.nix b/common/home/programs/nixvim/plugins/lualine.nix new file mode 100644 index 0000000..3887830 --- /dev/null +++ b/common/home/programs/nixvim/plugins/lualine.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + enable = true; +} diff --git a/common/home/programs/nixvim/plugins/luasnip.nix b/common/home/programs/nixvim/plugins/luasnip.nix new file mode 100644 index 0000000..3887830 --- /dev/null +++ b/common/home/programs/nixvim/plugins/luasnip.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + enable = true; +} diff --git a/common/home/programs/nixvim/plugins/nvim-tree.nix b/common/home/programs/nixvim/plugins/nvim-tree.nix new file mode 100644 index 0000000..dbd3256 --- /dev/null +++ b/common/home/programs/nixvim/plugins/nvim-tree.nix @@ -0,0 +1,7 @@ +{ ... }: +{ + enable = true; + autoClose = true; + disableNetrw = true; + hijackCursor = true; +} diff --git a/common/home/programs/nixvim/plugins/telescope.nix b/common/home/programs/nixvim/plugins/telescope.nix new file mode 100644 index 0000000..3887830 --- /dev/null +++ b/common/home/programs/nixvim/plugins/telescope.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + enable = true; +} diff --git a/common/home/programs/nixvim/plugins/treesitter.nix b/common/home/programs/nixvim/plugins/treesitter.nix new file mode 100644 index 0000000..3fbd4b6 --- /dev/null +++ b/common/home/programs/nixvim/plugins/treesitter.nix @@ -0,0 +1,24 @@ +{ ... }: +{ + enable = true; + settings = { + auto_install = true; + highlight = { + additional_vim_regex_highlighting = true; + enable = true; + }; + incremental_selection = { + enable = true; + keymaps = { + init_selection = false; + node_decremental = "grm"; + node_incremental = "grn"; + scope_incremental = "grc"; + }; + }; + indent = { + enable = true; + }; + sync_install = false; + }; +} -- cgit v1.2.3-70-g09d2