diff --git a/lua/config/init.lua b/lua/config/init.lua index e36d339..dba6f48 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -65,7 +65,6 @@ vim.opt.cursorline = true -- Show which line your cursor is on vim.opt.scrolloff = 4 -- Minimal number of screen lines to keep above and below the cursor. -- Set highlight on search, but clear on pressing in normal mode vim.opt.hlsearch = true -vim.keymap.set("n", "", "nohlsearch") -- Highlight when yanking (copying) text vim.api.nvim_create_autocmd("TextYankPost", { diff --git a/lua/config/keys.lua b/lua/config/keys.lua index fac9c42..5e76317 100644 --- a/lua/config/keys.lua +++ b/lua/config/keys.lua @@ -81,6 +81,25 @@ return { expr = true, }, }, + globals = { + -- Window Navigation + { "", "h", desc = "Window Left" }, + { "", "j", desc = "Window Down" }, + { "", "k", desc = "Window Up" }, + { "", "l", desc = "Window Right" }, + -- Window Resizing + { "", "+", desc = "Resize Increase Height" }, + { "", "-", desc = "Resize Decrease Height" }, + { "", ">", desc = "Resize Increase Width" }, + { "", "<", desc = "Resize Decrease Width" }, + -- Splits + { "", "s", desc = "Split Window Horizontal" }, + { "", "x", desc = "Swap Window" }, + { "", ":q", desc = "Close Window" }, + -- Misc + { "", "nohlsearch", desc = "Clear Highlight" }, + { "d", vim.diagnostic.open_float, desc = "[D]iagnostics" }, + }, harpoon = { { "ha", @@ -158,6 +177,48 @@ return { mode = "n", }, }, + lsp = { + { + "gd", + function() require("telescope.builtin").lsp_definitions() end, + desc = "[G]oto [D]efinition" + }, + { + "gr", + function() require("telescope.builtin").lsp_references() end, + desc = "[G]oto [R]eferences" + }, + { + "gI", + function() require("telescope.builtin").lsp_implementations() end, + desc = "[G]oto [I]mplementation" + }, + { + "D", + function() require("telescope.builtin").lsp_type_definitions() end, + desc = "Type [D]efinition" + }, + { + "ds", + function() require("telescope.builtin").lsp_document_symbols() end, + desc = "Document [S]ymbols" + }, + { + "ws", + function() require("telescope.builtin").lsp_dynamic_workspace_symbols() end, + desc = "[W]orkspace [S]ymbols" + }, + { "rn", vim.lsp.buf.rename, desc = "[R]e[n]ame" }, + { "ca", vim.lsp.buf.code_action, desc = "[C]ode [A]ction" }, + { "K", vim.lsp.buf.hover, desc = "Hover Documentation" }, + { "gD", vim.lsp.buf.declaration, desc = "[G]oto [D]eclaration" }, + { "f", vim.lsp.buf.format, desc = "[F]ormat" }, + { + "ci", + function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) end, + desc = "[I]nlay Hints" + }, + }, neogen = { { "gd", @@ -437,4 +498,7 @@ return { desc = "Toggle Rainbow Delimiters" }, }, + undotree = { + { "U", vim.cmd.UndotreeToggle, desc = "[U]ndotree" }, + }, } diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 6b52b41..bd8dc85 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -1,27 +1,9 @@ -vim.keymap.set("n", "", "h", { noremap = true, silent = true }) -vim.keymap.set("n", "", "j", { noremap = true, silent = true }) -vim.keymap.set("n", "", "k", { noremap = true, silent = true }) -vim.keymap.set("n", "", "l", { noremap = true, silent = true }) -vim.keymap.set("n", "", "h", { noremap = true, silent = true }) -vim.keymap.set("n", "", "j", { noremap = true, silent = true }) -vim.keymap.set("n", "", "k", { noremap = true, silent = true }) -vim.keymap.set("n", "", "l", { noremap = true, silent = true }) -vim.keymap.set("n", "", "+", { noremap = true, silent = true }) -vim.keymap.set("n", "", "-", { noremap = true, silent = true }) -vim.keymap.set("n", "", ">", { noremap = true, silent = true }) -vim.keymap.set("n", "", "<", { noremap = true, silent = true }) -vim.keymap.set("n", "", "s", { noremap = true, silent = true }) --- This keymap isn't ideal but its the best i can figure out right now -vim.keymap.set("n", "", "x", { noremap = true, silent = true }) -vim.keymap.set("n", "", ":q", { noremap = true, silent = true }) --- Non standard key mappings are here -vim.keymap.set("n", "d", vim.diagnostic.open_float, { desc = "[D]iagnostics" }) -vim.keymap.set("n", "f", vim.lsp.buf.format, { desc = "[F]ormat" }) -vim.keymap.set( - "n", - "ci", - function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) - end, - { desc = "[I]nlay Hints" } -) +local keys = require("config.keys").globals + +for _, map in ipairs(keys) do + vim.keymap.set("n", map[1], map[2], { + noremap = true, + silent = true, + desc = map.desc + }) +end diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index aca6a5e..f07c64a 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -11,19 +11,13 @@ return { vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }), callback = function(event) - local map = function(keys, func, desc) - vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + local lsp_keys = require("config.keys").lsp + for _, map in ipairs(lsp_keys) do + vim.keymap.set("n", map[1], map[2], { + buffer = event.buf, + desc = "LSP: " .. map.desc + }) end - map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") - map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") - map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") - map("D", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") - map("ds", require("telescope.builtin").lsp_document_symbols, "Document [S]ymbols") - map("ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols") - map("rn", vim.lsp.buf.rename, "[R]e[n]ame") - map("ca", vim.lsp.buf.code_action, "[C]ode [A]ction") - map("K", vim.lsp.buf.hover, "Hover Documentation") - map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client.server_capabilities.documentHighlightProvider then diff --git a/lua/plugins/utils.lua b/lua/plugins/utils.lua index 34bbb42..0603de9 100644 --- a/lua/plugins/utils.lua +++ b/lua/plugins/utils.lua @@ -134,10 +134,7 @@ return { -- General programming utilities go here { -- Undo tree "mbbill/undotree", event = "VeryLazy", - opts = {}, - config = function() - vim.keymap.set("n", "U", vim.cmd.UndotreeToggle, { desc = "[U]ndotree" }) - end, + keys = require("config.keys").undotree, }, { -- Add Overseer as a task running tool "stevearc/overseer.nvim",