-- Keymaps are automatically loaded on the VeryLazy event local map = vim.keymap.set -- better up/down map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { desc = "Down", expr = true, silent = true }) map({ "n", "x" }, "", "v:count == 0 ? 'gj' : 'j'", { desc = "Down", expr = true, silent = true }) map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { desc = "Up", expr = true, silent = true }) map({ "n", "x" }, "", "v:count == 0 ? 'gk' : 'k'", { desc = "Up", expr = true, silent = true }) -- Move to window using the hjkl keys map("n", "", "W", { desc = "Go to Prev Window", remap = true }) map("n", "", "w", { desc = "Go to Next Window", remap = true }) map("n", "", "j", { desc = "Go to Lower Window", remap = true }) map("n", "", "k", { desc = "Go to Upper Window", remap = true }) -- Resize window using arrow keys -- TODO: this is cool, but should also support a number 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" }) -- Move Lines -- NOTE: these trigger with when I'm too quick at doing "go to normal mode then move line" 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" }) -- buffers map("n", "", "BufferLineCyclePrev", { desc = "Prev Buffer" }) map("n", "", "BufferLineCycleNext", { desc = "Next Buffer" }) map("n", "[b", "BufferLineCyclePrev", { desc = "Prev Buffer" }) map("n", "]b", "BufferLineCycleNext", { desc = "Next Buffer" }) map("n", "bb", "e #", { desc = "Switch to Other Buffer" }) -- Clear search and stop snippet on escape map({ "i", "n", "s" }, "", function() vim.cmd("noh") -- TODO: stop snippet with esc *but don't do it in insert mode* -- require("luasnip").unlink_current() return "" end, { expr = true, desc = "Escape and Clear hlsearch" }) -- Clear search, diff update and redraw -- taken from runtime/lua/_editor.lua map( "n", "ur", "nohlsearchdiffupdatenormal! ", { desc = "Redraw / Clear hlsearch / Diff Update" } ) map({ "n", "x" }, "gw", "*N", { desc = "Search word under cursor" }) -- Add undo break-points map("i", ",", ",u") map("i", ".", ".u") map("i", ";", ";u") --keywordprg map("n", "K", "norm! K", { desc = "Keywordprg" }) -- lazy map("n", "l", "Lazy", { desc = "Lazy" }) -- new file map("n", "fn", "enew", { desc = "New File" }) -- diagnostic local diagnostic_goto = function(next, severity) local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev severity = severity and vim.diagnostic.severity[severity] or nil return function() 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" }) -- toggle options Snacks.toggle.option("spell", { name = "Spelling" }):map("us") Snacks.toggle.option("wrap", { name = "Wrap" }):map("uw") Snacks.toggle.option("relativenumber", { name = "Relative Number" }):map("uL") Snacks.toggle.diagnostics():map("ud") Snacks.toggle.line_number():map("ul") Snacks.toggle.option("conceallevel", { off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2, name = "Conceal Level" }):map("uc") Snacks.toggle.option("showtabline", { off = 0, on = vim.o.showtabline > 0 and vim.o.showtabline or 2, name = "Tabline" }):map("uA") Snacks.toggle.treesitter():map("uT") Snacks.toggle.option("background", { off = "light", on = "dark" , name = "Dark Background" }):map("ub") Snacks.toggle.dim():map("uD") Snacks.toggle.animate():map("ua") Snacks.toggle.indent():map("ug") Snacks.toggle.scroll():map("uS") Snacks.toggle.profiler():map("dpp") Snacks.toggle.profiler_highlights():map("dph") if vim.lsp.inlay_hint then Snacks.toggle.inlay_hints():map("uh") end map({ "n", "x" }, "gB", function() Snacks.gitbrowse() end, { desc = "Git Browse (open)" }) map({"n", "x" }, "gY", function() Snacks.gitbrowse({ open = function(url) vim.fn.setreg("+", url) end, notify = false }) end, { desc = "Git Browse (copy)" }) -- highlights under cursor map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) map("n", "uI", "InspectTree", { desc = "Inspect Tree" }) -- floating terminal -- TODO: I prefer a split buffer for terminal, need to review how to make this more vim-like map("n", "", function() Snacks.terminal() end, { desc = "Terminal (cmd)" }) -- Terminal Mappings map("t", "", "", { desc = "Enter Normal Mode" }) map("t", "", "close", { desc = "Hide Terminal" })