From 80c38b5120e806b94627c391fdfabd12d53cdc36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 10 Jun 2023 21:52:57 +0200 Subject: [PATCH] feat(nvim): use lazy to load plugins --- modules/programs/nvim/default.nix | 239 +++++++++++++--- modules/programs/nvim/keybinds.lua | 73 ----- modules/programs/nvim/plugins/copilot-lua.lua | 8 +- modules/programs/nvim/plugins/default.nix | 254 ++++++++++++++++++ .../programs/nvim/plugins/formatter-nvim.lua | 4 - modules/programs/nvim/plugins/nvim-cmp.lua | 63 +++++ .../{init.lua => plugins/nvim-lspconfig.lua} | 84 ------ .../programs/nvim/plugins/nvim-treesitter.lua | 12 + .../programs/nvim/plugins/telescope-nvim.lua | 22 -- .../programs/nvim/plugins/trouble-nvim.lua | 37 --- .../programs/nvim/plugins/which-key-nvim.lua | 74 +++++ 11 files changed, 604 insertions(+), 266 deletions(-) delete mode 100644 modules/programs/nvim/keybinds.lua create mode 100644 modules/programs/nvim/plugins/default.nix create mode 100644 modules/programs/nvim/plugins/nvim-cmp.lua rename modules/programs/nvim/{init.lua => plugins/nvim-lspconfig.lua} (65%) create mode 100644 modules/programs/nvim/plugins/nvim-treesitter.lua delete mode 100644 modules/programs/nvim/plugins/telescope-nvim.lua diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index ac10533..aacfb4c 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -7,22 +7,207 @@ with lib; let cfg = config.my.programs.nvim; - - mkPlugin = fileName: + boolToString = bool: if bool then "true" else "false"; + quote = str: ''"${toString str}"''; + listToString = list: ''{ ${concatStringsSep ", " (map quote list)} }''; + keybinding = + { key + , cmd + , func + , mode + , desc + }: let - path = ./plugins + "/${fileName}"; - pluginName = lib.removeSuffix ".lua" fileName; + cmdString = + if cmd != null + then quote cmd + else + ( + if func != null + then func + else abort "Either cmd or function must be set" + ); in - { - plugin = pkgs.vimPlugins.${pluginName}; - type = "lua"; - config = lib.readFile path; - }; - pluginFileNames = builtins.attrNames (builtins.readDir ./plugins); - pluginsWithConfig = builtins.map mkPlugin pluginFileNames; + ''{ ${quote key}, ${cmdString}, mode = ${quote mode}, ${optionalString (desc != null) "desc = ${quote desc},"} }''; + lazySpecFromPlugin = + { plugin + , dependencies + , init + , conf + , lazy + , event + , enabled + , cmd + , ft + , priority + , keys + }: + '' + { + dir = "${plugin}", + name = "${plugin.name}", + lazy = ${boolToString lazy}, + enabled = ${boolToString enabled}, + dependencies = { ${concatStringsSep ", " (map lazySpecFromPlugin dependencies)} }, + ${optionalString (init != null) + "init = function(plugin) + ${toString init} + end," + } + ${optionalString (conf != null) + "config = function(plugin, opts) + ${toString conf} + end," + } + keys = { ${concatStringsSep ",\n" (map keybinding keys)} }, + event = ${listToString event}, + cmd = ${listToString cmd}, + ft = ${listToString ft}, + priority = ${toString priority}, + } + ''; + lazySpecs = concatStringsSep ", " (map lazySpecFromPlugin cfg.plugins); + lazy = '' + require("lazy").setup({ + ${lazySpecs} + }) + ''; in { - options.my.programs.nvim.enable = mkEnableOption "nvim"; + imports = [ ./plugins ]; + + options.my.programs.nvim = { + enable = mkEnableOption "nvim"; + plugins = mkOption { + default = [ ]; + description = '' + List of plugins with config. + ''; + type = with types; listOf ( + let + sub = submodule { + options = { + conf = mkOption { + type = nullOr str; + default = null; + description = '' + Lua code to be executed when the plugin is loaded. + ''; + }; + dependencies = mkOption { + type = listOf sub; + default = [ ]; + description = '' + List of plugins this plugin depends on. + ''; + }; + init = mkOption { + type = nullOr str; + default = null; + description = '' + Lua code to be executed when the plugin is initialized. + ''; + }; + event = mkOption { + type = listOf str; + default = [ ]; + description = '' + Event to load the plugin on. + ''; + }; + lazy = mkOption { + type = bool; + default = false; + description = '' + Whether to load the plugin lazily. + ''; + }; + plugin = mkOption { + type = package; + description = '' + The plugin package. + ''; + }; + enabled = mkOption { + type = bool; + default = true; + description = '' + Whether to enable the plugin. + ''; + }; + cmd = mkOption { + type = listOf str; + default = [ ]; + description = '' + Command to load the plugin. + ''; + }; + ft = mkOption { + type = listOf str; + default = [ ]; + description = '' + Filetype to load the plugin on. + ''; + }; + priority = mkOption { + type = int; + default = 50; + description = '' + Priority to load the plugin. + ''; + }; + keys = mkOption { + default = [ ]; + description = '' + List of keybindings. + ''; + type = listOf (submodule { + options = { + key = mkOption { + type = str; + description = '' + Key to bind. + ''; + }; + cmd = mkOption { + type = nullOr str; + default = null; + description = '' + Command to execute. + ''; + }; + func = mkOption { + type = nullOr str; + default = null; + description = '' + Function to execute. + ''; + }; + mode = mkOption { + type = str; + default = "n"; + description = '' + Mode to bind the key in. + ''; + }; + desc = mkOption { + type = nullOr str; + default = null; + description = '' + Description of the keybinding. + ''; + }; + }; + }); + }; + }; + }; + in + sub + ); + }; + }; + config = mkIf cfg.enable { home-manager.users.moritz = { @@ -41,11 +226,7 @@ in vimdiffAlias = true; withNodeJs = true; withPython3 = true; - extraLuaConfig = lib.concatLines ( - builtins.map - builtins.readFile - [ ./options.lua ./keybinds.lua ./init.lua ] - ); + extraLuaConfig = lib.concatLines [ (builtins.readFile ./options.lua) lazy ]; extraPackages = with pkgs; [ alejandra black @@ -66,30 +247,10 @@ in yamlfmt ]; plugins = with pkgs.vimPlugins; [ - cmp-async-path - cmp-nvim-lsp - cmp_luasnip - copilot-cmp - direnv-vim - friendly-snippets - lsp_lines-nvim - lspkind-nvim - lspsaga-nvim-original - luasnip - nui-nvim - nvim-cmp - nvim-lspconfig + lazy-nvim nvim-treesitter.withAllGrammars - nvim-ufo - nvim-web-devicons - plenary-nvim - popup-nvim - promise-async - vim-fugitive - vim-tmux-navigator - ] ++ pluginsWithConfig; + ]; }; }; }; } - diff --git a/modules/programs/nvim/keybinds.lua b/modules/programs/nvim/keybinds.lua deleted file mode 100644 index 35325cc..0000000 --- a/modules/programs/nvim/keybinds.lua +++ /dev/null @@ -1,73 +0,0 @@ --- buffer -require("which-key").register({ - b = { - name = "buffer", - b = { "Telescope buffers", "List buffers" }, - d = { "bd", "Delete buffer" }, - }, -}, { prefix = "" }) -require("which-key").register({ - ["["] = { - b = { "bprevious", "Previous buffer" }, - }, - ["]"] = { - b = { "bnext", "Next buffer" }, - }, -}) - --- window -require("which-key").register({ - w = { - name = "window", - ["|"] = { "v", "Split window horizontally" }, - ["-"] = { "s", "Split window vertically" }, - w = { "w", "Switch window" }, - d = { "c", "Delete window" }, - }, -}, { prefix = "" }) - --- tab -require("which-key").register({ - [""] = { - name = "tab", - [""] = { "tabnew", "New tab" }, - n = { "tabnext", "Next tab" }, - p = { "tabprevious", "Previous tab" }, - d = { "tabclose", "Close tab" }, - }, -}, { prefix = "" }) - --- file -require("which-key").register({ - f = { - name = "file/find", - n = { "enew", "New file" }, - }, -}, { prefix = "" }) - --- better descriptions for navigation -require("which-key").register({ - [""] = { - f = { name = "file/find" }, - g = { name = "git" }, - l = { name = "lsp" }, - o = { name = "org" }, - s = { name = "search" }, - t = { name = "toggle" }, - x = { name = "diagnostics/quickfix" }, - }, - ["["] = { name = "prev" }, - ["]"] = { name = "next" }, - g = { name = "goto" }, -}) - --- Clear search with -require("which-key").register({ - [""] = { "noh", "Escape and clear hlsearch", mode = { "n", "i" } }, -}) - --- better indenting -require("which-key").register({ - ["<"] = { ""] = { ">gv", "Shift right" }, -}, { mode = "v" }) diff --git a/modules/programs/nvim/plugins/copilot-lua.lua b/modules/programs/nvim/plugins/copilot-lua.lua index 94e9600..f9799dc 100644 --- a/modules/programs/nvim/plugins/copilot-lua.lua +++ b/modules/programs/nvim/plugins/copilot-lua.lua @@ -2,10 +2,4 @@ require("copilot").setup({ suggestion = { enabled = false }, panel = { enabled = false }, }) -vim.api.nvim_create_autocmd("VimEnter", { - desc = "Disable Copilot by default on startup", - command = "Copilot disable", -}) -require("which-key").register({ - c = { "Copilot toggle", "Toggle Copilot" }, -}, { prefix = "t" }) +vim.cmd("Copilot disable") diff --git a/modules/programs/nvim/plugins/default.nix b/modules/programs/nvim/plugins/default.nix new file mode 100644 index 0000000..3b40c98 --- /dev/null +++ b/modules/programs/nvim/plugins/default.nix @@ -0,0 +1,254 @@ +{ pkgs, ... }: + +with builtins; +{ + config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ + { + plugin = which-key-nvim; + conf = readFile ./which-key-nvim.lua; + } + { + plugin = catppuccin-nvim; + conf = readFile ./catppuccin-nvim.lua; + priority = 99; + } + { + plugin = formatter-nvim; + lazy = true; + keys = [ + { key = "="; cmd = "Format"; desc = "format (formatter)"; } + ]; + conf = readFile ./formatter-nvim.lua; + dependencies = [{ plugin = which-key-nvim; lazy = true; }]; + } + { + plugin = oil-nvim; + conf = readFile ./oil-nvim.lua; + dependencies = [ + { plugin = which-key-nvim; lazy = true; } + { plugin = nvim-web-devicons; lazy = true; } + ]; + } + { + plugin = mini-nvim; + conf = readFile ./mini-nvim.lua; + } + { + plugin = noice-nvim; + conf = readFile ./noice-nvim.lua; + dependencies = [{ plugin = nui-nvim; lazy = true; }]; + } + { + plugin = trouble-nvim; + lazy = true; + keys = [ + { key = "xx"; cmd = "TroubleToggle document_diagnostics"; desc = "Document Diagnostics (Trouble)"; } + { key = "xX"; cmd = "TroubleToggle workspace_diagnostics"; desc = "Workspace Diagnostics (Troule)"; } + { key = "xl"; cmd = "TroubleToggle loclist"; desc = "Location List (Trouble)"; } + { key = "xq"; cmd = "TroubleToggle quickfix"; desc = "Quickfix List (Trouble)"; } + { key = "xt"; cmd = "TodoTrouble"; desc = "Todo (Trouble)"; } + { key = "xT"; cmd = "TodoTrouble keywords=TODO,FIX,FIXME"; desc = "Todo/Fix/Fixme (Trouble)"; } + { key = "st"; cmd = "TodoTelescope"; desc = "Todo"; } + { + key = "[q"; + func = ''function() + if require("trouble").is_open() then + require("trouble").previous({ skip_groups = true, jump = true }) + else + vim.cmd.cprev() + end + end''; + desc = "Previous trouble/quickfix item"; + } + { + key = "]q"; + func = ''function() + if require("trouble").is_open() then + require("trouble").next({ skip_groups = true, jump = true }) + else + vim.cmd.cnext() + end + end''; + desc = "Next trouble/quickfix item"; + } + ]; + conf = readFile ./trouble-nvim.lua; + dependencies = [ + { plugin = which-key-nvim; } + { plugin = nvim-web-devicons; lazy = true; } + ]; + } + { + plugin = nvim-cmp; + conf = readFile ./nvim-cmp.lua; + lazy = true; + event = [ "InsertEnter" ]; + dependencies = [ + { plugin = cmp-async-path; } + { plugin = cmp-nvim-lsp; } + { plugin = cmp_luasnip; } + { + plugin = copilot-cmp; + dependencies = [ + { + plugin = copilot-lua; + conf = readFile ./copilot-lua.lua; + dependencies = [{ plugin = which-key-nvim; }]; + } + ]; + } + { plugin = friendly-snippets; } + { plugin = luasnip; lazy = true; } + ]; + } + { + plugin = todo-comments-nvim; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./todo-comments-nvim.lua; + dependencies = [{ plugin = plenary-nvim; lazy = true; }]; + } + { + plugin = direnv-vim; + } + { + plugin = nvim-treesitter.withAllGrammars; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./nvim-treesitter.lua; + dependencies = [ + { + plugin = orgmode; + lazy = true; + conf = readFile ./orgmode.lua; + } + ]; + } + { + plugin = nvim-lspconfig; + lazy = true; + event = [ "BufReadPre" "BufNewFile" ]; + conf = readFile ./nvim-lspconfig.lua; + dependencies = [ + { + plugin = null-ls-nvim; + lazy = true; + conf = readFile ./null-ls-nvim.lua; + dependencies = [ + { plugin = which-key-nvim; lazy = true; } + { plugin = plenary-nvim; lazy = true; } + ]; + } + { + plugin = which-key-nvim; + lazy = true; + } + { + plugin = lspkind-nvim; + lazy = true; + } + { + plugin = lsp_lines-nvim; + lazy = true; + } + { + plugin = lspsaga-nvim-original; + lazy = true; + dependencies = [ + { plugin = nvim-web-devicons; lazy = true; } + { plugin = nvim-treesitter.withAllGrammars; lazy = true; } + ]; + } + { + plugin = nvim-ufo; + lazy = true; + dependencies = [ + { plugin = promise-async; lazy = true; } + ]; + } + ]; + } + { + event = [ "VeryLazy" ]; + lazy = true; + plugin = vim-fugitive; + } + { + plugin = vim-tmux-navigator; + } + { + plugin = gitsigns-nvim; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./gitsigns-nvim.lua; + dependencies = [{ plugin = which-key-nvim; }]; + } + { + plugin = nvim-lastplace; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./nvim-lastplace.lua; + } + { + plugin = nvim-treesitter-textsubjects; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./nvim-treesitter-textsubjects.lua; + dependencies = [ + { + plugin = nvim-treesitter.withAllGrammars; + lazy = true; + } + ]; + } + { + plugin = nvim-ts-context-commentstring; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./nvim-ts-context-commentstring.lua; + dependencies = [ + { + plugin = nvim-treesitter.withAllGrammars; + lazy = true; + } + ]; + } + { + plugin = smartcolumn-nvim; + lazy = true; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./smartcolumn-nvim.lua; + } + { + plugin = telescope-fzf-native-nvim; + conf = readFile ./telescope-fzf-native-nvim.lua; + lazy = true; + keys = [ + { key = "ff"; cmd = "Telescope find_files"; desc = "Find files"; } + { key = "fb"; cmd = "Telescope buffers"; desc = "Find buffers"; } + { key = "fr"; cmd = "Telescope oldfiles"; desc = "Find recent files"; } + { key = "sl"; cmd = "Telescope current_buffer_fuzzy_find"; desc = "Search lines"; } + { key = "sg"; cmd = "Telescope live_grep"; desc = "Live grep"; } + { key = "sc"; cmd = "Telescope command_history"; desc = "Command history"; } + { key = "sC"; cmd = "Telescope commands"; desc = "Commands"; } + { key = "sd"; cmd = "Telescope diagnostics"; desc = "Diagnostics"; } + { key = "sh"; cmd = "Telescope help_tags"; desc = "Help tags"; } + { key = "sk"; cmd = "Telescope keymaps"; desc = "Keymaps"; } + { key = "ss"; cmd = "Telescope lsp_document_symbols"; desc = "Symbols (Document)"; } + { key = "sS"; cmd = "Telescope lsp_workspace_symbols"; desc = "Symbols (Workspace)"; } + { key = "gc"; cmd = "Telescope git_commits"; desc = "Commits"; } + { key = "gs"; cmd = "Telescope git_status"; desc = "Status"; } + ]; + dependencies = [ + { + plugin = telescope-nvim; + lazy = true; + dependencies = [ + { plugin = plenary-nvim; lazy = true; } + { plugin = which-key-nvim; lazy = true; } + ]; + } + ]; + } + ]; +} diff --git a/modules/programs/nvim/plugins/formatter-nvim.lua b/modules/programs/nvim/plugins/formatter-nvim.lua index b72b72a..adbdeeb 100644 --- a/modules/programs/nvim/plugins/formatter-nvim.lua +++ b/modules/programs/nvim/plugins/formatter-nvim.lua @@ -65,7 +65,3 @@ end, { return languages[vim.bo.filetype] or {} end, }) - -require("which-key").register({ - ["="] = { "Format", "format (formatter)" }, -}, { noremap = true, silent = true }) diff --git a/modules/programs/nvim/plugins/nvim-cmp.lua b/modules/programs/nvim/plugins/nvim-cmp.lua new file mode 100644 index 0000000..0533cb7 --- /dev/null +++ b/modules/programs/nvim/plugins/nvim-cmp.lua @@ -0,0 +1,63 @@ +local cmp = require("cmp") +local luasnip = require("luasnip") +require("luasnip.loaders.from_vscode").lazy_load() +require("copilot_cmp").setup() + +local default_sources = { + { name = "async_path", priority = 1 }, + { name = "copilot", priority = 2 }, + { name = "luasnip", priority = 2 }, + { name = "nvim_lsp", priority = 3 }, +} + +cmp.setup({ + formatting = { + format = require("lspkind").cmp_format({ + mode = "symbol", -- show only symbol annotations + maxwidth = 50, -- prevent the popup from showing more than provided characters + ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead + symbol_map = { + Copilot = "", + }, + }), + }, + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = 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() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = default_sources, +}) + +cmp.setup.filetype("org", { + sources = vim.tbl_deep_extend("force", default_sources, { + { name = "buffer", priority = 1 }, + { name = "orgmode", priority = 3 }, + }), +}) diff --git a/modules/programs/nvim/init.lua b/modules/programs/nvim/plugins/nvim-lspconfig.lua similarity index 65% rename from modules/programs/nvim/init.lua rename to modules/programs/nvim/plugins/nvim-lspconfig.lua index cb933b2..75c3e5d 100644 --- a/modules/programs/nvim/init.lua +++ b/modules/programs/nvim/plugins/nvim-lspconfig.lua @@ -1,87 +1,3 @@ -vim.loader.enable() - --- Load custom treesitter grammar for org filetype -require("orgmode").setup_ts_grammar() -require("nvim-treesitter.configs").setup({ - sync_install = false, - auto_install = false, - highlight = { - enable = true, - -- Required for spellcheck, some LaTex highlights and - -- code block highlights that do not have ts grammar - additional_vim_regex_highlighting = { "org" }, - }, -}) - --- load cmp on InsertEnter -vim.api.nvim_create_autocmd("InsertEnter", { - callback = function() - local cmp = require("cmp") - local luasnip = require("luasnip") - require("luasnip.loaders.from_vscode").lazy_load() - require("copilot_cmp").setup() - - local default_sources = { - { name = "async_path", priority = 1 }, - { name = "copilot", priority = 2 }, - { name = "luasnip", priority = 2 }, - { name = "nvim_lsp", priority = 3 }, - } - - cmp.setup({ - formatting = { - format = require("lspkind").cmp_format({ - mode = "symbol", -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters - ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead - symbol_map = { - Copilot = "", - }, - }), - }, - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = 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() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }), - sources = default_sources, - }) - - cmp.setup.filetype("org", { - sources = vim.tbl_deep_extend("force", default_sources, { - { name = "buffer", priority = 1 }, - { name = "orgmode", priority = 3 }, - }), - }) - end, -}) - local lsp_lines = require("lsp_lines") lsp_lines.setup() -- Disable virtual_text since it's redundant due to lsp_lines. diff --git a/modules/programs/nvim/plugins/nvim-treesitter.lua b/modules/programs/nvim/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..c856c13 --- /dev/null +++ b/modules/programs/nvim/plugins/nvim-treesitter.lua @@ -0,0 +1,12 @@ +-- Load custom treesitter grammar for org filetype +require("orgmode").setup_ts_grammar() +require("nvim-treesitter.configs").setup({ + sync_install = false, + auto_install = false, + highlight = { + enable = true, + -- Required for spellcheck, some LaTex highlights and + -- code block highlights that do not have ts grammar + additional_vim_regex_highlighting = { "org" }, + }, +}) diff --git a/modules/programs/nvim/plugins/telescope-nvim.lua b/modules/programs/nvim/plugins/telescope-nvim.lua deleted file mode 100644 index 95b228c..0000000 --- a/modules/programs/nvim/plugins/telescope-nvim.lua +++ /dev/null @@ -1,22 +0,0 @@ -require("which-key").register({ - f = { - f = { "Telescope find_files", "Find files" }, - b = { "Telescope buffers", "Find buffers" }, - r = { "Telescope oldfiles", "Find recent files" }, - }, - s = { - l = { "Telescope current_buffer_fuzzy_find", "Search lines" }, - g = { "Telescope live_grep", "Live grep" }, - c = { "Telescope command_history", "Command history" }, - C = { "Telescope commands", "Commands" }, - d = { "Telescope diagnostics", "Diagnostics" }, - h = { "Telescope help_tags", "Help tags" }, - k = { "Telescope keymaps", "Keymaps" }, - s = { "Telescope lsp_document_symbols", "Symbols (Document)" }, - S = { "Telescope lsp_workspace_symbols", "Symbols (Workspace)" }, - }, - g = { - c = { "Telescope git_commits", "Commits" }, - s = { "Telescope git_status", "Status" }, - }, -}, { prefix = "" }) diff --git a/modules/programs/nvim/plugins/trouble-nvim.lua b/modules/programs/nvim/plugins/trouble-nvim.lua index 9a98571..38ef1e9 100644 --- a/modules/programs/nvim/plugins/trouble-nvim.lua +++ b/modules/programs/nvim/plugins/trouble-nvim.lua @@ -1,38 +1 @@ require("trouble").setup() -require("which-key").register({ - x = { "TroubleToggle document_diagnostics", "Document Diagnostics (Trouble)" }, - X = { "TroubleToggle workspace_diagnostics", "Workspace Diagnostics (Troule)" }, - l = { "TroubleToggle loclist", "Location List (Trouble)" }, - q = { "TroubleToggle quickfix", "Quickfix List (Trouble)" }, - t = { "TodoTrouble", "Todo (Trouble)" }, - T = { "TodoTrouble keywords=TODO,FIX,FIXME", "Todo/Fix/Fixme (Trouble)" }, -}, { prefix = "x" }) -require("which-key").register({ - t = { "TodoTelescope", "Todo" }, -}, { prefix = "s" }) -require("which-key").register({ - ["["] = { - q = { - function() - if require("trouble").is_open() then - require("trouble").previous({ skip_groups = true, jump = true }) - else - vim.cmd.cprev() - end - end, - "Previous trouble/quickfix item", - }, - }, - ["]"] = { - q = { - function() - if require("trouble").is_open() then - require("trouble").next({ skip_groups = true, jump = true }) - else - vim.cmd.cnext() - end - end, - "Next trouble/quickfix item", - }, - }, -}) diff --git a/modules/programs/nvim/plugins/which-key-nvim.lua b/modules/programs/nvim/plugins/which-key-nvim.lua index e70fb09..82d4b90 100644 --- a/modules/programs/nvim/plugins/which-key-nvim.lua +++ b/modules/programs/nvim/plugins/which-key-nvim.lua @@ -1,2 +1,76 @@ vim.o.timeout = true vim.o.timeoutlen = 500 + +-- buffer +require("which-key").register({ + b = { + name = "buffer", + b = { "Telescope buffers", "List buffers" }, + d = { "bd", "Delete buffer" }, + }, +}, { prefix = "" }) +require("which-key").register({ + ["["] = { + b = { "bprevious", "Previous buffer" }, + }, + ["]"] = { + b = { "bnext", "Next buffer" }, + }, +}) + +-- window +require("which-key").register({ + w = { + name = "window", + ["|"] = { "v", "Split window horizontally" }, + ["-"] = { "s", "Split window vertically" }, + w = { "w", "Switch window" }, + d = { "c", "Delete window" }, + }, +}, { prefix = "" }) + +-- tab +require("which-key").register({ + [""] = { + name = "tab", + [""] = { "tabnew", "New tab" }, + n = { "tabnext", "Next tab" }, + p = { "tabprevious", "Previous tab" }, + d = { "tabclose", "Close tab" }, + }, +}, { prefix = "" }) + +-- file +require("which-key").register({ + f = { + name = "file/find", + n = { "enew", "New file" }, + }, +}, { prefix = "" }) + +-- better descriptions for navigation +require("which-key").register({ + [""] = { + f = { name = "file/find" }, + g = { name = "git" }, + l = { name = "lsp" }, + o = { name = "org" }, + s = { name = "search" }, + t = { name = "toggle" }, + x = { name = "diagnostics/quickfix" }, + }, + ["["] = { name = "prev" }, + ["]"] = { name = "next" }, + g = { name = "goto" }, +}) + +-- Clear search with +require("which-key").register({ + [""] = { "noh", "Escape and clear hlsearch", mode = { "n", "i" } }, +}) + +-- better indenting +require("which-key").register({ + ["<"] = { ""] = { ">gv", "Shift right" }, +}, { mode = "v" })