From 406c5b5dbc7d49e384f73ffc9ca11b874bb8af33 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sat, 17 Sep 2022 17:18:37 -0500 Subject: [PATCH] refactor(nvim): major keybindings overhaul --- .../primary/config/lua/plugins/mappings.lua | 220 +++++++++++------- 1 file changed, 132 insertions(+), 88 deletions(-) diff --git a/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua b/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua index 5e37ae07..af187a6b 100755 --- a/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua +++ b/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua @@ -5,111 +5,156 @@ if not loaded then end -- Telescope mappings -vim.keymap.set("n", "tw", ":Telescope live_grep") -vim.keymap.set("n", "tgs", ":Telescope git_status") -vim.keymap.set("n", "tgc", ":Telescope git_commits") -vim.keymap.set("n", "tgb", ":Telescope git_branches") -vim.keymap.set("n", "tf", ":Telescope find_files") -vim.keymap.set("n", "td", ":Telescope find_directories") -vim.keymap.set("n", "tb", ":Telescope buffers") -vim.keymap.set("n", "th", ":Telescope help_tags") -vim.keymap.set("n", "to", ":Telescope oldfiles") -vim.keymap.set("n", "tc", ":Telescope neoclip default") -vim.keymap.set("n", "tr", ":Telescope registers") -vim.keymap.set("n", "tt", ":Telescope file_browser") -vim.keymap.set("n", "ts", ":Telescope spell_suggest") -vim.keymap.set("n", "tl", ":Telescope resume") -vim.keymap.set("n", "tT", ":TodoTelescope") +vim.keymap.set("n", "tw", ":Telescope live_grep", { silent = true, desc = "Telescope: Grep for Word" }) +vim.keymap.set("n", "tgs", ":Telescope git_status", { silent = true, desc = "Telescope: Git Status" }) +vim.keymap.set("n", "tgc", ":Telescope git_commits", { silent = true, desc = "Telescope: Git Commits" }) +vim.keymap.set("n", "tgb", ":Telescope git_branches", { silent = true, desc = "Telescope: Git Branches" }) +vim.keymap.set("n", "tf", ":Telescope find_files", { silent = true, desc = "Telescope: Find Files" }) +vim.keymap.set( + "n", + "td", + ":Telescope find_directories", + { silent = true, desc = "Telescope: Find Directories" } +) +vim.keymap.set("n", "tb", ":Telescope buffers", { silent = true, desc = "Telescope: Buffers" }) +vim.keymap.set("n", "th", ":Telescope help_tags", { silent = true, desc = "Telescope: Help Tags" }) +vim.keymap.set("n", "to", ":Telescope oldfiles", { silent = true, desc = "Telescope: Recent Files" }) +vim.keymap.set( + "n", + "tn", + ":Telescope neoclip default", + { silent = true, desc = "Telescope: Neoclip Buffer" } +) +vim.keymap.set("n", "tr", ":Telescope registers", { silent = true, desc = "Telescope: Registers" }) +vim.keymap.set("n", "tt", ":Telescope file_browser", { silent = true, desc = "Telescope: File Tree" }) +vim.keymap.set("n", "ts", ":Telescope spell_suggest", { silent = true, desc = "Telescope: Spell Suggest" }) +vim.keymap.set("n", "tl", ":Telescope resume", { silent = true, desc = "Telescope: Previous State" }) +vim.keymap.set("n", "tT", ":TodoTelescope", { silent = true, desc = "Telescope: Todo Items" }) +vim.keymap.set("n", "tk", ":Telescope keymaps", { silent = true, desc = "Telescope: Keymaps" }) +vim.keymap.set("n", "tc", ":Telescope commands", { silent = true, desc = "Telescope: Commands" }) -- Lsp Mappings -vim.keymap.set("n", "lD", ":lua vim.lsp.buf.declaration()") -vim.keymap.set("n", "ld", ":lua vim.lsp.buf.definition()") -vim.keymap.set("n", "k", ":lua vim.lsp.buf.hover()") -vim.keymap.set("n", "K", ":lua vim.lsp.buf.signature_help()") -vim.keymap.set("n", "li", ":lua vim.lsp.buf.implementation()") -vim.keymap.set("n", "la", ":lua vim.lsp.buf.add_workspace_folder()") -vim.keymap.set("n", "lx", ":lua vim.lsp.buf.remove_workspace_folder()") -vim.keymap.set("n", "ll", ":lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))") -vim.keymap.set("n", "ln", ":IncRename ") -vim.keymap.set("n", "lc", ":lua vim.lsp.buf.code_action()") -vim.keymap.set("n", "lr", ":lua vim.lsp.buf.references()") -vim.keymap.set("n", "lR", ":LspRestart") -vim.keymap.set("n", "ls", ":lua vim.diagnostic.open_float(nil, {focus=false, scope='cursor'})") -vim.keymap.set("n", "lf", ":lua vim.lsp.buf.format({ async = true })") -vim.keymap.set("n", "[l", ":lua vim.diagnostic.goto_prev()") -vim.keymap.set("n", "]l", ":lua vim.diagnostic.goto_next()") -vim.keymap.set("n", "lq", ":Telescope diagnostics bufnr=0") +vim.keymap.set("n", "lD", vim.lsp.buf.declaration, { silent = true, desc = "LSP: Declaration" }) +vim.keymap.set("n", "ld", vim.lsp.buf.definition, { silent = true, desc = "LSP: Definition" }) +vim.keymap.set("n", "k", vim.lsp.buf.hover, { silent = true, desc = "LSP: Hover" }) +vim.keymap.set("n", "K", vim.lsp.buf.signature_help, { silent = true, desc = "LSP: Sig Help" }) +vim.keymap.set("n", "li", vim.lsp.buf.implementation, { silent = true, desc = "LSP: Implementation" }) +vim.keymap.set( + "n", + "la", + vim.lsp.buf.add_workspace_folder, + { silent = true, desc = "LSP: Add Workspace Folder" } +) +vim.keymap.set( + "n", + "lx", + vim.lsp.buf.remove_workspace_folder, + { silent = true, desc = "LSP: Remove Workspace Folder" } +) +vim.keymap.set("n", "ll", function() + local output_workspaces = "" + for _, workspace in ipairs(vim.lsp.buf.list_workspace_folders()) do + output_workspaces = string.format("%s- %s\n", output_workspaces, vim.inspect(workspace):gsub('%"', "")) + end + vim.notify(output_workspaces:gsub("\n[^\n]*$", ""), "info", { title = "LSP: Workspaces" }) +end, { silent = true, desc = "LSP: List Workspaces" }) +vim.keymap.set("n", "ln", function() end, { silent = true }) +vim.keymap.set("n", "ln", ":IncRename ", { desc = "LSP: Rename" }) +vim.keymap.set("n", "lc", vim.lsp.buf.code_action, { silent = true, desc = "LSP: Code Action" }) +vim.keymap.set("n", "lr", vim.lsp.buf.references, { silent = true, desc = "LSP: References" }) +vim.keymap.set("n", "lR", ":LspRestart", { silent = true, desc = "LSP: Restart" }) +vim.keymap.set("n", "ls", function() + vim.diagnostic.open_float(nil, { focus = false, scope = "cursor" }) +end, { silent = true, desc = "LSP: Diagnostic Open Float" }) +vim.keymap.set("n", "lf", function() + vim.lsp.buf.format({ async = true }) +end, { silent = true, desc = "LSP: Format" }) +vim.keymap.set("n", "[l", vim.diagnostic.goto_prev, { silent = true, desc = "LSP: Diagnostic Previous" }) +vim.keymap.set("n", "]l", vim.diagnostic.goto_next, { silent = true, desc = "LSP: Diagnostic Next" }) +vim.keymap.set( + "n", + "lq", + ":Telescope diagnostics bufnr=0", + { silent = true, desc = "LSP: Telescope Diagnostics" } +) vim.keymap.set("n", "lt", function() local virtual_lines_enabled = not vim.diagnostic.config().virtual_lines vim.diagnostic.config({ virtual_lines = virtual_lines_enabled, virtual_text = not virtual_lines_enabled }) end, { - desc = "Toggle LSP Diag Style", + desc = "LSP: Toggle Diagnostic Style", }) --- Trouble mappings -vim.keymap.set("n", "lT", ":TroubleToggle") - -- Formatter -vim.keymap.set("n", "nf", ":Neoformat") +vim.keymap.set("n", "nf", ":Neoformat", { silent = true, desc = "Neoformat" }) -- DAP Mappings -vim.keymap.set("n", "dR", ':lua require("dap").continue()') -vim.keymap.set("n", "de", ':lua require("dap").terminate()') -vim.keymap.set("n", "db", ':lua require("dap").toggle_breakpoint()') -vim.keymap.set("n", "dr", ":lua require(\"dap\").set_breakpoint(vim.fn.input('Breakpoint condition: '))") -vim.keymap.set( - "n", - "dp", - ":lua require(\"dap\").set_breakpoint(nil, nil, vim.fn.input('Log point message: '))" -) -vim.keymap.set("n", "", ':lua require("dap").step_over()') -vim.keymap.set("n", "", ':lua require("dap").step_into()') -vim.keymap.set("n", "", ':lua require("dap").step_out()') -vim.keymap.set("n", "dB", ':lua require("dap").step_back()') -vim.keymap.set("n", "dc", ':lua require("dap").run_to_cursor()') -vim.keymap.set("n", "do", ':lua require("dap").repl.open()') -vim.keymap.set("n", "dt", ':lua require("dapui").toggle()') -vim.keymap.set("n", "dl", ':lua require("dap").run_last()') +local dap = require("dap") +vim.keymap.set("n", "dc", dap.continue, { silent = true, desc = "DAP: Continue" }) +vim.keymap.set("n", "de", dap.terminate, { silent = true, desc = "DAP: Terminate" }) +vim.keymap.set("n", "db", dap.toggle_breakpoint, { silent = true, desc = "DAP: Toggle Breakpoint" }) +vim.keymap.set("n", "dr", function() + dap.set_breakpoint(vim.fn.input("Breakpoint Condition: ")) +end, { silent = true, desc = "DAP: Set Conditional Breakpoint" }) + +vim.keymap.set("n", "dp", function() + dap.set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) +end, { silent = true, desc = "DAP: Set Log Breakpoint" }) +vim.keymap.set("n", "", dap.step_over, { silent = true, desc = "DAP: Step Over" }) +vim.keymap.set("n", "", dap.step_into, { silent = true, desc = "DAP: Step Into" }) +vim.keymap.set("n", "", dap.step_out, { silent = true, desc = "DAP: Step Out" }) +vim.keymap.set("n", "", dap.step_back, { silent = true, desc = "DAP: Step Back" }) +vim.keymap.set("n", "dR", dap.run_to_cursor, { silent = true, desc = "DAP: Run to Cursor" }) +vim.keymap.set("n", "do", dap.repl.open, { silent = true, desc = "DAP: Open Repl" }) +vim.keymap.set("n", "dt", require("dapui").toggle, { silent = true, desc = "DAP: Toggle UI" }) +vim.keymap.set("n", "dl", dap.run_last, { silent = true, desc = "DAP: Run Last" }) -- Comments -vim.keymap.set("n", "/", ":CommentToggle") -vim.keymap.set("v", "/", ":'<,'>CommentToggle") +vim.keymap.set("n", "/", ":CommentToggle", { silent = true, desc = "Toggle Comment" }) +vim.keymap.set("v", "/", ":'<,'>CommentToggle", { silent = true, desc = "Toggle Selection Comment" }) -- Bufferline mappings -vim.keymap.set("n", "", ":BufferLineCyclePrev") -vim.keymap.set("n", "", ":BufferLineCycleNext") -vim.keymap.set("n", "", ":lua require('utils.funcs').close_buffer()") +vim.keymap.set("n", "", ":BufferLineCyclePrev", { silent = true, desc = "Go to Previous Buffer" }) +vim.keymap.set("n", "", ":BufferLineCycleNext", { silent = true, desc = "Go to Next Buffer" }) +vim.keymap.set("n", "", require("utils.funcs").close_buffer, { silent = true, desc = "Close Buffer" }) -- Vim Notify Mappings -vim.keymap.set("n", "nv", ":lua require('telescope').extensions.notify.notify()") -vim.keymap.set("n", "nd", ":lua require('notify').dismiss()") +vim.keymap.set( + "n", + "nv", + require("telescope").extensions.notify.notify, + { silent = true, desc = "Notifications: Search" } +) +vim.keymap.set("n", "nd", require("notify").dismiss, { silent = true, desc = "Notifications: Dismiss" }) -- Whichkey Mappings -vim.keymap.set("n", "ww", ":WhichKey") -vim.keymap.set("n", "wk", ":Telescope keymaps") -vim.keymap.set("n", "wc", ":Telescope commands") +vim.keymap.set("n", "ww", ":WhichKey", { silent = true, desc = "Show Keybinds" }) -- Neogen Mappings -vim.keymap.set("n", "ng", ":Neogen") +vim.keymap.set("n", "ngf", ":Neogen func", { silent = true, desc = "Neogen: Function Annotation" }) +vim.keymap.set("n", "ngc", ":Neogen class", { silent = true, desc = "Neogen: Class Annotation" }) +vim.keymap.set("n", "ngt", ":Neogen type", { silent = true, desc = "Neogen: Type Annotation" }) +vim.keymap.set("n", "ngb", ":Neogen file", { silent = true, desc = "Neogen: File Annotation" }) -- Nvim Tree Mappings -vim.keymap.set("n", "nt", ":Neotree show toggle focus") +vim.keymap.set("n", "nt", ":Neotree show toggle focus", { silent = true, desc = "Neotree: Toggle" }) -- Plenary Mappings -vim.keymap.set("n", "pt", "PlenaryTestFile", {}) - --- Zenmode Mappings -vim.keymap.set("n", "zm", ":ZenMode") +vim.keymap.set("n", "pt", "PlenaryTestFile", { silent = true, desc = "Plenary: Test File" }) -- Neogit Mappings -vim.keymap.set("n", "gg", ":Neogit") +vim.keymap.set("n", "gg", ":Neogit", { silent = true, desc = "Neogit: Open" }) -- Gitsigns Mappings -vim.keymap.set("n", "]g", "Gitsigns next_hunk") -vim.keymap.set("n", "[g", "Gitsigns prev_hunk") -vim.keymap.set("n", "gs", "Gitsigns stage_hunk") -vim.keymap.set("n", "gr", "Gitsigns reset_hunk") -vim.keymap.set("n", "gu", "Gitsigns undo_stage_hunk") +vim.keymap.set("n", "]g", "Gitsigns next_hunk", { silent = true, desc = "Gitsigns: Next Hunk" }) +vim.keymap.set("n", "[g", "Gitsigns prev_hunk", { silent = true, desc = "Gitsigns: Prev Hunk" }) +vim.keymap.set("n", "gs", "Gitsigns stage_hunk", { silent = true, desc = "Gitsigns: Stage Hunk" }) +vim.keymap.set("n", "gr", "Gitsigns reset_hunk", { silent = true, desc = "Gitsigns: Reset Hunk" }) +vim.keymap.set( + "n", + "gu", + "Gitsigns undo_stage_hunk", + { silent = true, desc = "Gitsigns: Unstage Hunk" } +) -- Packer Mappings local packer = require("packer") @@ -130,16 +175,15 @@ local packer_compile = function() end vim.keymap.set("n", "ps", packer_sync, { - desc = "PackerSync", + silent = true, + desc = "Packer: Sync", }) vim.keymap.set("n", "pc", packer_compile, { - desc = "PackerCompile", + silent = true, + desc = "Packer: Compile", }) --- Mundo mappings -vim.keymap.set("n", "ut", ":MundoToggle") - -- Hop Mappings local hop = require("hop") @@ -147,14 +191,14 @@ vim.keymap.set("", "f", function() hop.hint_char1({ current_line_only = false, }) -end) +end, { silent = true, desc = "Hop: Character" }) -- Hop Bindings -vim.keymap.set("", ";l", "HopLineStart") -vim.keymap.set("", ";s", "HopPattern") -vim.keymap.set("", ";;", "HopWord") -vim.keymap.set("", ";a", "HopAnywhere") -vim.keymap.set("", ";v", "HopVertical") +vim.keymap.set("", ";l", "HopLineStart", { silent = true, desc = "Hop: Line Start" }) +vim.keymap.set("", ";s", "HopPattern", { silent = true, desc = "Hop: Pattern" }) +vim.keymap.set("", ";;", "HopWord", { silent = true, desc = "Hop: Word" }) +vim.keymap.set("", ";a", "HopAnywhere", { silent = true, desc = "Hop: Anywhere" }) +vim.keymap.set("", ";v", "HopVertical", { silent = true, desc = "Hop Vertical" }) -- Term/Open bindings -vim.keymap.set("n", "", "ToggleTerm") +vim.keymap.set("n", "", "ToggleTerm", { silent = true, desc = "Toggle Terminal" })