-- Keymaps are automatically loaded on the VeryLazy event local Util = require("lazyvim.util") local function map(mode, lhs, rhs, opts) local keys = require("lazy.core.handler").handlers.keys ---@cast keys LazyKeysHandler -- do not create the keymap if a lazy keys handler exists if not keys.active[keys.parse({ lhs, mode = mode }).id] then opts = opts or {} opts.silent = opts.silent ~= false vim.keymap.set(mode, lhs, rhs, opts) end end -- 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 map("n", "", "m .+1==", { desc = "Move down" }) map("n", "", "m .-2==", { desc = "Move up" }) map("i", "", "m .+1==gi", { desc = "Move down" }) map("i", "", "m .-2==gi", { desc = "Move up" }) map("v", "", ":m '>+1gv=gv", { desc = "Move down" }) map("v", "", ":m '<-2gv=gv", { desc = "Move up" }) -- buffers if Util.has("bufferline.nvim") then 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" }) else 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" }) end map("n", "bb", "e #", { desc = "Switch to Other Buffer" }) map("n", "`", "e #", { desc = "Switch to Other Buffer" }) -- Clear search with map({ "i", "n" }, "", "noh", { 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") -- lazy map("n", "l", ":Lazy", { desc = "Lazy" }) -- new file map("n", "fn", "enew", { desc = "New File" }) if not Util.has("trouble.nvim") then map("n", "[q", vim.cmd.cprev, { desc = "Previous quickfix" }) map("n", "]q", vim.cmd.cnext, { desc = "Next quickfix" }) end -- stylua: ignore start -- toggle options map("n", "uf", Util.format.toggle, { desc = "Toggle format on Save" }) map("n", "ud", Util.toggle.diagnostics, { desc = "Toggle Diagnostics" }) local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 map("n", "uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" }) -- highlights under cursor if vim.fn.has("nvim-0.9.0") == 1 then map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) end -- floating terminal -- TODO: I prefer a split buffer for terminal, need to review how to make this more vim-like map("n", "ft", function() Util.float_term(nil, { cwd = Util.get_root() }) end, { desc = "Terminal (root dir)" }) map("n", "fT", function() Util.float_term() end, { desc = "Terminal (cwd)" }) map("t", "", "", {desc = "Enter Normal Mode"})