From e0fdcfa86da86a6f2164e6b79a00a3c114bab83a Mon Sep 17 00:00:00 2001 From: dunix241 Date: Mon, 28 Oct 2024 19:04:40 +0700 Subject: [PATCH] feat(keymaps): enable modifying and disabling keymaps --- lua/lazyvim/config/autocmds.lua | 4 +- lua/lazyvim/config/keymaps.lua | 173 ++--- lua/lazyvim/keymaps.lua | 673 ++++++++++++++++++ lua/lazyvim/plugins/coding.lua | 45 +- lua/lazyvim/plugins/editor.lua | 283 ++++---- .../plugins/extras/coding/copilot-chat.lua | 15 +- lua/lazyvim/plugins/extras/coding/luasnip.lua | 8 +- .../plugins/extras/coding/mini-surround.lua | 16 +- lua/lazyvim/plugins/extras/coding/yanky.lua | 53 +- lua/lazyvim/plugins/extras/dap/core.lua | 42 +- lua/lazyvim/plugins/extras/editor/aerial.lua | 10 +- lua/lazyvim/plugins/extras/editor/dial.lua | 9 +- lua/lazyvim/plugins/extras/editor/fzf.lua | 114 +-- .../plugins/extras/editor/harpoon2.lua | 8 +- .../plugins/extras/editor/illuminate.lua | 16 +- .../plugins/extras/editor/inc-rename.lua | 4 +- lua/lazyvim/plugins/extras/editor/leap.lua | 26 +- .../plugins/extras/editor/mini-diff.lua | 4 +- .../plugins/extras/editor/mini-files.lua | 13 +- lua/lazyvim/plugins/extras/editor/outline.lua | 22 +- .../plugins/extras/editor/overseer.lua | 18 +- .../plugins/extras/editor/refactoring.lua | 26 +- .../plugins/extras/editor/telescope.lua | 141 ++-- lua/lazyvim/plugins/extras/lang/ansible.lua | 4 +- lua/lazyvim/plugins/extras/lang/clangd.lua | 4 +- lua/lazyvim/plugins/extras/lang/clojure.lua | 15 +- lua/lazyvim/plugins/extras/lang/elixir.lua | 6 +- lua/lazyvim/plugins/extras/lang/java.lua | 32 +- lua/lazyvim/plugins/extras/lang/lean.lua | 4 +- lua/lazyvim/plugins/extras/lang/markdown.lua | 6 +- lua/lazyvim/plugins/extras/lang/omnisharp.lua | 4 +- lua/lazyvim/plugins/extras/lang/python.lua | 12 +- lua/lazyvim/plugins/extras/lang/r.lua | 33 +- lua/lazyvim/plugins/extras/lang/rust.lua | 9 +- lua/lazyvim/plugins/extras/lang/scala.lua | 6 +- lua/lazyvim/plugins/extras/lang/sql.lua | 4 +- lua/lazyvim/plugins/extras/lang/svelte.lua | 4 +- lua/lazyvim/plugins/extras/lang/tex.lua | 6 +- .../plugins/extras/lang/typescript.lua | 16 +- lua/lazyvim/plugins/extras/test/core.lua | 24 +- lua/lazyvim/plugins/extras/ui/alpha.lua | 30 +- lua/lazyvim/plugins/extras/ui/edgy.lua | 52 +- .../plugins/extras/ui/mini-animate.lua | 4 +- .../plugins/extras/ui/treesitter-context.lua | 4 +- lua/lazyvim/plugins/extras/util/chezmoi.lua | 12 +- lua/lazyvim/plugins/extras/util/gitui.lua | 6 +- lua/lazyvim/plugins/extras/util/octo.lua | 32 +- lua/lazyvim/plugins/extras/util/project.lua | 13 +- lua/lazyvim/plugins/extras/util/rest.lua | 12 +- lua/lazyvim/plugins/extras/vscode.lua | 9 +- lua/lazyvim/plugins/formatting.lua | 3 +- lua/lazyvim/plugins/lsp/init.lua | 3 +- lua/lazyvim/plugins/lsp/keymaps.lua | 109 ++- lua/lazyvim/plugins/treesitter.lua | 40 +- lua/lazyvim/plugins/ui.lua | 133 +++- lua/lazyvim/plugins/util.lua | 10 +- lua/lazyvim/util/init.lua | 15 +- lua/lazyvim/util/mini.lua | 4 +- 58 files changed, 1729 insertions(+), 674 deletions(-) create mode 100644 lua/lazyvim/keymaps.lua diff --git a/lua/lazyvim/config/autocmds.lua b/lua/lazyvim/config/autocmds.lua index 6fe6b139..72763fd1 100644 --- a/lua/lazyvim/config/autocmds.lua +++ b/lua/lazyvim/config/autocmds.lua @@ -1,5 +1,7 @@ -- This file is automatically loaded by lazyvim.config.init. +local k = require("lazyvim.keymaps").get_keymaps() + local function augroup(name) return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true }) end @@ -73,7 +75,7 @@ vim.api.nvim_create_autocmd("FileType", { callback = function(event) vim.bo[event.buf].buflisted = false vim.schedule(function() - vim.keymap.set("n", "q", function() + LazyVim.keymap_set("n", k.quit_buffer, function() vim.cmd("close") pcall(vim.api.nvim_buf_delete, event.buf, { force = true }) end, { diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 84bba42c..5f3edd06 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -3,6 +3,7 @@ -- DO NOT USE `LazyVim.safe_keymap_set` IN YOUR OWN CONFIG!! -- use `vim.keymap.set` instead local map = LazyVim.safe_keymap_set +local k = require("lazyvim.keymaps").get_keymaps().keymaps -- better up/down map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { desc = "Down", expr = true, silent = true }) @@ -11,34 +12,34 @@ map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { desc = "Up", expr = true, map({ "n", "x" }, "", "v:count == 0 ? 'gk' : 'k'", { desc = "Up", expr = true, silent = true }) -- Move to window using the hjkl keys -map("n", "", "h", { desc = "Go to Left Window", remap = true }) -map("n", "", "j", { desc = "Go to Lower Window", remap = true }) -map("n", "", "k", { desc = "Go to Upper Window", remap = true }) -map("n", "", "l", { desc = "Go to Right Window", remap = true }) +map("n", k.window.left, "h", { desc = "Go to Left Window", remap = true }) +map("n", k.window.lower, "j", { desc = "Go to Lower Window", remap = true }) +map("n", k.window.upper, "k", { desc = "Go to Upper Window", remap = true }) +map("n", k.window.right, "l", { desc = "Go to Right Window", remap = true }) -- Resize window using arrow keys -map("n", "", "resize +2", { desc = "Increase Window Height" }) -map("n", "", "resize -2", { desc = "Decrease Window Height" }) -map("n", "", "vertical resize -2", { desc = "Decrease Window Width" }) -map("n", "", "vertical resize +2", { desc = "Increase Window Width" }) +map("n", k.resize_window.increase_height, "resize +2", { desc = "Increase Window Height" }) +map("n", k.resize_window.decrease_height, "resize -2", { desc = "Decrease Window Height" }) +map("n", k.resize_window.decrease_width, "vertical resize -2", { desc = "Decrease Window Width" }) +map("n", k.resize_window.increase_width, "vertical resize +2", { desc = "Increase Window Width" }) -- Move Lines -map("n", "", "execute 'move .+' . v:count1==", { desc = "Move Down" }) -map("n", "", "execute 'move .-' . (v:count1 + 1)==", { desc = "Move Up" }) -map("i", "", "m .+1==gi", { desc = "Move Down" }) -map("i", "", "m .-2==gi", { desc = "Move Up" }) -map("v", "", ":execute \"'<,'>move '>+\" . v:count1gv=gv", { desc = "Move Down" }) -map("v", "", ":execute \"'<,'>move '<-\" . (v:count1 + 1)gv=gv", { desc = "Move Up" }) +map("n", k.move_lines.down, "execute 'move .+' . v:count1==", { desc = "Move Down" }) +map("n", k.move_lines.up, "execute 'move .-' . (v:count1 + 1)==", { desc = "Move Up" }) +map("i", k.move_lines.down, "m .+1==gi", { desc = "Move Down" }) +map("i", k.move_lines.up, "m .-2==gi", { desc = "Move Up" }) +map("v", k.move_lines.down, ":execute \"'<,'>move '>+\" . v:count1gv=gv", { desc = "Move Down" }) +map("v", k.move_lines.up, ":execute \"'<,'>move '<-\" . (v:count1 + 1)gv=gv", { desc = "Move Up" }) -- buffers -map("n", "", "bprevious", { desc = "Prev Buffer" }) -map("n", "", "bnext", { desc = "Next Buffer" }) -map("n", "[b", "bprevious", { desc = "Prev Buffer" }) -map("n", "]b", "bnext", { desc = "Next Buffer" }) -map("n", "bb", "e #", { desc = "Switch to Other Buffer" }) -map("n", "`", "e #", { desc = "Switch to Other Buffer" }) -map("n", "bd", LazyVim.ui.bufremove, { desc = "Delete Buffer" }) -map("n", "bD", ":bd", { desc = "Delete Buffer and Window" }) +map("n", k.buffers.prev, "bprevious", { desc = "Prev Buffer" }) +map("n", k.buffers.next, "bnext", { desc = "Next Buffer" }) +map("n", k.buffers.prev_alt, "bprevious", { desc = "Prev Buffer" }) +map("n", k.buffers.next_alt, "bnext", { desc = "Next Buffer" }) +map("n", k.buffers.switch_to_other, "e #", { desc = "Switch to Other Buffer" }) +map("n", k.buffers.switch_to_other_alt, "e #", { desc = "Switch to Other Buffer" }) +map("n", k.buffers.delete, LazyVim.ui.bufremove, { desc = "Delete Buffer" }) +map("n", k.buffers.delete_and_close, ":bd", { desc = "Delete Buffer and Window" }) -- Clear search with map({ "i", "n" }, "", "noh", { desc = "Escape and Clear hlsearch" }) @@ -47,7 +48,7 @@ map({ "i", "n" }, "", "noh", { desc = "Escape and Clear hlsea -- taken from runtime/lua/_editor.lua map( "n", - "ur", + k.clear_search_diff_update_and_redraw, "nohlsearchdiffupdatenormal! ", { desc = "Redraw / Clear hlsearch / Diff Update" } ) @@ -66,33 +67,33 @@ map("i", ".", ".u") map("i", ";", ";u") -- save file -map({ "i", "x", "n", "s" }, "", "w", { desc = "Save File" }) +map({ "i", "x", "n", "s" }, k.save_file, "w", { desc = "Save File" }) --keywordprg -map("n", "K", "norm! K", { desc = "Keywordprg" }) +map("n", k.keywordprg, "norm! K", { desc = "Keywordprg" }) -- better indenting map("v", "<", "", ">gv") -- commenting -map("n", "gco", "oVcxnormal gccfxa", { desc = "Add Comment Below" }) -map("n", "gcO", "OVcxnormal gccfxa", { desc = "Add Comment Above" }) +map("n", k.commenting.add_comment_below, "oVcxnormal gccfxa", { desc = "Add Comment Below" }) +map("n", k.commenting.add_comment_above, "OVcxnormal gccfxa", { desc = "Add Comment Above" }) -- lazy -map("n", "l", "Lazy", { desc = "Lazy" }) +map("n", k.lazy, "Lazy", { desc = "Lazy" }) -- new file -map("n", "fn", "enew", { desc = "New File" }) +map("n", k.new_file, "enew", { desc = "New File" }) -map("n", "xl", "lopen", { desc = "Location List" }) -map("n", "xq", "copen", { desc = "Quickfix List" }) +map("n", k.location_list, "lopen", { desc = "Location List" }) +map("n", k.quickfix_list, "copen", { desc = "Quickfix List" }) -map("n", "[q", vim.cmd.cprev, { desc = "Previous Quickfix" }) -map("n", "]q", vim.cmd.cnext, { desc = "Next Quickfix" }) +map("n", k.previous_quickfix, vim.cmd.cprev, { desc = "Previous Quickfix" }) +map("n", k.next_quickfix, vim.cmd.cnext, { desc = "Next Quickfix" }) -- formatting -map({ "n", "v" }, "cf", function() +map({ "n", "v" }, k.format, function() LazyVim.format({ force = true }) end, { desc = "Format" }) @@ -104,87 +105,87 @@ local diagnostic_goto = function(next, severity) go({ severity = severity }) end end -map("n", "cd", vim.diagnostic.open_float, { desc = "Line Diagnostics" }) -map("n", "]d", diagnostic_goto(true), { desc = "Next Diagnostic" }) -map("n", "[d", diagnostic_goto(false), { desc = "Prev Diagnostic" }) -map("n", "]e", diagnostic_goto(true, "ERROR"), { desc = "Next Error" }) -map("n", "[e", diagnostic_goto(false, "ERROR"), { desc = "Prev Error" }) -map("n", "]w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" }) -map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" }) +map("n", k.diagnostics.line_diagnostics, vim.diagnostic.open_float, { desc = "Line Diagnostics" }) +map("n", k.diagnostics.next_diagnostic, diagnostic_goto(true), { desc = "Next Diagnostic" }) +map("n", k.diagnostics.prev_diagnostic, diagnostic_goto(false), { desc = "Prev Diagnostic" }) +map("n", k.diagnostics.next_error, diagnostic_goto(true, "ERROR"), { desc = "Next Error" }) +map("n", k.diagnostics.prev_error, diagnostic_goto(false, "ERROR"), { desc = "Prev Error" }) +map("n", k.diagnostics.next_warning, diagnostic_goto(true, "WARN"), { desc = "Next Warning" }) +map("n", k.diagnostics.prev_warning, diagnostic_goto(false, "WARN"), { desc = "Prev Warning" }) -- stylua: ignore start -- toggle options -LazyVim.toggle.map("uf", LazyVim.toggle.format()) -LazyVim.toggle.map("uF", LazyVim.toggle.format(true)) -LazyVim.toggle.map("us", LazyVim.toggle("spell", { name = "Spelling" })) -LazyVim.toggle.map("uw", LazyVim.toggle("wrap", { name = "Wrap" })) -LazyVim.toggle.map("uL", LazyVim.toggle("relativenumber", { name = "Relative Number" })) -LazyVim.toggle.map("ud", LazyVim.toggle.diagnostics) -LazyVim.toggle.map("ul", LazyVim.toggle.number) -LazyVim.toggle.map( "uc", LazyVim.toggle("conceallevel", { values = { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 } })) -LazyVim.toggle.map("uT", LazyVim.toggle.treesitter) -LazyVim.toggle.map("ub", LazyVim.toggle("background", { values = { "light", "dark" }, name = "Background" })) +LazyVim.toggle.map(k.toggle_options.auto_format_buffer, LazyVim.toggle.format()) +LazyVim.toggle.map(k.toggle_options.auto_format_global, LazyVim.toggle.format(true)) +LazyVim.toggle.map(k.toggle_options.spelling, LazyVim.toggle("spell", { name = "Spelling" })) +LazyVim.toggle.map(k.toggle_options.wrap, LazyVim.toggle("wrap", { name = "Wrap" })) +LazyVim.toggle.map(k.toggle_options.relativenumber, LazyVim.toggle("relativenumber", { name = "Relative Number" })) +LazyVim.toggle.map(k.toggle_options.diagnostics, LazyVim.toggle.diagnostics) +LazyVim.toggle.map(k.toggle_options.number, LazyVim.toggle.number) +LazyVim.toggle.map(k.toggle_options.conceallevel, LazyVim.toggle("conceallevel", { values = { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 } })) +LazyVim.toggle.map(k.toggle_options.treesitter, LazyVim.toggle.treesitter) +LazyVim.toggle.map(k.toggle_options.background, LazyVim.toggle("background", { values = { "light", "dark" }, name = "Background" })) if vim.lsp.inlay_hint then - LazyVim.toggle.map("uh", LazyVim.toggle.inlay_hints) + LazyVim.toggle.map(k.toggle_options.inlay_hints, LazyVim.toggle.inlay_hints) end -- lazygit -map("n", "gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) -map("n", "gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) -map("n", "gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) -map("n", "gB", LazyVim.lazygit.browse, { desc = "Git Browse" }) +map("n", k.lazygit.toggle_root, function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) +map("n", k.lazygit.toggle_cwd, function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) +map("n", k.lazygit.blame_line, LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) +map("n", k.lazygit.browse, LazyVim.lazygit.browse, { desc = "Git Browse" }) -map("n", "gf", function() +map("n", k.lazygit.current_file_history, function() local git_path = vim.api.nvim_buf_get_name(0) LazyVim.lazygit({args = { "-f", vim.trim(git_path) }}) end, { desc = "Lazygit Current File History" }) -map("n", "gl", function() +map("n", k.lazygit.git_log_root, function() LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() }) end, { desc = "Lazygit Log" }) -map("n", "gL", function() +map("n", k.lazygit.git_log_cwd, function() LazyVim.lazygit({ args = { "log" } }) end, { desc = "Lazygit Log (cwd)" }) -- quit -map("n", "qq", "qa", { desc = "Quit All" }) +map("n", k.quit_all, "qa", { desc = "Quit All" }) -- highlights under cursor -map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) -map("n", "uI", "InspectTree", { desc = "Inspect Tree" }) +map("n", k.inspect_pos, vim.show_pos, { desc = "Inspect Pos" }) +map("n", k.inspect_tree, "InspectTree", { desc = "Inspect Tree" }) -- LazyVim Changelog -map("n", "L", function() LazyVim.news.changelog() end, { desc = "LazyVim Changelog" }) +map("n", k.lazyvim_changelog, function() LazyVim.news.changelog() end, { desc = "LazyVim Changelog" }) -- floating terminal local lazyterm = function() LazyVim.terminal(nil, { cwd = LazyVim.root() }) end -map("n", "ft", lazyterm, { desc = "Terminal (Root Dir)" }) -map("n", "fT", function() LazyVim.terminal() end, { desc = "Terminal (cwd)" }) -map("n", "", lazyterm, { desc = "Terminal (Root Dir)" }) -map("n", "", lazyterm, { desc = "which_key_ignore" }) +map("n", k.terminal.floating_terminal.toggle_root, lazyterm, { desc = "Terminal (Root Dir)" }) +map("n", k.terminal.floating_terminal.toggle_cwd, function() LazyVim.terminal() end, { desc = "Terminal (cwd)" }) +map("n", k.terminal.floating_terminal.toggle_root_alt_1, lazyterm, { desc = "Terminal (Root Dir)" }) +map("n", k.terminal.floating_terminal.toggle_root_alt_2, lazyterm, { desc = "which_key_ignore" }) -- Terminal Mappings -map("t", "", "", { desc = "Enter Normal Mode" }) -map("t", "", "wincmd h", { desc = "Go to Left Window" }) -map("t", "", "wincmd j", { desc = "Go to Lower Window" }) -map("t", "", "wincmd k", { desc = "Go to Upper Window" }) -map("t", "", "wincmd l", { desc = "Go to Right Window" }) -map("t", "", "close", { desc = "Hide Terminal" }) -map("t", "", "close", { desc = "which_key_ignore" }) +map("t", k.terminal.enter_normal_mode, "", { desc = "Enter Normal Mode" }) +map("t", k.window.left, "wincmd h", { desc = "Go to Left Window" }) +map("t", k.window.lower, "wincmd j", { desc = "Go to Lower Window" }) +map("t", k.window.upper, "wincmd k", { desc = "Go to Upper Window" }) +map("t", k.window.right, "wincmd l", { desc = "Go to Right Window" }) +map("t", k.terminal.hide_terminal, "close", { desc = "Hide Terminal" }) +map("t", k.terminal.hide_terminal_alt, "close", { desc = "which_key_ignore" }) -- windows -map("n", "w", "", { desc = "Windows", remap = true }) -map("n", "-", "s", { desc = "Split Window Below", remap = true }) -map("n", "|", "v", { desc = "Split Window Right", remap = true }) -map("n", "wd", "c", { desc = "Delete Window", remap = true }) -LazyVim.toggle.map("wm", LazyVim.toggle.maximize) +map("n", k.windows.windows, "", { desc = "Windows", remap = true }) +map("n", k.windows.split_window_below, "s", { desc = "Split Window Below", remap = true }) +map("n", k.windows.split_window_right, "v", { desc = "Split Window Right", remap = true }) +map("n", k.windows.delete_window, "c", { desc = "Delete Window", remap = true }) +LazyVim.toggle.map(k.windows.toggle_maximize_window, LazyVim.toggle.maximize) -- tabs -map("n", "l", "tablast", { desc = "Last Tab" }) -map("n", "o", "tabonly", { desc = "Close Other Tabs" }) -map("n", "f", "tabfirst", { desc = "First Tab" }) -map("n", "", "tabnew", { desc = "New Tab" }) -map("n", "]", "tabnext", { desc = "Next Tab" }) -map("n", "d", "tabclose", { desc = "Close Tab" }) -map("n", "[", "tabprevious", { desc = "Previous Tab" }) +map("n", k.tabs.last_tab, "tablast", { desc = "Last Tab" }) +map("n", k.tabs.close_other_tabs, "tabonly", { desc = "Close Other Tabs" }) +map("n", k.tabs.first_tab, "tabfirst", { desc = "First Tab" }) +map("n", k.tabs.new_tab, "tabnew", { desc = "New Tab" }) +map("n", k.tabs.new_tab, "tabnext", { desc = "Next Tab" }) +map("n", k.tabs.close_other_tabs, "tabclose", { desc = "Close Tab" }) +map("n", k.tabs.previous_tab, "tabprevious", { desc = "Previous Tab" }) diff --git a/lua/lazyvim/keymaps.lua b/lua/lazyvim/keymaps.lua new file mode 100644 index 00000000..a6d50001 --- /dev/null +++ b/lua/lazyvim/keymaps.lua @@ -0,0 +1,673 @@ +local M = {} + +---@class LazyVimKeymaps +local keymaps = nil + +---@class LazyVimKeymaps +M.default_keymaps = { + keymaps = { + window = { + left = "", + lower = "", + upper = "", + right = "", + }, + resize_window = { + increase_height = "", + decrease_height = "", + decrease_width = "", + increase_width = "", + }, + move_lines = { + down = "", + up = "", + }, + buffers = { + prev = "", + next = "", + prev_alt = "[b", + next_alt = "]b", + switch_to_other = "bb", + switch_to_other_alt = "`", + delete = "bd", + delete_and_close = "bD", + }, + clear_search_diff_update_and_redraw = "ur", + save_file = "", + keywordprg = "K", + commenting = { + add_comment_below = "gco", + add_comment_above = "gcO", + }, + lazy = "l", + new_file = "fn", + location_list = "xl", + quickfix_list = "xq", + previous_quickfix = "[q", + next_quickfix = "]q", + format = "cf", + diagnostics = { + line_diagnostics = "cd", + next_diagnostic = "]d", + prev_diagnostic = "[d", + next_error = "]e", + prev_error = "[e", + next_warning = "]w", + prev_warning = "[w", + }, + toggle_options = { + auto_format_buffer = "uf", + auto_format_global = "uF", + spelling = "us", + wrap = "uw", + relativenumber = "uL", + diagnostics = "ud", + number = "ul", + conceallevel = "uc", + treesitter = "uT", + background = "ub", + inlay_hints = "uh", + }, + lazygit = { + toggle_root = "gg", + toggle_cwd = "gG", + blame_line = "gb", + browse = "gB", + current_file_history = "gf", + git_log_root = "gl", + git_log_cwd = "gL", + }, + quit_all = "qq", + inspect_pos = "ui", + inspect_tree = "uI", + lazyvim_changelog = "L", + terminal = { + floating_terminal = { + toggle_root = "ft", + toggle_cwd = "fT", + toggle_root_alt_1 = "", + toggle_root_alt_2 = "", + }, + enter_normal_mode = "", + hide_terminal = "", + hide_terminal_alt = "", + }, + windows = { + windows = "w", + split_window_below = "-", + split_window_right = "|", + delete_window = "wd", + toggle_maximize_window = "wm", + }, + tabs = { + last_tab = "l", + close_other_tabs = "o", + first_tab = "f", + new_tab = "", + next_tab = "]", + close_tab = "d", + previous_tab = "[", + }, + }, + quit_buffer = "q", + coding = { + cmp = { + scroll_docs_backward = "", + scroll_docs_forward = "", + select_next_item = "", + select_prev_item = "", + complete = "", + confirm_auto_select = "", + confirm_select = "", + confirm_replace = "", + abort = "", + snippet = { + jump_prev = "", + jump_next = "", + }, + }, + }, + editor = { + neo_tree = { + toggle_root = "fe", + toggle_cwd = "fE", + toggle_root_alt = "e", + toggle_cwd_alt = "E", + toggle_git_status = "ge", + toggle_buffers = "be", + window = { + open = "l", + close_node = "h", + copy_path_to_clipboard = "Y", + open_with_system_application = "O", + toggle_preview = "P", + }, + }, + grug_far = { + open = "sr", + }, + flash = { + jump = "s", + treesitter = "S", + remote = "r", + treesitter_search = "R", + toggle = "", + }, + which_key = { + group = { + tabs = "", + code = "c", + file_find = "f", + git = "g", + hunks = "gh", + quit_session = "q", + search = "s", + ui = "u", + diagnostics_quickfix = "x", + buffer = "b", + windows = "w", + }, + buffer_keymaps = "?", + window_hydra_mode = "", + }, + gitsigns = { + next_hunk = "]h", + prev_hunk = "[h", + last_hunk = "]H", + first_hunk = "[H", + stage_hunk = "ghs", + reset_hunk = "ghr", + stage_buffer = "ghS", + undo_stage_hunk = "ghu", + reset_buffer = "ghR", + preview_hunk_inline = "ghp", + blame_line = "ghb", + blame_buffer = "ghB", + diff_index = "ghd", + diff_commit = "ghD", + select_hunk = "ih", + }, + trouble = { + diagnostics_toggle = "xx", + diagnostics_buffer_toggle = "xX", + symbols_toggle = "cs", + lsp_toggle = "cS", + loclist_toggle = "xL", + qflist_toggle = "xQ", + previous_trouble = "[q", + next_trouble = "]q", + }, + todo_comments = { + next_todo = "]t", + prev_todo = "[t", + todo_trouble = "xt", + todo_fix_fixme_trouble = "xT", + todo_telescope = "st", + todo_fix_fixme_telescope = "sT", + }, + }, + formatting = { + conform = { + format = "cF", + }, + }, + treesitter = { + increment_selection = "", + decrement_selection = "", + textobjects = { + goto_next_start = { + function_outer = "]f", + class_outer = "]c", + parameter_inner = "]a", + }, + goto_next_end = { + function_outer = "]F", + class_outer = "]C", + parameter_inner = "]A", + }, + goto_previous_start = { + function_outer = "[f", + class_outer = "[c", + parameter_inner = "[a", + }, + goto_previous_end = { + function_outer = "[F", + class_outer = "[C", + parameter_inner = "[A", + }, + }, + }, + ui = { + nvim_notify = { + dismiss_all_notifications = "un", + }, + bufferline = { + toggle_pin = "bp", + delete_non_pinned_buffers = "bP", + delete_other_buffers = "bo", + delete_buffers_to_the_right = "br", + delete_buffers_to_the_left = "bl", + prev_buffer = "", + next_buffer = "", + prev_buffer_alt = "[b", + next_buffer_alt = "]b", + move_buffer_prev = "[B", + move_buffer_next = "]B", + }, + indent_blankline = { + toggle = "ug", + }, + noice = { + prefix = "sn", + redirect_cmdline = "", + last_message = "snl", + history = "snh", + all = "sna", + dismiss = "snd", + pick = "snt", + scroll_forward = "", + scroll_backward = "", + }, + dashboard = { + find_file = "f", + new_file = "n", + recent_files = "r", + find_text = "g", + config = "c", + restore_session = "s", + lazy_extras = "x", + lazy = "l", + quit = "q", + projects = "p", + }, + }, + util = { + persistence = { + restore_session = "qs", + select_session = "qS", + restore_last_session = "ql", + skip_current_session = "qd", + }, + mini_pairs = { + toggle = "up", + }, + }, + extras = { + coding = { + copilot_chat = { + submit_prompt = "", + prefix = "a", + toggle = "aa", + clear = "ax", + quick_chat = "aq", + diagnostic_help = "ad", + prompt_actions = "ap", + }, + luasnip = { + jump_next = "", + jump_prev = "", + }, + mini_surround = { + prefix = "gs", + add = "gsa", + delete = "gsd", + find = "gsf", + find_left = "gsF", + highlight = "gsh", + replace = "gsr", + update_n_lines = "gsn", + alt = { + prefix = "gz", + add = "gza", + delete = "gzd", + find = "gzf", + find_left = "gzF", + highlight = "gzh", + replace = "gzr", + update_n_lines = "gzn", + }, + }, + yanky = { + yank_history = "p", + yank = "y", + put_text_after_cursor = "p", + put_text_before_cursor = "P", + put_text_after_selection = "gp", + put_text_before_selection = "gP", + cycle_forward_yank_history = "[y", + cycle_backward_yank_history = "]y", + put_indent_after_cursor_linewise = "]p", + put_indent_before_cursor_linewise = "[p", + put_indent_after_cursor_linewise_alt = "]P", + put_indent_before_cursor_linewise_alt = "[P", + put_and_indent_right = ">p", + put_and_indent_left = ""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), - [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), - [""] = cmp.mapping.complete(), - [""] = LazyVim.cmp.confirm({ select = auto_select }), - [""] = LazyVim.cmp.confirm({ select = true }), - [""] = LazyVim.cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [""] = function(fallback) - cmp.abort() - fallback() - end, - }), + mapping = cmp.mapping.preset.insert({ mappings }), sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "path" }, @@ -107,7 +120,7 @@ return { end, keys = { { - "", + k.cmp.snippet.jump_prev, function() return vim.snippet.active({ direction = 1 }) and "lua vim.snippet.jump(1)" or "" end, @@ -116,7 +129,7 @@ return { mode = { "i", "s" }, }, { - "", + k.cmp.snippet.jump_next, function() return vim.snippet.active({ direction = -1 }) and "lua vim.snippet.jump(-1)" or "" end, diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index a57d9aeb..b96da960 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -1,41 +1,56 @@ +local k = require("lazyvim.keymaps").get_keymaps().editor +local s = require("lazyvim.keymaps").get_keymaps().extras.coding.mini_surround + return { -- file explorer { "nvim-neo-tree/neo-tree.nvim", cmd = "Neotree", - keys = { - { - "fe", - function() - require("neo-tree.command").execute({ toggle = true, dir = LazyVim.root() }) - end, - desc = "Explorer NeoTree (Root Dir)", - }, - { - "fE", - function() - require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) - end, - desc = "Explorer NeoTree (cwd)", - }, - { "e", "fe", desc = "Explorer NeoTree (Root Dir)", remap = true }, - { "E", "fE", desc = "Explorer NeoTree (cwd)", remap = true }, - { - "ge", - function() - require("neo-tree.command").execute({ source = "git_status", toggle = true }) - end, - desc = "Git Explorer", - }, - { - "be", - function() - require("neo-tree.command").execute({ source = "buffers", toggle = true }) - end, - desc = "Buffer Explorer", - }, - }, + keys = function() + return { + { + k.neo_tree.toggle_root, + function() + require("neo-tree.command").execute({ toggle = true, dir = LazyVim.root() }) + end, + desc = "Explorer NeoTree (Root Dir)", + }, + { + k.neo_tree.toggle_cwd, + function() + require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) + end, + desc = "Explorer NeoTree (cwd)", + }, + { + k.neo_tree.toggle_root_alt, + k.neo_tree.toggle_root, + desc = "Explorer NeoTree (Root Dir)", + remap = true, + }, + { + k.neo_tree.toggle_cwd_alt, + k.neo_tree.toggle_cwd, + desc = "Explorer NeoTree (cwd)", + remap = true, + }, + { + k.neo_tree.toggle_git_status, + function() + require("neo-tree.command").execute({ source = "git_status", toggle = true }) + end, + desc = "Git Explorer", + }, + { + k.neo_tree.toggle_buffers, + function() + require("neo-tree.command").execute({ source = "buffers", toggle = true }) + end, + desc = "Buffer Explorer", + }, + } + end, deactivate = function() vim.cmd([[Neotree close]]) end, @@ -58,51 +73,61 @@ return { end, }) end, - opts = { - sources = { "filesystem", "buffers", "git_status" }, - open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, - filesystem = { - bind_to_cwd = false, - follow_current_file = { enabled = true }, - use_libuv_file_watcher = true, - }, - window = { - mappings = { - ["l"] = "open", - ["h"] = "close_node", - [""] = "none", - ["Y"] = { - function(state) - local node = state.tree:get_node() - local path = node:get_id() - vim.fn.setreg("+", path, "c") - end, - desc = "Copy Path to Clipboard", - }, - ["O"] = { - function(state) - require("lazy.util").open(state.tree:get_node().path, { system = true }) - end, - desc = "Open with System Application", - }, - ["P"] = { "toggle_preview", config = { use_float = false } }, + opts = function() + local neo_tree_mappings = {} + local neo_tree_actions = { + [k.neo_tree.window.open] = "open", + [k.neo_tree.window.close_node] = "close_node", + [""] = "none", + [k.neo_tree.window.copy_path_to_clipboard] = { + function(state) + local node = state.tree:get_node() + local path = node:get_id() + vim.fn.setreg("+", path, "c") + end, + desc = "Copy Path to Clipboard", }, - }, - default_component_configs = { - indent = { - with_expanders = true, -- if nil and file nesting is enabled, will enable expanders - expander_collapsed = "", - expander_expanded = "", - expander_highlight = "NeoTreeExpander", + [k.neo_tree.window.open_with_system_application] = { + function(state) + require("lazy.util").open(state.tree:get_node().path, { system = true }) + end, + desc = "Open with System Application", }, - git_status = { - symbols = { - unstaged = "󰄱", - staged = "󰱒", + [k.neo_tree.window.toggle_preview] = { "toggle_preview", config = { use_float = false } }, + } + for key, value in pairs(neo_tree_actions) do + if key and key ~= "" then + neo_tree_mappings[key] = value + end + end + + return { + sources = { "filesystem", "buffers", "git_status" }, + open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, + filesystem = { + bind_to_cwd = false, + follow_current_file = { enabled = true }, + use_libuv_file_watcher = true, + }, + window = { + mappings = neo_tree_mappings, + }, + default_component_configs = { + indent = { + with_expanders = true, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + git_status = { + symbols = { + unstaged = "󰄱", + staged = "󰱒", + }, }, }, - }, - }, + } + end, config = function(_, opts) local function on_move(data) LazyVim.lsp.on_rename(data.source, data.destination) @@ -133,7 +158,7 @@ return { cmd = "GrugFar", keys = { { - "sr", + k.grug_far.open, function() local grug = require("grug-far") local ext = vim.bo.buftype == "" and vim.fn.expand("%:e") @@ -161,11 +186,11 @@ return { opts = {}, -- stylua: ignore keys = { - { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, - { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, - { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, - { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, - { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, + {k.flash.jump, mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, + {k.flash.treesitter, mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, + {k.flash.remote, mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, + {k.flash.treesitter_search, mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, + {k.flash.toggle, mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, }, }, @@ -180,29 +205,33 @@ return { spec = { { mode = { "n", "v" }, - { "", group = "tabs" }, - { "c", group = "code" }, - { "f", group = "file/find" }, - { "g", group = "git" }, - { "gh", group = "hunks" }, - { "q", group = "quit/session" }, - { "s", group = "search" }, - { "u", group = "ui", icon = { icon = "󰙵 ", color = "cyan" } }, - { "x", group = "diagnostics/quickfix", icon = { icon = "󱖫 ", color = "green" } }, + { k.which_key.group.tabs, group = "tabs" }, + { k.which_key.group.code, group = "code" }, + { k.which_key.group.file_find, group = "file/find" }, + { k.which_key.group.git, group = "git" }, + { k.which_key.group.hunks, group = "hunks" }, + { k.which_key.group.quit_session, group = "quit/session" }, + { k.which_key.group.search, group = "search" }, + { k.which_key.group.ui, group = "ui", icon = { icon = "󰙵 ", color = "cyan" } }, + { + k.which_key.group.diagnostics_quickfix, + group = "diagnostics/quickfix", + icon = { icon = "󱖫 ", color = "green" }, + }, { "[", group = "prev" }, { "]", group = "next" }, { "g", group = "goto" }, - { "gs", group = "surround" }, + { s.prefix, group = "surround" }, { "z", group = "fold" }, - { - "b", + k.which_key.group.buffer == "" and {} or { + k.which_key.group.buffer, group = "buffer", expand = function() return require("which-key.extras").expand.buf() end, }, - { - "w", + k.which_key.group.windows == "" and {} or { + k.which_key.group.windows, group = "windows", proxy = "", expand = function() @@ -216,14 +245,14 @@ return { }, keys = { { - "?", + k.which_key.buffer_keymaps, function() require("which-key").show({ global = false }) end, desc = "Buffer Keymaps (which-key)", }, { - "", + k.which_key.window_hydra_mode, function() require("which-key").show({ keys = "", loop = true }) end, @@ -266,37 +295,37 @@ return { local gs = package.loaded.gitsigns local function map(mode, l, r, desc) - vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc }) + LazyVim.keymap_set(mode, l, r, { buffer = buffer, desc = desc }) end -- stylua: ignore start - map("n", "]h", function() + map("n", k.gitsigns.next_hunk, function() if vim.wo.diff then vim.cmd.normal({ "]c", bang = true }) else gs.nav_hunk("next") end end, "Next Hunk") - map("n", "[h", function() + map("n", k.gitsigns.prev_hunk, function() if vim.wo.diff then vim.cmd.normal({ "[c", bang = true }) else gs.nav_hunk("prev") end end, "Prev Hunk") - map("n", "]H", function() gs.nav_hunk("last") end, "Last Hunk") - map("n", "[H", function() gs.nav_hunk("first") end, "First Hunk") - map({ "n", "v" }, "ghs", ":Gitsigns stage_hunk", "Stage Hunk") - map({ "n", "v" }, "ghr", ":Gitsigns reset_hunk", "Reset Hunk") - map("n", "ghS", gs.stage_buffer, "Stage Buffer") - map("n", "ghu", gs.undo_stage_hunk, "Undo Stage Hunk") - map("n", "ghR", gs.reset_buffer, "Reset Buffer") - map("n", "ghp", gs.preview_hunk_inline, "Preview Hunk Inline") - map("n", "ghb", function() gs.blame_line({ full = true }) end, "Blame Line") - map("n", "ghB", function() gs.blame() end, "Blame Buffer") - map("n", "ghd", gs.diffthis, "Diff This") - map("n", "ghD", function() gs.diffthis("~") end, "Diff This ~") - map({ "o", "x" }, "ih", ":Gitsigns select_hunk", "GitSigns Select Hunk") + map("n", k.gitsigns.last_hunk, function() gs.nav_hunk("last") end, "Last Hunk") + map("n", k.gitsigns.first_hunk, function() gs.nav_hunk("first") end, "First Hunk") + map({ "n", "v" }, k.gitsigns.stage_hunk, ":Gitsigns stage_hunk", "Stage Hunk") + map({ "n", "v" }, k.gitsigns.reset_hunk, ":Gitsigns reset_hunk", "Reset Hunk") + map("n", k.gitsigns.stage_buffer, gs.stage_buffer, "Stage Buffer") + map("n", k.gitsigns.undo_stage_hunk, gs.undo_stage_hunk, "Undo Stage Hunk") + map("n", k.gitsigns.reset_buffer, gs.reset_buffer, "Reset Buffer") + map("n", k.gitsigns.preview_hunk_inline, gs.preview_hunk_inline, "Preview Hunk Inline") + map("n", k.gitsigns.blame_line, function() gs.blame_line({ full = true }) end, "Blame Line") + map("n", k.gitsigns.blame_buffer, function() gs.blame() end, "Blame Buffer") + map("n", k.gitsigns.diff_index, gs.diffthis, "Diff This") + map("n", k.gitsigns.diff_commit, function() gs.diffthis("~") end, "Diff This ~") + map({ "o", "x" }, k.gitsigns.select_hunk, ":Gitsigns select_hunk", "GitSigns Select Hunk") end, }, }, @@ -313,14 +342,18 @@ return { }, }, keys = { - { "xx", "Trouble diagnostics toggle", desc = "Diagnostics (Trouble)" }, - { "xX", "Trouble diagnostics toggle filter.buf=0", desc = "Buffer Diagnostics (Trouble)" }, - { "cs", "Trouble symbols toggle", desc = "Symbols (Trouble)" }, - { "cS", "Trouble lsp toggle", desc = "LSP references/definitions/... (Trouble)" }, - { "xL", "Trouble loclist toggle", desc = "Location List (Trouble)" }, - { "xQ", "Trouble qflist toggle", desc = "Quickfix List (Trouble)" }, + { k.trouble.diagnostics_toggle, "Trouble diagnostics toggle", desc = "Diagnostics (Trouble)" }, { - "[q", + k.trouble.diagnostics_buffer_toggle, + "Trouble diagnostics toggle filter.buf=0", + desc = "Buffer Diagnostics (Trouble)", + }, + { k.trouble.symbols_toggle, "Trouble symbols toggle", desc = "Symbols (Trouble)" }, + { k.trouble.lsp_toggle, "Trouble lsp toggle", desc = "LSP references/definitions/... (Trouble)" }, + { k.trouble.loclist_toggle, "Trouble loclist toggle", desc = "Location List (Trouble)" }, + { k.trouble.qflist_toggle, "Trouble qflist toggle", desc = "Quickfix List (Trouble)" }, + { + k.trouble.previous_trouble, function() if require("trouble").is_open() then require("trouble").prev({ skip_groups = true, jump = true }) @@ -334,7 +367,7 @@ return { desc = "Previous Trouble/Quickfix Item", }, { - "]q", + k.trouble.next_trouble, function() if require("trouble").is_open() then require("trouble").next({ skip_groups = true, jump = true }) @@ -359,12 +392,12 @@ return { opts = {}, -- stylua: ignore keys = { - { "]t", function() require("todo-comments").jump_next() end, desc = "Next Todo Comment" }, - { "[t", function() require("todo-comments").jump_prev() end, desc = "Previous Todo Comment" }, - { "xt", "Trouble todo toggle", desc = "Todo (Trouble)" }, - { "xT", "Trouble todo toggle filter = {tag = {TODO,FIX,FIXME}}", desc = "Todo/Fix/Fixme (Trouble)" }, - { "st", "TodoTelescope", desc = "Todo" }, - { "sT", "TodoTelescope keywords=TODO,FIX,FIXME", desc = "Todo/Fix/Fixme" }, + { k.todo_comments.next_todo, function() require("todo-comments").jump_next() end, desc = "Next Todo Comment" }, + { k.todo_comments.prev_todo, function() require("todo-comments").jump_prev() end, desc = "Previous Todo Comment" }, + { k.todo_comments.todo_trouble, "Trouble todo toggle", desc = "Todo (Trouble)" }, + { k.todo_comments.todo_fix_fixme_trouble, "Trouble todo toggle filter = {tag = {TODO,FIX,FIXME}}", desc = "Todo/Fix/Fixme (Trouble)" }, + { k.todo_comments.todo_telescope, "TodoTelescope", desc = "Todo" }, + { k.todo_comments.todo_fix_fixme_telescope, "TodoTelescope keywords=TODO,FIX,FIXME", desc = "Todo/Fix/Fixme" }, }, }, diff --git a/lua/lazyvim/plugins/extras/coding/copilot-chat.lua b/lua/lazyvim/plugins/extras/coding/copilot-chat.lua index fd58b857..341461f2 100644 --- a/lua/lazyvim/plugins/extras/coding/copilot-chat.lua +++ b/lua/lazyvim/plugins/extras/coding/copilot-chat.lua @@ -1,4 +1,5 @@ local M = {} +local k = require("lazyvim.keymaps").get_keymaps().extras.coding.copilot_chat ---@param kind string function M.pick(kind) @@ -37,10 +38,10 @@ return { } end, keys = { - { "", "", ft = "copilot-chat", desc = "Submit Prompt", remap = true }, - { "a", "", desc = "+ai", mode = { "n", "v" } }, + { k.submit_prompt, "", ft = "copilot-chat", desc = "Submit Prompt", remap = true }, + { k.prefix, "", desc = "+ai", mode = { "n", "v" } }, { - "aa", + k.toggle, function() return require("CopilotChat").toggle() end, @@ -48,7 +49,7 @@ return { mode = { "n", "v" }, }, { - "ax", + k.clear, function() return require("CopilotChat").reset() end, @@ -56,7 +57,7 @@ return { mode = { "n", "v" }, }, { - "aq", + k.quick_chat, function() local input = vim.fn.input("Quick Chat: ") if input ~= "" then @@ -67,9 +68,9 @@ return { mode = { "n", "v" }, }, -- Show help actions with telescope - { "ad", M.pick("help"), desc = "Diagnostic Help (CopilotChat)", mode = { "n", "v" } }, + { k.diagnostic_help, M.pick("help"), desc = "Diagnostic Help (CopilotChat)", mode = { "n", "v" } }, -- Show prompts actions with telescope - { "ap", M.pick("prompt"), desc = "Prompt Actions (CopilotChat)", mode = { "n", "v" } }, + { k.prompt_actions, M.pick("prompt"), desc = "Prompt Actions (CopilotChat)", mode = { "n", "v" } }, }, config = function(_, opts) local chat = require("CopilotChat") diff --git a/lua/lazyvim/plugins/extras/coding/luasnip.lua b/lua/lazyvim/plugins/extras/coding/luasnip.lua index 47bd80c4..d2b484cc 100644 --- a/lua/lazyvim/plugins/extras/coding/luasnip.lua +++ b/lua/lazyvim/plugins/extras/coding/luasnip.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.coding.luasnip + return { { "L3MON4D3/LuaSnip", @@ -37,14 +39,14 @@ return { -- stylua: ignore keys = { { - "", + k.jump_next, function() return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" end, expr = true, silent = true, mode = "i", }, - { "", function() require("luasnip").jump(1) end, mode = "s" }, - { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, + { k.jump_next, function() require("luasnip").jump(1) end, mode = "s" }, + { k.jump_prev, function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, }, }, { diff --git a/lua/lazyvim/plugins/extras/coding/mini-surround.lua b/lua/lazyvim/plugins/extras/coding/mini-surround.lua index 56d16a60..7cfbfb62 100644 --- a/lua/lazyvim/plugins/extras/coding/mini-surround.lua +++ b/lua/lazyvim/plugins/extras/coding/mini-surround.lua @@ -2,6 +2,8 @@ -- surrounding characters like brackets or quotes, this allows you -- to select the text inside, change or modify the surrounding characters, -- and more. +local k = require("lazyvim.keymaps").get_keymaps().extras.coding.mini_surround + return { "echasnovski/mini.surround", recommended = true, @@ -24,13 +26,13 @@ return { end, opts = { mappings = { - add = "gsa", -- Add surrounding in Normal and Visual modes - delete = "gsd", -- Delete surrounding - find = "gsf", -- Find surrounding (to the right) - find_left = "gsF", -- Find surrounding (to the left) - highlight = "gsh", -- Highlight surrounding - replace = "gsr", -- Replace surrounding - update_n_lines = "gsn", -- Update `n_lines` + add = k.add, -- Add surrounding in Normal and Visual modes + delete = k.delete, -- Delete surrounding + find = k.find, -- Find surrounding (to the right) + find_left = k.find_left, -- Find surrounding (to the left) + highlight = k.highlight, -- Highlight surrounding + replace = k.replace, -- Replace surrounding + update_n_lines = k.update_n_lines, -- Update `n_lines` }, }, } diff --git a/lua/lazyvim/plugins/extras/coding/yanky.lua b/lua/lazyvim/plugins/extras/coding/yanky.lua index c880aceb..9f4c84e6 100644 --- a/lua/lazyvim/plugins/extras/coding/yanky.lua +++ b/lua/lazyvim/plugins/extras/coding/yanky.lua @@ -1,4 +1,5 @@ -- better yank/paste +local k = require("lazyvim.keymaps").get_keymaps().extras.coding.yanky return { "gbprod/yanky.nvim", recommended = true, @@ -9,7 +10,7 @@ return { }, keys = { { - "p", + k.yank_history, function() if LazyVim.pick.picker.name == "telescope" then require("telescope").extensions.yank_history.yank_history({}) @@ -21,22 +22,38 @@ return { desc = "Open Yank History", }, -- stylua: ignore - { "y", "(YankyYank)", mode = { "n", "x" }, desc = "Yank Text" }, - { "p", "(YankyPutAfter)", mode = { "n", "x" }, desc = "Put Text After Cursor" }, - { "P", "(YankyPutBefore)", mode = { "n", "x" }, desc = "Put Text Before Cursor" }, - { "gp", "(YankyGPutAfter)", mode = { "n", "x" }, desc = "Put Text After Selection" }, - { "gP", "(YankyGPutBefore)", mode = { "n", "x" }, desc = "Put Text Before Selection" }, - { "[y", "(YankyCycleForward)", desc = "Cycle Forward Through Yank History" }, - { "]y", "(YankyCycleBackward)", desc = "Cycle Backward Through Yank History" }, - { "]p", "(YankyPutIndentAfterLinewise)", desc = "Put Indented After Cursor (Linewise)" }, - { "[p", "(YankyPutIndentBeforeLinewise)", desc = "Put Indented Before Cursor (Linewise)" }, - { "]P", "(YankyPutIndentAfterLinewise)", desc = "Put Indented After Cursor (Linewise)" }, - { "[P", "(YankyPutIndentBeforeLinewise)", desc = "Put Indented Before Cursor (Linewise)" }, - { ">p", "(YankyPutIndentAfterShiftRight)", desc = "Put and Indent Right" }, - { "(YankyPutIndentAfterShiftLeft)", desc = "Put and Indent Left" }, - { ">P", "(YankyPutIndentBeforeShiftRight)", desc = "Put Before and Indent Right" }, - { "(YankyPutIndentBeforeShiftLeft)", desc = "Put Before and Indent Left" }, - { "=p", "(YankyPutAfterFilter)", desc = "Put After Applying a Filter" }, - { "=P", "(YankyPutBeforeFilter)", desc = "Put Before Applying a Filter" }, + { k.yank, "(YankyYank)", mode = { "n", "x" }, desc = "Yank Text" }, + { k.put_text_after_cursor, "(YankyPutAfter)", mode = { "n", "x" }, desc = "Put Text After Cursor" }, + { k.put_text_before_cursor, "(YankyPutBefore)", mode = { "n", "x" }, desc = "Put Text Before Cursor" }, + { k.put_text_after_selection, "(YankyGPutAfter)", mode = { "n", "x" }, desc = "Put Text After Selection" }, + { k.put_text_before_selection, "(YankyGPutBefore)", mode = { "n", "x" }, desc = "Put Text Before Selection" }, + { k.cycle_forward_yank_history, "(YankyCycleForward)", desc = "Cycle Forward Through Yank History" }, + { k.cycle_backward_yank_history, "(YankyCycleBackward)", desc = "Cycle Backward Through Yank History" }, + { + k.put_indent_after_cursor_linewise, + "(YankyPutIndentAfterLinewise)", + desc = "Put Indented After Cursor (Linewise)", + }, + { + k.put_indent_before_cursor_linewise, + "(YankyPutIndentBeforeLinewise)", + desc = "Put Indented Before Cursor (Linewise)", + }, + { + k.put_indent_after_cursor_linewise_alt, + "(YankyPutIndentAfterLinewise)", + desc = "Put Indented After Cursor (Linewise)", + }, + { + k.put_indent_before_cursor_linewise_alt, + "(YankyPutIndentBeforeLinewise)", + desc = "Put Indented Before Cursor (Linewise)", + }, + { k.put_and_indent_right, "(YankyPutIndentAfterShiftRight)", desc = "Put and Indent Right" }, + { k.put_and_indent_left, "(YankyPutIndentAfterShiftLeft)", desc = "Put and Indent Left" }, + { k.put_before_indent_right, "(YankyPutIndentBeforeShiftRight)", desc = "Put Before and Indent Right" }, + { k.put_before_indent_left, "(YankyPutIndentBeforeShiftLeft)", desc = "Put Before and Indent Left" }, + { k.put_after_filter, "(YankyPutAfterFilter)", desc = "Put After Applying a Filter" }, + { k.put_before_filter, "(YankyPutBeforeFilter)", desc = "Put Before Applying a Filter" }, }, } diff --git a/lua/lazyvim/plugins/extras/dap/core.lua b/lua/lazyvim/plugins/extras/dap/core.lua index ac6709f1..64c0ee3f 100644 --- a/lua/lazyvim/plugins/extras/dap/core.lua +++ b/lua/lazyvim/plugins/extras/dap/core.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.dap.core + ---@param config {args?:string[]|fun():string[]?} local function get_args(config) local args = type(config.args) == "function" and (config.args() or {}) or config.args or {} @@ -27,24 +29,24 @@ return { -- stylua: ignore keys = { - { "d", "", desc = "+debug", mode = {"n", "v"} }, - { "dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" }, - { "db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, - { "dc", function() require("dap").continue() end, desc = "Continue" }, - { "da", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" }, - { "dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" }, - { "dg", function() require("dap").goto_() end, desc = "Go to Line (No Execute)" }, - { "di", function() require("dap").step_into() end, desc = "Step Into" }, - { "dj", function() require("dap").down() end, desc = "Down" }, - { "dk", function() require("dap").up() end, desc = "Up" }, - { "dl", function() require("dap").run_last() end, desc = "Run Last" }, - { "do", function() require("dap").step_out() end, desc = "Step Out" }, - { "dO", function() require("dap").step_over() end, desc = "Step Over" }, - { "dp", function() require("dap").pause() end, desc = "Pause" }, - { "dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" }, - { "ds", function() require("dap").session() end, desc = "Session" }, - { "dt", function() require("dap").terminate() end, desc = "Terminate" }, - { "dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" }, + { k.nvim_dap.prefix, "", desc = "+debug", mode = {"n", "v"} }, + { k.nvim_dap.breakpoint_condition, function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" }, + { k.nvim_dap.toggle_breakpoint, function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, + { k.nvim_dap.continue, function() require("dap").continue() end, desc = "Continue" }, + { k.nvim_dap.run_with_args, function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" }, + { k.nvim_dap.run_to_cursor, function() require("dap").run_to_cursor() end, desc = "Run to Cursor" }, + { k.nvim_dap.go_to_line_no_execute, function() require("dap").goto_() end, desc = "Go to Line (No Execute)" }, + { k.nvim_dap.step_into, function() require("dap").step_into() end, desc = "Step Into" }, + { k.nvim_dap.down, function() require("dap").down() end, desc = "Down" }, + { k.nvim_dap.up, function() require("dap").up() end, desc = "Up" }, + { k.nvim_dap.run_last, function() require("dap").run_last() end, desc = "Run Last" }, + { k.nvim_dap.step_out, function() require("dap").step_out() end, desc = "Step Out" }, + { k.nvim_dap.step_over, function() require("dap").step_over() end, desc = "Step Over" }, + { k.nvim_dap.pause, function() require("dap").pause() end, desc = "Pause" }, + { k.nvim_dap.toggle_repl, function() require("dap").repl.toggle() end, desc = "Toggle REPL" }, + { k.nvim_dap.session, function() require("dap").session() end, desc = "Session" }, + { k.nvim_dap.terminate, function() require("dap").terminate() end, desc = "Terminate" }, + { k.nvim_dap.widgets, function() require("dap.ui.widgets").hover() end, desc = "Widgets" }, }, config = function() @@ -78,8 +80,8 @@ return { dependencies = { "nvim-neotest/nvim-nio" }, -- stylua: ignore keys = { - { "du", function() require("dapui").toggle({ }) end, desc = "Dap UI" }, - { "de", function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} }, + { k.nvim_dap_ui.toggle_dap_ui, function() require("dapui").toggle({ }) end, desc = "Dap UI" }, + { k.nvim_dap_ui.eval_dap_ui, function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} }, }, opts = {}, config = function(_, opts) diff --git a/lua/lazyvim/plugins/extras/editor/aerial.lua b/lua/lazyvim/plugins/extras/editor/aerial.lua index d2486c22..b6763e6a 100644 --- a/lua/lazyvim/plugins/extras/editor/aerial.lua +++ b/lua/lazyvim/plugins/extras/editor/aerial.lua @@ -1,3 +1,7 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.aerial +local p = require("lazyvim.keymaps").get_keymaps().extras.editor.picker +local t = require("lazyvim.keymaps").get_keymaps().editor.trouble + return { desc = "Aerial Symbol Browser", { @@ -43,7 +47,7 @@ return { return opts end, keys = { - { "cs", "AerialToggle", desc = "Aerial (Symbols)" }, + { k.toggle, "AerialToggle", desc = "Aerial (Symbols)" }, }, }, @@ -51,7 +55,7 @@ return { "folke/trouble.nvim", optional = true, keys = { - { "cs", false }, + { t.symbols_toggle, false }, }, }, @@ -66,7 +70,7 @@ return { end, keys = { { - "ss", + p.go_to_symbol, "Telescope aerial", desc = "Goto Symbol (Aerial)", }, diff --git a/lua/lazyvim/plugins/extras/editor/dial.lua b/lua/lazyvim/plugins/extras/editor/dial.lua index 5d2dcaa1..4d4038ed 100644 --- a/lua/lazyvim/plugins/extras/editor/dial.lua +++ b/lua/lazyvim/plugins/extras/editor/dial.lua @@ -1,4 +1,5 @@ local M = {} +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.dial ---@param increment boolean ---@param g? boolean @@ -17,10 +18,10 @@ return { desc = "Increment and decrement numbers, dates, and more", -- stylua: ignore keys = { - { "", function() return M.dial(true) end, expr = true, desc = "Increment", mode = {"n", "v"} }, - { "", function() return M.dial(false) end, expr = true, desc = "Decrement", mode = {"n", "v"} }, - { "g", function() return M.dial(true, true) end, expr = true, desc = "Increment", mode = {"n", "v"} }, - { "g", function() return M.dial(false, true) end, expr = true, desc = "Decrement", mode = {"n", "v"} }, + { k.increase, function() return M.dial(true) end, expr = true, desc = "Increment", mode = {"n", "v"} }, + { k.decrement, function() return M.dial(false) end, expr = true, desc = "Decrement", mode = {"n", "v"} }, + { k.increment_g, function() return M.dial(true, true) end, expr = true, desc = "Increment", mode = {"n", "v"} }, + { k.decrement_g, function() return M.dial(false, true) end, expr = true, desc = "Decrement", mode = {"n", "v"} }, }, opts = function() local augend = require("dial.augend") diff --git a/lua/lazyvim/plugins/extras/editor/fzf.lua b/lua/lazyvim/plugins/extras/editor/fzf.lua index e23af81b..d47b5b6a 100644 --- a/lua/lazyvim/plugins/extras/editor/fzf.lua +++ b/lua/lazyvim/plugins/extras/editor/fzf.lua @@ -1,3 +1,7 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.picker +local lang = require("lazyvim.keymaps").get_keymaps().extras.lang +local t = require("lazyvim.keymaps").get_keymaps().editor.todo_comments + if lazyvim_docs then -- In case you don't want to use `:LazyExtras`, -- then you need to set the option below. @@ -98,6 +102,18 @@ return { end end + local default_keymaps = { + [k.actions.find_files_no_ignore] = { actions.toggle_ignore }, + [k.actions.find_files_with_hidden] = { actions.toggle_hidden }, + } + local keymaps = {} + + for key, value in pairs(default_keymaps) do + if key and key ~= "" then + keymaps[key] = value + end + end + return vim.tbl_deep_extend("force", defaults, { fzf_colors = true, fzf_opts = { @@ -161,16 +177,10 @@ return { }, files = { cwd_prompt = false, - actions = { - ["alt-i"] = { actions.toggle_ignore }, - ["alt-h"] = { actions.toggle_hidden }, - }, + actions = keymaps, }, grep = { - actions = { - ["alt-i"] = { actions.toggle_ignore }, - ["alt-h"] = { actions.toggle_hidden }, - }, + actions = keymaps, }, lsp = { symbols = { @@ -205,50 +215,50 @@ return { { "", "", ft = "fzf", mode = "t", nowait = true }, { "", "", ft = "fzf", mode = "t", nowait = true }, { - ",", + k.switch_buffer, "FzfLua buffers sort_mru=true sort_lastused=true", desc = "Switch Buffer", }, - { "/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, - { ":", "FzfLua command_history", desc = "Command History" }, - { "", LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, + { k.grep_root, LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, + { k.command_history, "FzfLua command_history", desc = "Command History" }, + { k.find_files_root, LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, -- find - { "fb", "FzfLua buffers sort_mru=true sort_lastused=true", desc = "Buffers" }, - { "fc", LazyVim.pick.config_files(), desc = "Find Config File" }, - { "ff", LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, - { "fF", LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" }, - { "fg", "FzfLua git_files", desc = "Find Files (git-files)" }, - { "fr", "FzfLua oldfiles", desc = "Recent" }, - { "fR", LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" }, + { k.find_buffers, "FzfLua buffers sort_mru=true sort_lastused=true", desc = "Buffers" }, + { k.find_config_file, LazyVim.pick.config_files(), desc = "Find Config File" }, + { k.find_files_root_alt, LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, + { k.find_files_cwd, LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" }, + { k.find_git_files, "FzfLua git_files", desc = "Find Files (git-files)" }, + { k.find_recent_files, "FzfLua oldfiles", desc = "Recent" }, + { k.find_recent_files_cwd, LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" }, -- git - { "gc", "FzfLua git_commits", desc = "Commits" }, - { "gs", "FzfLua git_status", desc = "Status" }, + { k.git_commits, "FzfLua git_commits", desc = "Commits" }, + { k.git_status, "FzfLua git_status", desc = "Status" }, -- search - { 's"', "FzfLua registers", desc = "Registers" }, - { "sa", "FzfLua autocmds", desc = "Auto Commands" }, - { "sb", "FzfLua grep_curbuf", desc = "Buffer" }, - { "sc", "FzfLua command_history", desc = "Command History" }, - { "sC", "FzfLua commands", desc = "Commands" }, - { "sd", "FzfLua diagnostics_document", desc = "Document Diagnostics" }, - { "sD", "FzfLua diagnostics_workspace", desc = "Workspace Diagnostics" }, - { "sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, - { "sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" }, - { "sh", "FzfLua help_tags", desc = "Help Pages" }, - { "sH", "FzfLua highlights", desc = "Search Highlight Groups" }, - { "sj", "FzfLua jumps", desc = "Jumplist" }, - { "sk", "FzfLua keymaps", desc = "Key Maps" }, - { "sl", "FzfLua loclist", desc = "Location List" }, - { "sM", "FzfLua man_pages", desc = "Man Pages" }, - { "sm", "FzfLua marks", desc = "Jump to Mark" }, - { "sR", "FzfLua resume", desc = "Resume" }, - { "sq", "FzfLua quickfix", desc = "Quickfix List" }, - { "sw", LazyVim.pick("grep_cword"), desc = "Word (Root Dir)" }, - { "sW", LazyVim.pick("grep_cword", { root = false }), desc = "Word (cwd)" }, - { "sw", LazyVim.pick("grep_visual"), mode = "v", desc = "Selection (Root Dir)" }, - { "sW", LazyVim.pick("grep_visual", { root = false }), mode = "v", desc = "Selection (cwd)" }, - { "uC", LazyVim.pick("colorschemes"), desc = "Colorscheme with Preview" }, + { k.search_registers, "FzfLua registers", desc = "Registers" }, + { k.search_autocommands, "FzfLua autocmds", desc = "Auto Commands" }, + { k.search_buffer, "FzfLua grep_curbuf", desc = "Buffer" }, + { k.search_command_history, "FzfLua command_history", desc = "Command History" }, + { k.search_commands, "FzfLua commands", desc = "Commands" }, + { k.search_document_diagnostics, "FzfLua diagnostics_document", desc = "Document Diagnostics" }, + { k.search_workspace_diagnostics, "FzfLua diagnostics_workspace", desc = "Workspace Diagnostics" }, + { k.search_grep_root, LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, + { k.search_grep_cwd, LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" }, + { k.search_help_pages, "FzfLua help_tags", desc = "Help Pages" }, + { k.search_highlight_groups, "FzfLua highlights", desc = "Search Highlight Groups" }, + { k.search_jumplist, "FzfLua jumps", desc = "Jumplist" }, + { k.search_keymaps, "FzfLua keymaps", desc = "Key Maps" }, + { k.search_loclist, "FzfLua loclist", desc = "Location List" }, + { k.search_man_pages, "FzfLua man_pages", desc = "Man Pages" }, + { k.search_marks, "FzfLua marks", desc = "Jump to Mark" }, + { k.search_resume, "FzfLua resume", desc = "Resume" }, + { k.search_quickfix, "FzfLua quickfix", desc = "Quickfix List" }, + { k.search_word_root, LazyVim.pick("grep_cword"), desc = "Word (Root Dir)" }, + { k.search_word_cwd, LazyVim.pick("grep_cword", { root = false }), desc = "Word (cwd)" }, + { k.search_selection_root, LazyVim.pick("grep_visual"), mode = "v", desc = "Selection (Root Dir)" }, + { k.search_selection_cwd, LazyVim.pick("grep_visual", { root = false }), mode = "v", desc = "Selection (cwd)" }, + { k.colorscheme_preview, LazyVim.pick("colorschemes"), desc = "Colorscheme with Preview" }, { - "ss", + k.go_to_symbol, function() require("fzf-lua").lsp_document_symbols({ regex_filter = symbols_filter, @@ -257,7 +267,7 @@ return { desc = "Goto Symbol", }, { - "sS", + k.go_to_symbol_workspace, function() require("fzf-lua").lsp_live_workspace_symbols({ regex_filter = symbols_filter, @@ -273,8 +283,8 @@ return { optional = true, -- stylua: ignore keys = { - { "st", function() require("todo-comments.fzf").todo() end, desc = "Todo" }, - { "sT", function () require("todo-comments.fzf").todo({ keywords = { "TODO", "FIX", "FIXME" } }) end, desc = "Todo/Fix/Fixme" }, + { t.todo_telescope, function() require("todo-comments.fzf").todo() end, desc = "Todo" }, + { t.todo_fix_fixme_telescope, function () require("todo-comments.fzf").todo({ keywords = { "TODO", "FIX", "FIXME" } }) end, desc = "Todo/Fix/Fixme" }, }, }, @@ -284,10 +294,10 @@ return { local Keys = require("lazyvim.plugins.lsp.keymaps").get() -- stylua: ignore vim.list_extend(Keys, { - { "gd", "FzfLua lsp_definitions jump_to_single_result=true ignore_current_line=true", desc = "Goto Definition", has = "definition" }, - { "gr", "FzfLua lsp_references jump_to_single_result=true ignore_current_line=true", desc = "References", nowait = true }, - { "gI", "FzfLua lsp_implementations jump_to_single_result=true ignore_current_line=true", desc = "Goto Implementation" }, - { "gy", "FzfLua lsp_typedefs jump_to_single_result=true ignore_current_line=true", desc = "Goto T[y]pe Definition" }, + { lang.go_to_definition, "FzfLua lsp_definitions jump_to_single_result=true ignore_current_line=true", desc = "Goto Definition", has = "definition" }, + { lang.references, "FzfLua lsp_references jump_to_single_result=true ignore_current_line=true", desc = "References", nowait = true }, + { lang.go_to_implementation, "FzfLua lsp_implementations jump_to_single_result=true ignore_current_line=true", desc = "Goto Implementation" }, + { lang.go_to_type_definition, "FzfLua lsp_typedefs jump_to_single_result=true ignore_current_line=true", desc = "Goto T[y]pe Definition" }, }) end, }, diff --git a/lua/lazyvim/plugins/extras/editor/harpoon2.lua b/lua/lazyvim/plugins/extras/editor/harpoon2.lua index 760d805a..19d2515e 100644 --- a/lua/lazyvim/plugins/extras/editor/harpoon2.lua +++ b/lua/lazyvim/plugins/extras/editor/harpoon2.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.harpoon2 + return { "ThePrimeagen/harpoon", branch = "harpoon2", @@ -12,14 +14,14 @@ return { keys = function() local keys = { { - "H", + k.harpoon_file, function() require("harpoon"):list():add() end, desc = "Harpoon File", }, { - "h", + k.harpoon_quick_menu, function() local harpoon = require("harpoon") harpoon.ui:toggle_quick_menu(harpoon:list()) @@ -30,7 +32,7 @@ return { for i = 1, 5 do table.insert(keys, { - "" .. i, + k.harpoon_to_file_prefix .. i, function() require("harpoon"):list():select(i) end, diff --git a/lua/lazyvim/plugins/extras/editor/illuminate.lua b/lua/lazyvim/plugins/extras/editor/illuminate.lua index d4f4bf89..2bc7b785 100644 --- a/lua/lazyvim/plugins/extras/editor/illuminate.lua +++ b/lua/lazyvim/plugins/extras/editor/illuminate.lua @@ -1,6 +1,8 @@ -- Automatically highlights other instances of the word under your cursor. -- This works with LSP, Treesitter, and regexp matching to find the other -- instances. +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.vim_illuminate + return { { "RRethy/vim-illuminate", @@ -16,26 +18,26 @@ return { require("illuminate").configure(opts) local function map(key, dir, buffer) - vim.keymap.set("n", key, function() + LazyVim.keymap_set("n", key, function() require("illuminate")["goto_" .. dir .. "_reference"](false) end, { desc = dir:sub(1, 1):upper() .. dir:sub(2) .. " Reference", buffer = buffer }) end - map("]]", "next") - map("[[", "prev") + map(k.next, "next") + map(k.prev, "prev") -- also set it after loading ftplugins, since a lot overwrite [[ and ]] vim.api.nvim_create_autocmd("FileType", { callback = function() local buffer = vim.api.nvim_get_current_buf() - map("]]", "next", buffer) - map("[[", "prev", buffer) + map(k.next, "next", buffer) + map(k.prev, "prev", buffer) end, }) end, keys = { - { "]]", desc = "Next Reference" }, - { "[[", desc = "Prev Reference" }, + { k.next, desc = "Next Reference" }, + { k.prev, desc = "Prev Reference" }, }, }, { diff --git a/lua/lazyvim/plugins/extras/editor/inc-rename.lua b/lua/lazyvim/plugins/extras/editor/inc-rename.lua index a7c65243..8421e536 100644 --- a/lua/lazyvim/plugins/extras/editor/inc-rename.lua +++ b/lua/lazyvim/plugins/extras/editor/inc-rename.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.inc_rename + return { -- Rename with cmdpreview @@ -15,7 +17,7 @@ return { opts = function() local keys = require("lazyvim.plugins.lsp.keymaps").get() keys[#keys + 1] = { - "cr", + k.rename, function() local inc_rename = require("inc_rename") return ":" .. inc_rename.config.cmd_name .. " " .. vim.fn.expand("") diff --git a/lua/lazyvim/plugins/extras/editor/leap.lua b/lua/lazyvim/plugins/extras/editor/leap.lua index 19c8b331..73167c71 100644 --- a/lua/lazyvim/plugins/extras/editor/leap.lua +++ b/lua/lazyvim/plugins/extras/editor/leap.lua @@ -1,3 +1,7 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.leap +local m = require("lazyvim.keymaps").get_keymaps().extras.coding.mini_surround +local default = require("lazyvim.keymaps").default_keymaps.extras.coding.mini_surround + return { -- disable flash { "folke/flash.nvim", enabled = false, optional = true }, @@ -20,9 +24,9 @@ return { "ggandor/leap.nvim", enabled = true, keys = { - { "s", mode = { "n", "x", "o" }, desc = "Leap Forward to" }, - { "S", mode = { "n", "x", "o" }, desc = "Leap Backward to" }, - { "gs", mode = { "n", "x", "o" }, desc = "Leap from Windows" }, + { k.next, mode = { "n", "x", "o" }, desc = "Leap Forward to" }, + { k.prev, mode = { "n", "x", "o" }, desc = "Leap Backward to" }, + { k.from_windows, mode = { "n", "x", "o" }, desc = "Leap from Windows" }, }, config = function(_, opts) local leap = require("leap") @@ -41,17 +45,17 @@ return { optional = true, opts = { mappings = { - add = "gza", -- Add surrounding in Normal and Visual modes - delete = "gzd", -- Delete surrounding - find = "gzf", -- Find surrounding (to the right) - find_left = "gzF", -- Find surrounding (to the left) - highlight = "gzh", -- Highlight surrounding - replace = "gzr", -- Replace surrounding - update_n_lines = "gzn", -- Update `n_lines` + add = m.add == default.add and "gza" or m.add, -- Add surrounding in Normal and Visual modes + delete = m.delete == default.delete and "gzd" or m.delete, -- Delete surrounding + find = m.find == default.find and "gzf" or m.find, -- Find surrounding (to the right) + find_left = m.find_left == default.find_left and "gzF" or m.find_left, -- Find surrounding (to the left) + highlight = m.highlight == default.highlight and "gzh" or m.highlight, -- Highlight surrounding + replace = m.replace == default.replace and "gzr" or m.replace, -- Replace surrounding + update_n_lines = m.update_n_lines == default.update_n_lines and "gzn" or m.update_n_lines, -- Update `n_lines` }, }, keys = { - { "gz", "", desc = "+surround" }, + { m.prefix == default.prefix and "gz" or m.prefix, "", desc = "+surround" }, }, }, diff --git a/lua/lazyvim/plugins/extras/editor/mini-diff.lua b/lua/lazyvim/plugins/extras/editor/mini-diff.lua index 6e5040ad..0d5fb1b2 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-diff.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-diff.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.mini_diff + return { -- disable gitsigns.nvim { @@ -11,7 +13,7 @@ return { event = "VeryLazy", keys = { { - "go", + k.toggle_overlay, function() require("mini.diff").toggle_overlay(0) end, diff --git a/lua/lazyvim/plugins/extras/editor/mini-files.lua b/lua/lazyvim/plugins/extras/editor/mini-files.lua index 461e6dca..e9904745 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-files.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-files.lua @@ -1,3 +1,6 @@ +local map = LazyVim.keymap_set +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.mini_files + return { "echasnovski/mini.files", opts = { @@ -14,14 +17,14 @@ return { }, keys = { { - "fm", + k.open_current_file_dir, function() require("mini.files").open(vim.api.nvim_buf_get_name(0), true) end, desc = "Open mini.files (Directory of Current File)", }, { - "fM", + k.open_cwd, function() require("mini.files").open(vim.uv.cwd(), true) end, @@ -64,7 +67,7 @@ return { if close_on_file then desc = desc .. " and close" end - vim.keymap.set("n", lhs, rhs, { buffer = buf_id, desc = desc }) + map("n", lhs, rhs, { buffer = buf_id, desc = desc }) end local files_set_cwd = function() @@ -80,14 +83,14 @@ return { callback = function(args) local buf_id = args.data.buf_id - vim.keymap.set( + map( "n", opts.mappings and opts.mappings.toggle_hidden or "g.", toggle_dotfiles, { buffer = buf_id, desc = "Toggle hidden files" } ) - vim.keymap.set( + map( "n", opts.mappings and opts.mappings.change_cwd or "gc", files_set_cwd, diff --git a/lua/lazyvim/plugins/extras/editor/outline.lua b/lua/lazyvim/plugins/extras/editor/outline.lua index 5b5a5831..eeb95d86 100644 --- a/lua/lazyvim/plugins/extras/editor/outline.lua +++ b/lua/lazyvim/plugins/extras/editor/outline.lua @@ -1,15 +1,18 @@ +local k = require("lazyvim.keymaps").get_keymaps().editor.trouble +local o = require("lazyvim.keymaps").get_keymaps().extras.editor.outline + return { -- Disable `cs` keymap so it doesn't conflict with `outline.nvim` { "folke/trouble.nvim", optional = true, keys = { - { "cs", false }, + { k.symbols_toggle, false }, }, }, { "hedyhli/outline.nvim", - keys = { { "cs", "Outline", desc = "Toggle Outline" } }, + keys = { { k.symbols_toggle, "Outline", desc = "Toggle Outline" } }, cmd = "Outline", opts = function() local defaults = require("outline.config").defaults @@ -18,12 +21,19 @@ return { icons = {}, filter = vim.deepcopy(LazyVim.config.kind_filter), }, - keymaps = { - up_and_jump = "", - down_and_jump = "", - }, + keymaps = {}, } + local keymaps = { + up_and_jump = o.up_and_jump, + down_and_jump = o.down_and_jump, + } + for key, value in pairs(keymaps) do + if value and value ~= "" then + opts.keymaps[key] = value + end + end + for kind, symbol in pairs(defaults.symbols.icons) do opts.symbols.icons[kind] = { icon = LazyVim.config.icons.kinds[kind] or symbol.icon, diff --git a/lua/lazyvim/plugins/extras/editor/overseer.lua b/lua/lazyvim/plugins/extras/editor/overseer.lua index 373c0029..dbe16d02 100644 --- a/lua/lazyvim/plugins/extras/editor/overseer.lua +++ b/lua/lazyvim/plugins/extras/editor/overseer.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.overseer + return { { "catppuccin", @@ -51,13 +53,13 @@ return { }, -- stylua: ignore keys = { - { "ow", "OverseerToggle", desc = "Task list" }, - { "oo", "OverseerRun", desc = "Run task" }, - { "oq", "OverseerQuickAction", desc = "Action recent task" }, - { "oi", "OverseerInfo", desc = "Overseer Info" }, - { "ob", "OverseerBuild", desc = "Task builder" }, - { "ot", "OverseerTaskAction", desc = "Task action" }, - { "oc", "OverseerClearCache", desc = "Clear cache" }, + { k.toggle, "OverseerToggle", desc = "Task list" }, + { k.run, "OverseerRun", desc = "Run task" }, + { k.quick_action, "OverseerQuickAction", desc = "Action recent task" }, + { k.info, "OverseerInfo", desc = "Overseer Info" }, + { k.build, "OverseerBuild", desc = "Task builder" }, + { k.task_action, "OverseerTaskAction", desc = "Task action" }, + { k.clear_cache, "OverseerClearCache", desc = "Clear cache" }, }, }, { @@ -65,7 +67,7 @@ return { optional = true, opts = { spec = { - { "o", group = "overseer" }, + k.prefix == "" and {} or { k.prefix, group = "overseer" }, }, }, }, diff --git a/lua/lazyvim/plugins/extras/editor/refactoring.lua b/lua/lazyvim/plugins/extras/editor/refactoring.lua index 29920347..d7a009e8 100644 --- a/lua/lazyvim/plugins/extras/editor/refactoring.lua +++ b/lua/lazyvim/plugins/extras/editor/refactoring.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.refactoring + local pick = function() if LazyVim.pick.picker.name == "telescope" then return require("telescope").extensions.refactoring.refactors() @@ -28,15 +30,15 @@ return { "nvim-treesitter/nvim-treesitter", }, keys = { - { "r", "", desc = "+refactor", mode = { "n", "v" } }, + { k.prefix, "", desc = "+refactor", mode = { "n", "v" } }, { - "rs", + k.refactor, pick, mode = "v", desc = "Refactor", }, { - "ri", + k.inline_variable, function() require("refactoring").refactor("Inline Variable") end, @@ -44,42 +46,42 @@ return { desc = "Inline Variable", }, { - "rb", + k.extract_block, function() require("refactoring").refactor("Extract Block") end, desc = "Extract Block", }, { - "rf", + k.extract_block_to_file, function() require("refactoring").refactor("Extract Block To File") end, desc = "Extract Block To File", }, { - "rP", + k.debug_print, function() require("refactoring").debug.printf({ below = false }) end, desc = "Debug Print", }, { - "rp", + k.debug_print_variable, function() require("refactoring").debug.print_var({ normal = true }) end, desc = "Debug Print Variable", }, { - "rc", + k.debug_cleanup, function() require("refactoring").debug.cleanup({}) end, desc = "Debug Cleanup", }, { - "rf", + k.extract_function, function() require("refactoring").refactor("Extract Function") end, @@ -87,7 +89,7 @@ return { desc = "Extract Function", }, { - "rF", + k.extract_function_to_file, function() require("refactoring").refactor("Extract Function To File") end, @@ -95,7 +97,7 @@ return { desc = "Extract Function To File", }, { - "rx", + k.extract_variable, function() require("refactoring").refactor("Extract Variable") end, @@ -103,7 +105,7 @@ return { desc = "Extract Variable", }, { - "rp", + k.debug_print_variable, function() require("refactoring").debug.print_var() end, diff --git a/lua/lazyvim/plugins/extras/editor/telescope.lua b/lua/lazyvim/plugins/extras/editor/telescope.lua index 11cfef1b..af7c1090 100644 --- a/lua/lazyvim/plugins/extras/editor/telescope.lua +++ b/lua/lazyvim/plugins/extras/editor/telescope.lua @@ -1,3 +1,7 @@ +local extras = require("lazyvim.keymaps").get_keymaps().extras +local k = extras.editor.picker +local lang = extras.lang + if lazyvim_docs then -- In case you don't want to use `:LazyExtras`, -- then you need to set the option below. @@ -86,51 +90,55 @@ return { }, keys = { { - ",", + k.switch_buffer, "Telescope buffers sort_mru=true sort_lastused=true", desc = "Switch Buffer", }, - { "/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, - { ":", "Telescope command_history", desc = "Command History" }, - { "", LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, + { k.grep_root, LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, + { k.command_history, "Telescope command_history", desc = "Command History" }, + { k.find_files_root, LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, -- find - { "fb", "Telescope buffers sort_mru=true sort_lastused=true", desc = "Buffers" }, - { "fc", LazyVim.pick.config_files(), desc = "Find Config File" }, - { "ff", LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, - { "fF", LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" }, - { "fg", "Telescope git_files", desc = "Find Files (git-files)" }, - { "fr", "Telescope oldfiles", desc = "Recent" }, - { "fR", LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" }, + { k.find_buffers, "Telescope buffers sort_mru=true sort_lastused=true", desc = "Buffers" }, + { k.find_config_file, LazyVim.pick.config_files(), desc = "Find Config File" }, + { k.find_files_root_alt, LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, + { k.find_files_cwd, LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" }, + { k.find_git_files, "Telescope git_files", desc = "Find Files (git-files)" }, + { k.find_recent_files, "Telescope oldfiles", desc = "Recent" }, + { k.find_files_cwd, LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" }, -- git - { "gc", "Telescope git_commits", desc = "Commits" }, - { "gs", "Telescope git_status", desc = "Status" }, + { k.git_commits, "Telescope git_commits", desc = "Commits" }, + { k.git_status, "Telescope git_status", desc = "Status" }, -- search - { 's"', "Telescope registers", desc = "Registers" }, - { "sa", "Telescope autocommands", desc = "Auto Commands" }, - { "sb", "Telescope current_buffer_fuzzy_find", desc = "Buffer" }, - { "sc", "Telescope command_history", desc = "Command History" }, - { "sC", "Telescope commands", desc = "Commands" }, - { "sd", "Telescope diagnostics bufnr=0", desc = "Document Diagnostics" }, - { "sD", "Telescope diagnostics", desc = "Workspace Diagnostics" }, - { "sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, - { "sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" }, - { "sh", "Telescope help_tags", desc = "Help Pages" }, - { "sH", "Telescope highlights", desc = "Search Highlight Groups" }, - { "sj", "Telescope jumplist", desc = "Jumplist" }, - { "sk", "Telescope keymaps", desc = "Key Maps" }, - { "sl", "Telescope loclist", desc = "Location List" }, - { "sM", "Telescope man_pages", desc = "Man Pages" }, - { "sm", "Telescope marks", desc = "Jump to Mark" }, - { "so", "Telescope vim_options", desc = "Options" }, - { "sR", "Telescope resume", desc = "Resume" }, - { "sq", "Telescope quickfix", desc = "Quickfix List" }, - { "sw", LazyVim.pick("grep_string", { word_match = "-w" }), desc = "Word (Root Dir)" }, - { "sW", LazyVim.pick("grep_string", { root = false, word_match = "-w" }), desc = "Word (cwd)" }, - { "sw", LazyVim.pick("grep_string"), mode = "v", desc = "Selection (Root Dir)" }, - { "sW", LazyVim.pick("grep_string", { root = false }), mode = "v", desc = "Selection (cwd)" }, - { "uC", LazyVim.pick("colorscheme", { enable_preview = true }), desc = "Colorscheme with Preview" }, + { k.search_registers, "Telescope registers", desc = "Registers" }, + { k.search_autocommands, "Telescope autocommands", desc = "Auto Commands" }, + { k.search_buffer, "Telescope current_buffer_fuzzy_find", desc = "Buffer" }, + { k.search_command_history, "Telescope command_history", desc = "Command History" }, + { k.search_commands, "Telescope commands", desc = "Commands" }, + { k.search_document_diagnostics, "Telescope diagnostics bufnr=0", desc = "Document Diagnostics" }, + { k.search_workspace_diagnostics, "Telescope diagnostics", desc = "Workspace Diagnostics" }, + { k.search_grep_root, LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, + { k.search_grep_cwd, LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" }, + { k.search_help_pages, "Telescope help_tags", desc = "Help Pages" }, + { k.search_highlight_groups, "Telescope highlights", desc = "Search Highlight Groups" }, + { k.search_jumplist, "Telescope jumplist", desc = "Jumplist" }, + { k.search_keymaps, "Telescope keymaps", desc = "Key Maps" }, + { k.search_loclist, "Telescope loclist", desc = "Location List" }, + { k.search_man_pages, "Telescope man_pages", desc = "Man Pages" }, + { k.search_marks, "Telescope marks", desc = "Jump to Mark" }, + { k.search_options, "Telescope vim_options", desc = "Options" }, + { k.search_resume, "Telescope resume", desc = "Resume" }, + { k.search_quickfix, "Telescope quickfix", desc = "Quickfix List" }, + { k.search_word_root, LazyVim.pick("grep_string", { word_match = "-w" }), desc = "Word (Root Dir)" }, + { k.search_word_cwd, LazyVim.pick("grep_string", { root = false, word_match = "-w" }), desc = "Word (cwd)" }, + { k.search_selection_root, LazyVim.pick("grep_string"), mode = "v", desc = "Selection (Root Dir)" }, + { k.search_selection_cwd, LazyVim.pick("grep_string", { root = false }), mode = "v", desc = "Selection (cwd)" }, { - "ss", + k.colorscheme_preview, + LazyVim.pick("colorscheme", { enable_preview = true }), + desc = "Colorscheme with Preview", + }, + { + k.go_to_symbol, function() require("telescope.builtin").lsp_document_symbols({ symbols = LazyVim.config.get_kind_filter(), @@ -139,7 +147,7 @@ return { desc = "Goto Symbol", }, { - "sS", + k.go_to_symbol_workspace, function() require("telescope.builtin").lsp_dynamic_workspace_symbols({ symbols = LazyVim.config.get_kind_filter(), @@ -179,6 +187,35 @@ return { end end + local keymaps = { + i = { + { k.actions.open_with_trouble, open_with_trouble }, + { k.actions.open_with_trouble_alt, open_with_trouble }, + { k.actions.find_files_no_ignore, find_files_no_ignore }, + { k.actions.find_files_with_hidden, find_files_with_hidden }, + { k.actions.cycle_history_next, actions.cycle_history_next }, + { k.actions.cycle_history_prev, actions.cycle_history_prev }, + { k.actions.preview_scrolling_down, actions.preview_scrolling_down }, + { k.actions.preview_scrolling_up, actions.preview_scrolling_up }, + }, + n = { + { k.actions.close, actions.close }, + }, + } + local mappings = { + i = {}, + n = {}, + } + local function filter_keymaps(_keymaps, source) + for _, keymap in ipairs(_keymaps) do + if keymap[1] and keymap[1] ~= "" then + source[keymap[1]] = keymap[2] + end + end + end + filter_keymaps(keymaps.i, mappings.i) + filter_keymaps(keymaps.n, mappings.n) + return { defaults = { prompt_prefix = " ", @@ -196,21 +233,7 @@ return { end return 0 end, - mappings = { - i = { - [""] = open_with_trouble, - [""] = open_with_trouble, - [""] = find_files_no_ignore, - [""] = find_files_with_hidden, - [""] = actions.cycle_history_next, - [""] = actions.cycle_history_prev, - [""] = actions.preview_scrolling_down, - [""] = actions.preview_scrolling_up, - }, - n = { - ["q"] = actions.close, - }, - }, + mappings = mappings, }, pickers = { find_files = { @@ -249,7 +272,7 @@ return { }) end opts.defaults = vim.tbl_deep_extend("force", opts.defaults or {}, { - mappings = { n = { s = flash }, i = { [""] = flash } }, + mappings = { n = k.flash.normal == "" and {} or { [k.flash.normal] = flash }, i = k.flash.insert == "" and {} or { [k.flash.insert] = flash } }, }) end, }, @@ -284,10 +307,10 @@ return { local Keys = require("lazyvim.plugins.lsp.keymaps").get() -- stylua: ignore vim.list_extend(Keys, { - { "gd", function() require("telescope.builtin").lsp_definitions({ reuse_win = true }) end, desc = "Goto Definition", has = "definition" }, - { "gr", "Telescope lsp_references", desc = "References", nowait = true }, - { "gI", function() require("telescope.builtin").lsp_implementations({ reuse_win = true }) end, desc = "Goto Implementation" }, - { "gy", function() require("telescope.builtin").lsp_type_definitions({ reuse_win = true }) end, desc = "Goto T[y]pe Definition" }, + { lang.go_to_definition, function() require("telescope.builtin").lsp_definitions({ reuse_win = true }) end, desc = "Goto Definition", has = "definition" }, + { lang.references, "Telescope lsp_references", desc = "References", nowait = true }, + { lang.go_to_implementation, function() require("telescope.builtin").lsp_implementations({ reuse_win = true }) end, desc = "Goto Implementation" }, + { lang.go_to_type_definition, function() require("telescope.builtin").lsp_type_definitions({ reuse_win = true }) end, desc = "Goto T[y]pe Definition" }, }) end, }, diff --git a/lua/lazyvim/plugins/extras/lang/ansible.lua b/lua/lazyvim/plugins/extras/lang/ansible.lua index 29d1711a..315494f2 100644 --- a/lua/lazyvim/plugins/extras/lang/ansible.lua +++ b/lua/lazyvim/plugins/extras/lang/ansible.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.ansible + return { recommended = function() return LazyVim.extras.wants({ @@ -22,7 +24,7 @@ return { ft = {}, keys = { { - "ta", + k.ansible_run_playbook_role, function() require("ansible").run() end, diff --git a/lua/lazyvim/plugins/extras/lang/clangd.lua b/lua/lazyvim/plugins/extras/lang/clangd.lua index dccbc9cb..0272a47e 100644 --- a/lua/lazyvim/plugins/extras/lang/clangd.lua +++ b/lua/lazyvim/plugins/extras/lang/clangd.lua @@ -1,3 +1,4 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.clangd return { recommended = function() return LazyVim.extras.wants({ @@ -58,7 +59,8 @@ return { -- Ensure mason installs the server clangd = { keys = { - { "ch", "ClangdSwitchSourceHeader", desc = "Switch Source/Header (C/C++)" }, + k.switch_source_header == "" and {} + or { k.switch_source_header, "ClangdSwitchSourceHeader", desc = "Switch Source/Header (C/C++)" }, }, root_dir = function(fname) return require("lspconfig.util").root_pattern( diff --git a/lua/lazyvim/plugins/extras/lang/clojure.lua b/lua/lazyvim/plugins/extras/lang/clojure.lua index 7197aabd..9c6c6adc 100644 --- a/lua/lazyvim/plugins/extras/lang/clojure.lua +++ b/lua/lazyvim/plugins/extras/lang/clojure.lua @@ -1,3 +1,6 @@ +local map = LazyVim.keymap_set +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.clojure + return { recommended = function() return LazyVim.extras.wants({ @@ -75,17 +78,17 @@ return { vim.g.conjure_baleia.automatically(buffer) end - vim.keymap.set( + map( { "n", "v" }, - "[c", + k.jump_prev_evaluation_output, "call search('^; -\\+$', 'bw')", - { silent = true, buffer = true, desc = "Jumps to the begining of previous evaluation output." } + { silent = true, buffer = true, desc = "Jumps to the beginning of previous evaluation output." } ) - vim.keymap.set( + map( { "n", "v" }, - "]c", + k.jump_next_evaluation_output, "call search('^; -\\+$', 'w')", - { silent = true, buffer = true, desc = "Jumps to the begining of next evaluation output." } + { silent = true, buffer = true, desc = "Jumps to the beginning of next evaluation output." } ) end, }) diff --git a/lua/lazyvim/plugins/extras/lang/elixir.lua b/lua/lazyvim/plugins/extras/lang/elixir.lua index f391edbd..3a558db6 100644 --- a/lua/lazyvim/plugins/extras/lang/elixir.lua +++ b/lua/lazyvim/plugins/extras/lang/elixir.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.elixir + return { recommended = function() return LazyVim.extras.wants({ @@ -12,7 +14,7 @@ return { elixirls = { keys = { { - "cp", + k.to_pipe, function() local params = vim.lsp.util.make_position_params() LazyVim.lsp.execute({ @@ -23,7 +25,7 @@ return { desc = "To Pipe", }, { - "cP", + k.from_pipe, function() local params = vim.lsp.util.make_position_params() LazyVim.lsp.execute({ diff --git a/lua/lazyvim/plugins/extras/lang/java.lua b/lua/lazyvim/plugins/extras/lang/java.lua index 6b83fe29..de59ab85 100644 --- a/lua/lazyvim/plugins/extras/lang/java.lua +++ b/lua/lazyvim/plugins/extras/lang/java.lua @@ -1,5 +1,8 @@ -- This is the same as in lspconfig.configs.jdtls, but avoids -- needing to require that when this module loads. +local k = require("lazyvim.keymaps").get_keymaps().extras.lang +local t = require("lazyvim.keymaps").get_keymaps().extras.test.core + local java_filetypes = { "java" } -- Utility function to extend or override a config table, similar to the way @@ -194,32 +197,31 @@ return { { mode = "n", buffer = args.buf, - { "cx", group = "extract" }, - { "cxv", require("jdtls").extract_variable_all, desc = "Extract Variable" }, - { "cxc", require("jdtls").extract_constant, desc = "Extract Constant" }, - { "gs", require("jdtls").super_implementation, desc = "Goto Super" }, - { "gS", require("jdtls.tests").goto_subjects, desc = "Goto Subjects" }, - { "co", require("jdtls").organize_imports, desc = "Organize Imports" }, + { k.extract.prefix, group = "extract" }, + { k.extract.variable, require("jdtls").extract_variable_all, desc = "Extract Variable" }, + { k.extract.constant, require("jdtls").extract_constant, desc = "Extract Constant" }, + { k.go_to_super, require("jdtls").super_implementation, desc = "Goto Super" }, + { k.go_to_subjects, require("jdtls.tests").goto_subjects, desc = "Goto Subjects" }, + { k.organize_imports, require("jdtls").organize_imports, desc = "Organize Imports" }, }, }) wk.add({ { mode = "v", buffer = args.buf, - { "cx", group = "extract" }, + { k.extract.prefix, group = "extract" }, { - "cxm", + k.extract.method, [[lua require('jdtls').extract_method(true)]], desc = "Extract Method", }, { - "cxv", + k.extract.variable, [[lua require('jdtls').extract_variable_all(true)]], desc = "Extract Variable", }, { - "cxc", - [[lua require('jdtls').extract_constant(true)]], + k.extract.constant([[lua require('jdtls').extract_constant(true)]]), desc = "Extract Constant", }, }, @@ -237,9 +239,9 @@ return { { mode = "n", buffer = args.buf, - { "t", group = "test" }, + { t.prefix, group = "test" }, { - "tt", + t.run_all_test_files, function() require("jdtls.dap").test_class({ config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil, @@ -248,7 +250,7 @@ return { desc = "Run All Test", }, { - "tr", + t.run_nearest, function() require("jdtls.dap").test_nearest_method({ config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil, @@ -256,7 +258,7 @@ return { end, desc = "Run Nearest Test", }, - { "tT", require("jdtls.dap").pick_test, desc = "Run Test" }, + { t.run_file, require("jdtls.dap").pick_test, desc = "Run Test" }, }, }) end diff --git a/lua/lazyvim/plugins/extras/lang/lean.lua b/lua/lazyvim/plugins/extras/lang/lean.lua index 58488372..a510161e 100644 --- a/lua/lazyvim/plugins/extras/lang/lean.lua +++ b/lua/lazyvim/plugins/extras/lang/lean.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.lean + return { recommended = function() return LazyVim.extras.wants({ @@ -60,7 +62,7 @@ return { }, -- Change if you don't like the backslash -- (comma is a popular choice on French keyboards) - leader = "\\", + leader = k.abbreviations_leader, }, -- Enable suggested mappings? diff --git a/lua/lazyvim/plugins/extras/lang/markdown.lua b/lua/lazyvim/plugins/extras/lang/markdown.lua index 4829098b..a1d31082 100644 --- a/lua/lazyvim/plugins/extras/lang/markdown.lua +++ b/lua/lazyvim/plugins/extras/lang/markdown.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.markdown + LazyVim.on_very_lazy(function() vim.filetype.add({ extension = { mdx = "markdown.mdx" }, @@ -81,7 +83,7 @@ return { end, keys = { { - "cp", + k.markdown_preview_toggle, ft = "markdown", "MarkdownPreviewToggle", desc = "Markdown Preview", @@ -108,7 +110,7 @@ return { ft = { "markdown", "norg", "rmd", "org" }, config = function(_, opts) require("render-markdown").setup(opts) - LazyVim.toggle.map("um", { + LazyVim.toggle.map(k.render_markdown_toggle, { name = "Render Markdown", get = function() return require("render-markdown.state").enabled diff --git a/lua/lazyvim/plugins/extras/lang/omnisharp.lua b/lua/lazyvim/plugins/extras/lang/omnisharp.lua index 3881e6a4..2c55dc6b 100644 --- a/lua/lazyvim/plugins/extras/lang/omnisharp.lua +++ b/lua/lazyvim/plugins/extras/lang/omnisharp.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang + return { recommended = function() return LazyVim.extras.wants({ @@ -51,7 +53,7 @@ return { }, keys = { { - "gd", + k.go_to_definition, LazyVim.has("telescope.nvim") and function() require("omnisharp_extended").telescope_lsp_definitions() end or function() diff --git a/lua/lazyvim/plugins/extras/lang/python.lua b/lua/lazyvim/plugins/extras/lang/python.lua index 4c098452..224e0879 100644 --- a/lua/lazyvim/plugins/extras/lang/python.lua +++ b/lua/lazyvim/plugins/extras/lang/python.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang + if lazyvim_docs then -- LSP Server to use for Python. -- Set to "basedpyright" to use basedpyright instead of pyright. @@ -40,7 +42,7 @@ return { }, keys = { { - "co", + k.organize_imports, LazyVim.lsp.action["source.organizeImports"], desc = "Organize Imports", }, @@ -49,7 +51,7 @@ return { ruff_lsp = { keys = { { - "co", + k.organize_imports, LazyVim.lsp.action["source.organizeImports"], desc = "Organize Imports", }, @@ -99,8 +101,8 @@ return { "mfussenegger/nvim-dap-python", -- stylua: ignore keys = { - { "dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" }, - { "dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" }, + { k.python.debug_method, function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" }, + { k.python.debug_class, function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" }, }, config = function() if vim.fn.has("win32") == 1 then @@ -128,7 +130,7 @@ return { }, -- Call config for python files and load the cached venv automatically ft = "python", - keys = { { "cv", ":VenvSelect", desc = "Select VirtualEnv", ft = "python" } }, + keys = { { k.python.select_virtual_env, ":VenvSelect", desc = "Select VirtualEnv", ft = "python" } }, }, { diff --git a/lua/lazyvim/plugins/extras/lang/r.lua b/lua/lazyvim/plugins/extras/lang/r.lua index f2c46041..9f3038ce 100644 --- a/lua/lazyvim/plugins/extras/lang/r.lua +++ b/lua/lazyvim/plugins/extras/lang/r.lua @@ -1,3 +1,6 @@ +local map = LazyVim.keymap_set +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.r + return { recommended = function() return LazyVim.extras.wants({ @@ -16,25 +19,25 @@ return { -- This function will be called at the FileType event -- of files supported by R.nvim. This is an -- opportunity to create mappings local to buffers. - vim.keymap.set("n", "", "RDSendLine", { buffer = true }) - vim.keymap.set("v", "", "RSendSelection", { buffer = true }) + map("n", k.send, "RDSendLine", { buffer = true }) + map("v", k.send, "RSendSelection", { buffer = true }) local wk = require("which-key") wk.add({ buffer = true, - { "a", group = "all" }, - { "b", group = "between marks" }, - { "c", group = "chunks" }, - { "f", group = "functions" }, - { "g", group = "goto" }, - { "i", group = "install" }, - { "k", group = "knit" }, - { "p", group = "paragraph" }, - { "q", group = "quarto" }, - { "r", group = "r general" }, - { "s", group = "split or send" }, - { "t", group = "terminal" }, - { "v", group = "view" }, + { k.send_all, group = "all" }, + { k.send_between_marks, group = "between marks" }, + { k.send_chunks, group = "chunks" }, + { k.send_functions, group = "functions" }, + { k.send_goto, group = "goto" }, + { k.send_install, group = "install" }, + { k.send_knit, group = "knit" }, + { k.send_paragraph, group = "paragraph" }, + { k.send_quarto, group = "quarto" }, + { k.send_general, group = "r general" }, + { k.send_split_or_send, group = "split or send" }, + { k.send_terminal, group = "terminal" }, + { k.send_view, group = "view" }, }) end, }, diff --git a/lua/lazyvim/plugins/extras/lang/rust.lua b/lua/lazyvim/plugins/extras/lang/rust.lua index 145940ca..c6f4e04e 100644 --- a/lua/lazyvim/plugins/extras/lang/rust.lua +++ b/lua/lazyvim/plugins/extras/lang/rust.lua @@ -1,3 +1,6 @@ +local map = LazyVim.keymap_set +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.rust + return { recommended = function() return LazyVim.extras.wants({ @@ -48,10 +51,10 @@ return { opts = { server = { on_attach = function(_, bufnr) - vim.keymap.set("n", "cR", function() + map("n", k.code_action, function() vim.cmd.RustLsp("codeAction") end, { desc = "Code Action", buffer = bufnr }) - vim.keymap.set("n", "dr", function() + map("n", k.debuggables, function() vim.cmd.RustLsp("debuggables") end, { desc = "Rust Debuggables", buffer = bufnr }) end, @@ -98,7 +101,7 @@ return { taplo = { keys = { { - "K", + k.show_crate_documentation, function() if vim.fn.expand("%:t") == "Cargo.toml" and require("crates").popup_available() then require("crates").show_popup() diff --git a/lua/lazyvim/plugins/extras/lang/scala.lua b/lua/lazyvim/plugins/extras/lang/scala.lua index 3b159697..51493555 100644 --- a/lua/lazyvim/plugins/extras/lang/scala.lua +++ b/lua/lazyvim/plugins/extras/lang/scala.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.scala + return { recommended = function() return LazyVim.extras.wants({ @@ -21,14 +23,14 @@ return { metals = { keys = { { - "me", + k.metals_commands, function() require("telescope").extensions.metals.commands() end, desc = "Metals commands", }, { - "mc", + k.metals_compile_cascade, function() require("metals").compile_cascade() end, diff --git a/lua/lazyvim/plugins/extras/lang/sql.lua b/lua/lazyvim/plugins/extras/lang/sql.lua index a4b426ba..88dceb1d 100644 --- a/lua/lazyvim/plugins/extras/lang/sql.lua +++ b/lua/lazyvim/plugins/extras/lang/sql.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.sql + if lazyvim_docs then -- The setup below will automatically configure connections without the need for manual input each time. @@ -71,7 +73,7 @@ return { cmd = { "DBUI", "DBUIToggle", "DBUIAddConnection", "DBUIFindBuffer" }, dependencies = "vim-dadbod", keys = { - { "D", "DBUIToggle", desc = "Toggle DBUI" }, + { k.toggle_dbui, "DBUIToggle", desc = "Toggle DBUI" }, }, init = function() local data_path = vim.fn.stdpath("data") diff --git a/lua/lazyvim/plugins/extras/lang/svelte.lua b/lua/lazyvim/plugins/extras/lang/svelte.lua index 565e50e5..541a5ba2 100644 --- a/lua/lazyvim/plugins/extras/lang/svelte.lua +++ b/lua/lazyvim/plugins/extras/lang/svelte.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang + return { recommended = function() return LazyVim.extras.wants({ @@ -26,7 +28,7 @@ return { svelte = { keys = { { - "co", + k.organize_imports, LazyVim.lsp.action["source.organizeImports"], desc = "Organize Imports", }, diff --git a/lua/lazyvim/plugins/extras/lang/tex.lua b/lua/lazyvim/plugins/extras/lang/tex.lua index 870a3fda..e86dc1c7 100644 --- a/lua/lazyvim/plugins/extras/lang/tex.lua +++ b/lua/lazyvim/plugins/extras/lang/tex.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang.tex + return { recommended = function() return LazyVim.extras.wants({ @@ -30,7 +32,7 @@ return { vim.g.vimtex_quickfix_method = vim.fn.executable("pplatex") == 1 and "pplatex" or "latexlog" end, keys = { - { "l", "", desc = "+vimtex" }, + { k.prefix, "", desc = "+vimtex" }, }, }, @@ -42,7 +44,7 @@ return { servers = { texlab = { keys = { - { "K", "(vimtex-doc-package)", desc = "Vimtex Docs", silent = true }, + { k.vimtex_docs, "(vimtex-doc-package)", desc = "Vimtex Docs", silent = true }, }, }, }, diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index dd5ca25c..543288c2 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang + return { recommended = function() return LazyVim.extras.wants({ @@ -66,7 +68,7 @@ return { }, keys = { { - "gD", + k.typescript.go_to_source_definition, function() local params = vim.lsp.util.make_position_params() LazyVim.lsp.execute({ @@ -78,7 +80,7 @@ return { desc = "Goto Source Definition", }, { - "gR", + k.file_references, function() LazyVim.lsp.execute({ command = "typescript.findAllFileReferences", @@ -89,27 +91,27 @@ return { desc = "File References", }, { - "co", + k.organize_imports, LazyVim.lsp.action["source.organizeImports"], desc = "Organize Imports", }, { - "cM", + k.add_missing_imports, LazyVim.lsp.action["source.addMissingImports.ts"], desc = "Add missing imports", }, { - "cu", + k.remove_unused_imports, LazyVim.lsp.action["source.removeUnused.ts"], desc = "Remove unused imports", }, { - "cD", + k.fix_all_diagnostics, LazyVim.lsp.action["source.fixAll.ts"], desc = "Fix all diagnostics", }, { - "cV", + k.select_lang_version, function() LazyVim.lsp.execute({ command = "typescript.selectTypeScriptVersion" }) end, diff --git a/lua/lazyvim/plugins/extras/test/core.lua b/lua/lazyvim/plugins/extras/test/core.lua index f9d8a4ac..a9ca16bf 100644 --- a/lua/lazyvim/plugins/extras/test/core.lua +++ b/lua/lazyvim/plugins/extras/test/core.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.test.core + return { recommended = true, desc = "Neotest support. Requires language specific adapters to be configured. (see lang extras)", @@ -105,16 +107,16 @@ return { end, -- stylua: ignore keys = { - {"t", "", desc = "+test"}, - { "tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" }, - { "tT", function() require("neotest").run.run(vim.uv.cwd()) end, desc = "Run All Test Files" }, - { "tr", function() require("neotest").run.run() end, desc = "Run Nearest" }, - { "tl", function() require("neotest").run.run_last() end, desc = "Run Last" }, - { "ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" }, - { "to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" }, - { "tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" }, - { "tS", function() require("neotest").run.stop() end, desc = "Stop" }, - { "tw", function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" }, + { k.prefix, "", desc = "+test"}, + { k.run_file, function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" }, + { k.run_all_test_files, function() require("neotest").run.run(vim.uv.cwd()) end, desc = "Run All Test Files" }, + { k.run_nearest, function() require("neotest").run.run() end, desc = "Run Nearest" }, + { k.run_last, function() require("neotest").run.run_last() end, desc = "Run Last" }, + { k.toggle_summary, function() require("neotest").summary.toggle() end, desc = "Toggle Summary" }, + { k.show_output, function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" }, + { k.toggle_output_panel, function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" }, + { k.stop, function() require("neotest").run.stop() end, desc = "Stop" }, + { k.toggle_watch, function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" }, }, }, { @@ -122,7 +124,7 @@ return { optional = true, -- stylua: ignore keys = { - { "td", function() require("neotest").run.run({strategy = "dap"}) end, desc = "Debug Nearest" }, + { k.debug_nearest, function() require("neotest").run.run({strategy = "dap"}) end, desc = "Debug Nearest" }, }, }, } diff --git a/lua/lazyvim/plugins/extras/ui/alpha.lua b/lua/lazyvim/plugins/extras/ui/alpha.lua index 1898bd08..f60ba1bc 100644 --- a/lua/lazyvim/plugins/extras/ui/alpha.lua +++ b/lua/lazyvim/plugins/extras/ui/alpha.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().ui.dashboard + return { { "nvimdev/dashboard-nvim", enabled = false }, @@ -22,17 +24,25 @@ return { dashboard.section.header.val = vim.split(logo, "\n") -- stylua: ignore - dashboard.section.buttons.val = { - dashboard.button("f", " " .. " Find file", LazyVim.pick()), - dashboard.button("n", " " .. " New file", [[ ene startinsert ]]), - dashboard.button("r", " " .. " Recent files", LazyVim.pick("oldfiles")), - dashboard.button("g", " " .. " Find text", LazyVim.pick("live_grep")), - dashboard.button("c", " " .. " Config", LazyVim.pick.config_files()), - dashboard.button("s", " " .. " Restore Session", [[ lua require("persistence").load() ]]), - dashboard.button("x", " " .. " Lazy Extras", " LazyExtras "), - dashboard.button("l", "󰒲 " .. " Lazy", " Lazy "), - dashboard.button("q", " " .. " Quit", " qa "), + dashboard.section.buttons.val = {} + local actions = { + { k.find_file, " " .. " Find file", LazyVim.pick() }, + { k.new_file, " " .. " New file", [[ ene startinsert ]] }, + { k.recent_files, " " .. " Recent files", LazyVim.pick("oldfiles") }, + { k.find_text, " " .. " Find text", LazyVim.pick("live_grep") }, + { k.config, " " .. " Config", LazyVim.pick.config_files() }, + { k.restore_session, " " .. " Restore Session", [[ lua require("persistence").load() ]] }, + { k.lazy_extras, " " .. " Lazy Extras", " LazyExtras " }, + { k.lazy, "󰒲 " .. " Lazy", " Lazy " }, + { k.quit, " " .. " Quit", " qa " }, } + + for _, action in ipairs(actions) do + if action[1] and action[1] ~= "" then + table.insert(dashboard.section.buttons.val, dashboard.button(action[1], action[2], action[3])) + end + end + for _, button in ipairs(dashboard.section.buttons.val) do button.opts.hl = "AlphaButtons" button.opts.hl_shortcut = "AlphaShortcut" diff --git a/lua/lazyvim/plugins/extras/ui/edgy.lua b/lua/lazyvim/plugins/extras/ui/edgy.lua index f63e31ad..c2cdf077 100644 --- a/lua/lazyvim/plugins/extras/ui/edgy.lua +++ b/lua/lazyvim/plugins/extras/ui/edgy.lua @@ -1,3 +1,6 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.ui.edgy +local r = require("lazyvim.keymaps").get_keymaps().keymaps.resize_window + return { -- edgy { @@ -5,16 +8,42 @@ return { event = "VeryLazy", keys = { { - "ue", + k.toggle, function() require("edgy").toggle() end, desc = "Edgy Toggle", }, -- stylua: ignore - { "uE", function() require("edgy").select() end, desc = "Edgy Select Window" }, + { k.select_window, function() require("edgy").select() end, desc = "Edgy Select Window" }, }, opts = function() + local keys = {} + local actions = { + -- increase width + [r.increase_width] = function(win) + win:resize("width", 2) + end, + -- decrease width + [r.decrease_width] = function(win) + win:resize("width", -2) + end, + -- increase height + [r.increase_height] = function(win) + win:resize("height", 2) + end, + -- decrease height + [r.decrease_height] = function(win) + win:resize("height", -2) + end, + } + + for key, action in pairs(actions) do + if key and key ~= "" then + keys[key] = action + end + end + local opts = { bottom = { { @@ -59,24 +88,7 @@ return { right = { { title = "Grug Far", ft = "grug-far", size = { width = 0.4 } }, }, - keys = { - -- increase width - [""] = function(win) - win:resize("width", 2) - end, - -- decrease width - [""] = function(win) - win:resize("width", -2) - end, - -- increase height - [""] = function(win) - win:resize("height", 2) - end, - -- decrease height - [""] = function(win) - win:resize("height", -2) - end, - }, + keys = keys, } if LazyVim.has("neo-tree.nvim") then diff --git a/lua/lazyvim/plugins/extras/ui/mini-animate.lua b/lua/lazyvim/plugins/extras/ui/mini-animate.lua index 1136230a..60d3e620 100644 --- a/lua/lazyvim/plugins/extras/ui/mini-animate.lua +++ b/lua/lazyvim/plugins/extras/ui/mini-animate.lua @@ -1,4 +1,6 @@ -- animations +local k = require("lazyvim.keymaps").get_keymaps().extras.ui.mini_animate + return { "echasnovski/mini.animate", recommended = true, @@ -21,7 +23,7 @@ return { end, }) - LazyVim.toggle.map("ua", { + LazyVim.toggle.map(k.toggle, { name = "Mini Animate", get = function() return not vim.g.minianimate_disable diff --git a/lua/lazyvim/plugins/extras/ui/treesitter-context.lua b/lua/lazyvim/plugins/extras/ui/treesitter-context.lua index 019977ed..4e4625fc 100644 --- a/lua/lazyvim/plugins/extras/ui/treesitter-context.lua +++ b/lua/lazyvim/plugins/extras/ui/treesitter-context.lua @@ -1,11 +1,13 @@ -- Show context of the current function +local k = require("lazyvim.keymaps").get_keymaps().extras.ui.treesitter_context + return { "nvim-treesitter/nvim-treesitter-context", event = "VeryLazy", opts = function() local tsc = require("treesitter-context") - LazyVim.toggle.map("ut", { + LazyVim.toggle.map(k.toggle, { name = "Treesitter Context", get = tsc.enabled, set = function(state) diff --git a/lua/lazyvim/plugins/extras/util/chezmoi.lua b/lua/lazyvim/plugins/extras/util/chezmoi.lua index 633f3008..4d5c62e3 100644 --- a/lua/lazyvim/plugins/extras/util/chezmoi.lua +++ b/lua/lazyvim/plugins/extras/util/chezmoi.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.util.chezmoi + local pick_chezmoi = function() if LazyVim.pick.picker.name == "telescope" then require("telescope").extensions.chezmoi.find_files() @@ -35,7 +37,7 @@ return { "xvzc/chezmoi.nvim", keys = { { - "sz", + k.pick_chezmoi, pick_chezmoi, desc = "Chezmoi", }, @@ -51,7 +53,7 @@ return { on_watch = false, }, telescope = { - select = { "" }, + select = k.select == "" and {} or { k.select }, }, }, init = function() @@ -68,11 +70,15 @@ return { "nvimdev/dashboard-nvim", optional = true, opts = function(_, opts) + if not k.key or k.key == "" then + return opts + end + local projects = { action = pick_chezmoi, desc = " Config", icon = "", - key = "c", + key = k.key, } projects.desc = projects.desc .. string.rep(" ", 43 - #projects.desc) diff --git a/lua/lazyvim/plugins/extras/util/gitui.lua b/lua/lazyvim/plugins/extras/util/gitui.lua index b5033235..fc882f47 100644 --- a/lua/lazyvim/plugins/extras/util/gitui.lua +++ b/lua/lazyvim/plugins/extras/util/gitui.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().keymaps.lazygit + return { -- Ensure GitUI tool is installed @@ -6,14 +8,14 @@ return { opts = { ensure_installed = { "gitui" } }, keys = { { - "gG", + k.toggle_cwd, function() LazyVim.terminal.open({ "gitui" }, { esc_esc = false, ctrl_hjkl = false }) end, desc = "GitUi (cwd)", }, { - "gg", + k.toggle_root, function() LazyVim.terminal.open({ "gitui" }, { cwd = LazyVim.root.get(), esc_esc = false, ctrl_hjkl = false }) end, diff --git a/lua/lazyvim/plugins/extras/util/octo.lua b/lua/lazyvim/plugins/extras/util/octo.lua index a8286265..e5c0ecc3 100644 --- a/lua/lazyvim/plugins/extras/util/octo.lua +++ b/lua/lazyvim/plugins/extras/util/octo.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.util.octo + return { -- depends on the git extra for highlighting and auto-completion of github issues/prs @@ -15,22 +17,22 @@ return { picker = "telescope", }, keys = { - { "gi", "Octo issue list", desc = "List Issues (Octo)" }, - { "gI", "Octo issue search", desc = "Search Issues (Octo)" }, - { "gp", "Octo pr list", desc = "List PRs (Octo)" }, - { "gP", "Octo pr search", desc = "Search PRs (Octo)" }, - { "gr", "Octo repo list", desc = "List Repos (Octo)" }, - { "gS", "Octo search", desc = "Search (Octo)" }, + { k.issue_list, "Octo issue list", desc = "List Issues (Octo)" }, + { k.issue_search, "Octo issue search", desc = "Search Issues (Octo)" }, + { k.pr_list, "Octo pr list", desc = "List PRs (Octo)" }, + { k.pr_search, "Octo pr search", desc = "Search PRs (Octo)" }, + { k.repo_list, "Octo repo list", desc = "List Repos (Octo)" }, + { k.search, "Octo search", desc = "Search (Octo)" }, - { "a", "", desc = "+assignee (Octo)", ft = "octo" }, - { "c", "", desc = "+comment/code (Octo)", ft = "octo" }, - { "l", "", desc = "+label (Octo)", ft = "octo" }, - { "i", "", desc = "+issue (Octo)", ft = "octo" }, - { "r", "", desc = "+react (Octo)", ft = "octo" }, - { "p", "", desc = "+pr (Octo)", ft = "octo" }, - { "v", "", desc = "+review (Octo)", ft = "octo" }, - { "@", "@", mode = "i", ft = "octo", silent = true }, - { "#", "#", mode = "i", ft = "octo", silent = true }, + { k.assignee, "", desc = "+assignee (Octo)", ft = "octo" }, + { k.comment_code, "", desc = "+comment/code (Octo)", ft = "octo" }, + { k.label, "", desc = "+label (Octo)", ft = "octo" }, + { k.issue, "", desc = "+issue (Octo)", ft = "octo" }, + { k.react, "", desc = "+react (Octo)", ft = "octo" }, + { k.pr, "", desc = "+pr (Octo)", ft = "octo" }, + { k.review, "", desc = "+review (Octo)", ft = "octo" }, + { k.insert_at, "@", mode = "i", ft = "octo", silent = true }, + { k.insert_hashtag, "#", mode = "i", ft = "octo", silent = true }, }, }, diff --git a/lua/lazyvim/plugins/extras/util/project.lua b/lua/lazyvim/plugins/extras/util/project.lua index 77705f37..329eeb25 100644 --- a/lua/lazyvim/plugins/extras/util/project.lua +++ b/lua/lazyvim/plugins/extras/util/project.lua @@ -1,3 +1,6 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.editor.picker +local d = require("lazyvim.keymaps").get_keymaps().ui.dashboard + local pick = nil pick = function() @@ -101,7 +104,7 @@ return { "nvim-telescope/telescope.nvim", optional = true, keys = { - { "fp", pick, desc = "Projects" }, + { k.find_projects, pick, desc = "Projects" }, }, }, @@ -109,7 +112,7 @@ return { "ibhagwan/fzf-lua", optional = true, keys = { - { "fp", pick, desc = "Projects" }, + { k.find_projects, pick, desc = "Projects" }, }, }, @@ -143,11 +146,15 @@ return { "nvimdev/dashboard-nvim", optional = true, opts = function(_, opts) + if not d.projects or d.projects == "" then + return opts + end + local projects = { action = pick, desc = " Projects", icon = " ", - key = "p", + key = d.projects, } projects.desc = projects.desc .. string.rep(" ", 43 - #projects.desc) diff --git a/lua/lazyvim/plugins/extras/util/rest.lua b/lua/lazyvim/plugins/extras/util/rest.lua index 61092ca6..1dbdc5db 100644 --- a/lua/lazyvim/plugins/extras/util/rest.lua +++ b/lua/lazyvim/plugins/extras/util/rest.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.util.rest.kulala + vim.filetype.add({ extension = { ["http"] = "http", @@ -8,11 +10,11 @@ return { "mistweaverco/kulala.nvim", ft = "http", keys = { - { "R", "", desc = "+Rest" }, - { "Rs", "lua require('kulala').run()", desc = "Send the request" }, - { "Rt", "lua require('kulala').toggle_view()", desc = "Toggle headers/body" }, - { "Rp", "lua require('kulala').jump_prev()", desc = "Jump to previous request" }, - { "Rn", "lua require('kulala').jump_next()", desc = "Jump to next request" }, + { k.prefix, "", desc = "+Rest" }, + { k.send_request, "lua require('kulala').run()", desc = "Send the request" }, + { k.toggle_view, "lua require('kulala').toggle_view()", desc = "Toggle headers/body" }, + { k.jump_to_previous_request, "lua require('kulala').jump_prev()", desc = "Jump to previous request" }, + { k.jump_to_next_request, "lua require('kulala').jump_next()", desc = "Jump to next request" }, }, opts = {}, }, diff --git a/lua/lazyvim/plugins/extras/vscode.lua b/lua/lazyvim/plugins/extras/vscode.lua index a272d2ce..38421997 100644 --- a/lua/lazyvim/plugins/extras/vscode.lua +++ b/lua/lazyvim/plugins/extras/vscode.lua @@ -28,13 +28,16 @@ Config.options.defaults.cond = function(plugin) return vim.tbl_contains(enabled, plugin.name) or plugin.vscode end +local map = LazyVim.keymap_set +local k = require("lazyvim.keymaps").get_keymaps().extras.vscode + -- Add some vscode specific keymaps vim.api.nvim_create_autocmd("User", { pattern = "LazyVimKeymapsDefaults", callback = function() - vim.keymap.set("n", "", "Find") - vim.keymap.set("n", "/", [[lua require('vscode').action('workbench.action.findInFiles')]]) - vim.keymap.set("n", "ss", [[lua require('vscode').action('workbench.action.gotoSymbol')]]) + map("n", k.find, "Find") + map("n", k.find_in_files, [[lua require('vscode').action('workbench.action.findInFiles')]]) + map("n", k.go_to_symbol, [[lua require('vscode').action('workbench.action.gotoSymbol')]]) end, }) diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index ae32c0ef..41cf3b91 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -1,4 +1,5 @@ local M = {} +local k = require("lazyvim.keymaps").get_keymaps().formatting ---@param opts conform.setupOpts function M.setup(_, opts) @@ -25,7 +26,7 @@ return { cmd = "ConformInfo", keys = { { - "cF", + k.conform.format, function() require("conform").format({ formatters = { "injected" }, timeout_ms = 3000 }) end, diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 076344dd..4ab4119b 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -1,3 +1,4 @@ +local k = require("lazyvim.keymaps").get_keymaps().extras.lang return { -- lspconfig { @@ -263,7 +264,7 @@ return { "williamboman/mason.nvim", cmd = "Mason", - keys = { { "cm", "Mason", desc = "Mason" } }, + keys = { { k.mason, "Mason", desc = "Mason" } }, build = ":MasonUpdate", opts_extend = { "ensure_installed" }, opts = { diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 2a35dc97..78779f53 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -1,4 +1,5 @@ local M = {} +local k = require("lazyvim.keymaps").get_keymaps().extras.lang ---@type LazyKeysLspSpec[]|nil M._keys = nil @@ -11,32 +12,86 @@ function M.get() if M._keys then return M._keys end - -- stylua: ignore - M._keys = { - { "cl", "LspInfo", desc = "Lsp Info" }, - { "gd", vim.lsp.buf.definition, desc = "Goto Definition", has = "definition" }, - { "gr", vim.lsp.buf.references, desc = "References", nowait = true }, - { "gI", vim.lsp.buf.implementation, desc = "Goto Implementation" }, - { "gy", vim.lsp.buf.type_definition, desc = "Goto T[y]pe Definition" }, - { "gD", vim.lsp.buf.declaration, desc = "Goto Declaration" }, - { "K", vim.lsp.buf.hover, desc = "Hover" }, - { "gK", vim.lsp.buf.signature_help, desc = "Signature Help", has = "signatureHelp" }, - { "", vim.lsp.buf.signature_help, mode = "i", desc = "Signature Help", has = "signatureHelp" }, - { "ca", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" }, - { "cc", vim.lsp.codelens.run, desc = "Run Codelens", mode = { "n", "v" }, has = "codeLens" }, - { "cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" }, - { "cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = { "workspace/didRenameFiles", "workspace/willRenameFiles" } }, - { "cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" }, - { "cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" }, - { "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight", - desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end }, - { "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight", - desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end }, - { "", function() LazyVim.lsp.words.jump(vim.v.count1, true) end, has = "documentHighlight", - desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end }, - { "", function() LazyVim.lsp.words.jump(-vim.v.count1, true) end, has = "documentHighlight", - desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end }, - } + local actions = { + { k.lsp_info, "LspInfo", desc = "Lsp Info" }, + { k.go_to_definition, vim.lsp.buf.definition, desc = "Goto Definition", has = "definition" }, + { k.references, vim.lsp.buf.references, desc = "References", nowait = true }, + { k.go_to_implementation, vim.lsp.buf.implementation, desc = "Goto Implementation" }, + { k.go_to_type_definition, vim.lsp.buf.type_definition, desc = "Goto T[y]pe Definition" }, + { k.go_to_declaration, vim.lsp.buf.declaration, desc = "Goto Declaration" }, + { k.hover, vim.lsp.buf.hover, desc = "Hover" }, + { k.signature_help, vim.lsp.buf.signature_help, desc = "Signature Help", has = "signatureHelp" }, + { k.insert_signature_help, vim.lsp.buf.signature_help, mode = "i", desc = "Signature Help", has = "signatureHelp" }, + { k.code_action, vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" }, + { k.run_codelens, vim.lsp.codelens.run, desc = "Run Codelens", mode = { "n", "v" }, has = "codeLens" }, + { + k.refresh_codelens, + vim.lsp.codelens.refresh, + desc = "Refresh & Display Codelens", + mode = { "n" }, + has = "codeLens", + }, + { + k.rename_file, + LazyVim.lsp.rename_file, + desc = "Rename File", + mode = { "n" }, + has = { "workspace/didRenameFiles", "workspace/willRenameFiles" }, + }, + { k.rename, vim.lsp.buf.rename, desc = "Rename", has = "rename" }, + { k.source_action, LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" }, + { + k.next_reference, + function() + LazyVim.lsp.words.jump(vim.v.count1) + end, + has = "documentHighlight", + desc = "Next Reference", + cond = function() + return LazyVim.lsp.words.enabled + end, + }, + { + k.prev_reference, + function() + LazyVim.lsp.words.jump(-vim.v.count1) + end, + has = "documentHighlight", + desc = "Prev Reference", + cond = function() + return LazyVim.lsp.words.enabled + end, + }, + { + k.cycle_next_reference, + function() + LazyVim.lsp.words.jump(vim.v.count1, true) + end, + has = "documentHighlight", + desc = "Next Reference", + cond = function() + return LazyVim.lsp.words.enabled + end, + }, + { + k.cycle_prev_reference, + function() + LazyVim.lsp.words.jump(-vim.v.count1, true) + end, + has = "documentHighlight", + desc = "Prev Reference", + cond = function() + return LazyVim.lsp.words.enabled + end, + }, + } + M._keys = {} + + for _, action in ipairs(actions) do + if action[1] and action[1] ~= "" then + table.insert(M._keys, action) + end + end return M._keys end @@ -91,7 +146,7 @@ function M.on_attach(_, buffer) opts.has = nil opts.silent = opts.silent ~= false opts.buffer = buffer - vim.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts) + LazyVim.keymap_set(keys.mode or "n", keys.lhs, keys.rhs, opts) end end end diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index 0f0c8fe8..47ac8d71 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -1,10 +1,12 @@ +local k = require("lazyvim.keymaps").get_keymaps().treesitter + return { { "folke/which-key.nvim", opts = { spec = { - { "", desc = "Decrement Selection", mode = "x" }, - { "", desc = "Increment Selection", mode = { "x", "n" } }, + { k.decrement_selection, desc = "Decrement Selection", mode = "x" }, + { k.increment_selection, desc = "Increment Selection", mode = { "x", "n" } }, }, }, }, @@ -29,8 +31,8 @@ return { end, cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" }, keys = { - { "", desc = "Increment Selection" }, - { "", desc = "Decrement Selection", mode = "x" }, + { k.increment_selection, desc = "Increment Selection" }, + { k.decrement_selection, desc = "Decrement Selection", mode = "x" }, }, opts_extend = { "ensure_installed" }, ---@type TSConfig @@ -67,19 +69,35 @@ return { incremental_selection = { enable = true, keymaps = { - init_selection = "", - node_incremental = "", + init_selection = (k.increment_selection and k.increment_selection ~= "") and k.increment_selection or false, + node_incremental = (k.increment_selection and k.increment_selection ~= "") and k.increment_selection or false, scope_incremental = false, - node_decremental = "", + node_decremental = (k.decrement_selection and k.decrement_selection ~= "") and k.decrement_selection or false, }, }, textobjects = { move = { enable = true, - goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer", ["]a"] = "@parameter.inner" }, - goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer", ["]A"] = "@parameter.inner" }, - goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer", ["[a"] = "@parameter.inner" }, - goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer", ["[A"] = "@parameter.inner" }, + goto_next_start = { + [k.textobjects.goto_next_start.function_outer] = "@function.outer", + [k.textobjects.goto_next_start.class_outer] = "@class.outer", + [k.textobjects.goto_next_start.parameter_inner] = "@parameter.inner", + }, + goto_next_end = { + [k.textobjects.goto_next_end.function_outer] = "@function.outer", + [k.textobjects.goto_next_end.class_outer] = "@class.outer", + [k.textobjects.goto_next_end.parameter_inner] = "@parameter.inner", + }, + goto_previous_start = { + [k.textobjects.goto_previous_start.function_outer] = "@function.outer", + [k.textobjects.goto_previous_start.class_outer] = "@class.outer", + [k.textobjects.goto_previous_start.parameter_inner] = "@parameter.inner", + }, + goto_previous_end = { + [k.textobjects.goto_previous_end.function_outer] = "@function.outer", + [k.textobjects.goto_previous_end.class_outer] = "@class.outer", + [k.textobjects.goto_previous_end.parameter_inner] = "@parameter.inner", + }, }, }, }, diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 14807497..dfd04145 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -1,10 +1,12 @@ +local k = require("lazyvim.keymaps").get_keymaps().ui + return { -- Better `vim.notify()` { "rcarriga/nvim-notify", keys = { { - "un", + k.nvim_notify.dismiss_all_notifications, function() require("notify").dismiss({ silent = true, pending = true }) end, @@ -40,17 +42,29 @@ return { "akinsho/bufferline.nvim", event = "VeryLazy", keys = { - { "bp", "BufferLineTogglePin", desc = "Toggle Pin" }, - { "bP", "BufferLineGroupClose ungrouped", desc = "Delete Non-Pinned Buffers" }, - { "bo", "BufferLineCloseOthers", desc = "Delete Other Buffers" }, - { "br", "BufferLineCloseRight", desc = "Delete Buffers to the Right" }, - { "bl", "BufferLineCloseLeft", desc = "Delete Buffers to the Left" }, - { "", "BufferLineCyclePrev", desc = "Prev Buffer" }, - { "", "BufferLineCycleNext", desc = "Next Buffer" }, - { "[b", "BufferLineCyclePrev", desc = "Prev Buffer" }, - { "]b", "BufferLineCycleNext", desc = "Next Buffer" }, - { "[B", "BufferLineMovePrev", desc = "Move buffer prev" }, - { "]B", "BufferLineMoveNext", desc = "Move buffer next" }, + { k.bufferline.toggle_pin, "BufferLineTogglePin", desc = "Toggle Pin" }, + { + k.bufferline.delete_non_pinned_buffers, + "BufferLineGroupClose ungrouped", + desc = "Delete Non-Pinned Buffers", + }, + { k.bufferline.delete_other_buffers, "BufferLineCloseOthers", desc = "Delete Other Buffers" }, + { + k.bufferline.delete_buffers_to_the_right, + "BufferLineCloseRight", + desc = "Delete Buffers to the Right", + }, + { + k.bufferline.delete_buffers_to_the_left, + "BufferLineCloseLeft", + desc = "Delete Buffers to the Left", + }, + { k.bufferline.prev_buffer, "BufferLineCyclePrev", desc = "Prev Buffer" }, + { k.bufferline.next_buffer, "BufferLineCycleNext", desc = "Next Buffer" }, + { k.bufferline.prev_buffer_alt, "BufferLineCyclePrev", desc = "Prev Buffer" }, + { k.bufferline.next_buffer_alt, "BufferLineCycleNext", desc = "Next Buffer" }, + { k.bufferline.move_buffer_prev, "BufferLineMovePrev", desc = "Move buffer prev" }, + { k.bufferline.move_buffer_next, "BufferLineMoveNext", desc = "Move buffer next" }, }, opts = { options = { @@ -226,7 +240,7 @@ return { "lukas-reineke/indent-blankline.nvim", event = "LazyFile", opts = function() - LazyVim.toggle.map("ug", { + LazyVim.toggle.map(k.indent_blankline.toggle, { name = "Indention Guides", get = function() return require("ibl.config").get_config(0).enabled @@ -295,15 +309,15 @@ return { }, -- stylua: ignore keys = { - { "sn", "", desc = "+noice"}, - { "", function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" }, - { "snl", function() require("noice").cmd("last") end, desc = "Noice Last Message" }, - { "snh", function() require("noice").cmd("history") end, desc = "Noice History" }, - { "sna", function() require("noice").cmd("all") end, desc = "Noice All" }, - { "snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" }, - { "snt", function() require("noice").cmd("pick") end, desc = "Noice Picker (Telescope/FzfLua)" }, - { "", function() if not require("noice.lsp").scroll(4) then return "" end end, silent = true, expr = true, desc = "Scroll Forward", mode = {"i", "n", "s"} }, - { "", function() if not require("noice.lsp").scroll(-4) then return "" end end, silent = true, expr = true, desc = "Scroll Backward", mode = {"i", "n", "s"}}, + { k.noice.prefix, "", desc = "+noice"}, + { k.noice.redirect_cmdline, function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" }, + { k.noice.last_message, function() require("noice").cmd("last") end, desc = "Noice Last Message" }, + { k.noice.history, function() require("noice").cmd("history") end, desc = "Noice History" }, + { k.noice.all, function() require("noice").cmd("all") end, desc = "Noice All" }, + { k.noice.dismiss, function() require("noice").cmd("dismiss") end, desc = "Dismiss All" }, + { k.noice.pick, function() require("noice").cmd("pick") end, desc = "Noice Picker (Telescope/FzfLua)" }, + { k.noice.scroll_forward, function() if not require("noice.lsp").scroll(4) then return "" end end, silent = true, expr = true, desc = "Scroll Forward", mode = {"i", "n", "s"} }, + { k.noice.scroll_backward, function() if not require("noice.lsp").scroll(-4) then return "" end end, silent = true, expr = true, desc = "Scroll Backward", mode = {"i", "n", "s"}}, }, config = function(_, opts) -- HACK: noice shows messages from before it was enabled, @@ -355,6 +369,69 @@ return { logo = string.rep("\n", 8) .. logo .. "\n\n" + local actions = { + { + action = "lua LazyVim.pick()()", + desc = " Find File", + icon = " ", + key = k.dashboard.find_file, + }, + { + action = "ene | startinsert", + desc = " New File", + icon = " ", + key = k.dashboard.new_file, + }, + { + action = 'lua LazyVim.pick("oldfiles")()', + desc = " Recent Files", + icon = " ", + key = k.dashboard.recent_files, + }, + { + action = 'lua LazyVim.pick("live_grep")()', + desc = " Find Text", + icon = " ", + key = k.dashboard.find_text, + }, + { + action = "lua LazyVim.pick.config_files()()", + desc = " Config", + icon = " ", + key = k.dashboard.config, + }, + { + action = 'lua require("persistence").load()', + desc = " Restore Session", + icon = " ", + key = k.dashboard.restore_session, + }, + { + action = "LazyExtras", + desc = " Lazy Extras", + icon = " ", + key = k.dashboard.lazy_extras, + }, + { + action = "Lazy", + desc = " Lazy", + icon = "󰒲 ", + key = k.dashboard.lazy, + }, + { + action = function() + vim.api.nvim_input("qa") + end, + desc = " Quit", + icon = " ", + key = k.dashboard.quit, + }, + } + + actions = vim.tbl_filter(function(action) + return action.key and action.key ~= "" + end, actions) + local opts = { theme = "doom", hide = { @@ -365,17 +442,7 @@ return { config = { header = vim.split(logo, "\n"), -- stylua: ignore - center = { - { action = 'lua LazyVim.pick()()', desc = " Find File", icon = " ", key = "f" }, - { action = "ene | startinsert", desc = " New File", icon = " ", key = "n" }, - { action = 'lua LazyVim.pick("oldfiles")()', desc = " Recent Files", icon = " ", key = "r" }, - { action = 'lua LazyVim.pick("live_grep")()', desc = " Find Text", icon = " ", key = "g" }, - { action = 'lua LazyVim.pick.config_files()()', desc = " Config", icon = " ", key = "c" }, - { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, - { action = "LazyExtras", desc = " Lazy Extras", icon = " ", key = "x" }, - { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, - { action = function() vim.api.nvim_input("qa") end, desc = " Quit", icon = " ", key = "q" }, - }, + center = actions, footer = function() local stats = require("lazy").stats() local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) diff --git a/lua/lazyvim/plugins/util.lua b/lua/lazyvim/plugins/util.lua index 22a3e734..4a0f328c 100644 --- a/lua/lazyvim/plugins/util.lua +++ b/lua/lazyvim/plugins/util.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().util.persistence + return { -- Session management. This saves your session in the background, @@ -9,10 +11,10 @@ return { opts = {}, -- stylua: ignore keys = { - { "qs", function() require("persistence").load() end, desc = "Restore Session" }, - { "qS", function() require("persistence").select() end,desc = "Select Session" }, - { "ql", function() require("persistence").load({ last = true }) end, desc = "Restore Last Session" }, - { "qd", function() require("persistence").stop() end, desc = "Don't Save Current Session" }, + { k.restore_session, function() require("persistence").load() end, desc = "Restore Session" }, + { k.select_session, function() require("persistence").select() end,desc = "Select Session" }, + { k.restore_last_session, function() require("persistence").load({ last = true }) end, desc = "Restore Last Session" }, + { k.skip_current_session, function() require("persistence").stop() end, desc = "Don't Save Current Session" }, }, }, diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 106cbdc0..d4a2c2db 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -194,7 +194,7 @@ function M.on_load(name, fn) end end --- Wrapper around vim.keymap.set that will +-- Wrapper around LazyVim.keymap_set that will -- not create a keymap if a lazy key handler exists. -- It will also set `silent` to true by default. function M.safe_keymap_set(mode, lhs, rhs, opts) @@ -215,10 +215,21 @@ function M.safe_keymap_set(mode, lhs, rhs, opts) ---@diagnostic disable-next-line: no-unknown opts.remap = nil end - vim.keymap.set(modes, lhs, rhs, opts) + M.keymap_set(modes, lhs, rhs, opts) end end +-- Wrapper around vim.keymap.set that will +-- not create a keymap if lhs or rhs is empty. +-- This is useful in case `lhs` is dynamic +-- and users can set it to empty to disable the keymap. +function M.keymap_set(mode, lhs, rhs, opts) + if not lhs or lhs == "" or not rhs or rhs == "" then + return + end + vim.keymap.set(mode, lhs, rhs, opts) +end + ---@generic T ---@param list T[] ---@return T[] diff --git a/lua/lazyvim/util/mini.lua b/lua/lazyvim/util/mini.lua index e7320a73..fb79f3cb 100644 --- a/lua/lazyvim/util/mini.lua +++ b/lua/lazyvim/util/mini.lua @@ -1,3 +1,5 @@ +local k = require("lazyvim.keymaps").get_keymaps().util.mini_pairs + ---@class lazyvim.util.mini local M = {} @@ -121,7 +123,7 @@ end ---@param opts {skip_next: string, skip_ts: string[], skip_unbalanced: boolean, markdown: boolean} function M.pairs(opts) - LazyVim.toggle.map("up", { + LazyVim.toggle.map(k.toggle, { name = "Mini Pairs", get = function() return not vim.g.minipairs_disable