-- This file is automatically loaded by lazyvim.config.init -- DO NOT USE `LazyVim.safe_keymap_set` IN YOUR OWN CONFIG!! -- use `vim.keymap.set` instead local map = LazyVim.safe_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", "", "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 }) -- 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" }) -- 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" }) -- 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", function() Snacks.bufdelete() end, { desc = "Delete Buffer" }) map("n", "bo", function() Snacks.bufdelete.other() end, { desc = "Delete Other Buffers" }) map("n", "bD", ":bd", { desc = "Delete Buffer and Window" }) -- 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" } ) -- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n map("n", "n", "'Nn'[v:searchforward].'zv'", { expr = true, desc = "Next Search Result" }) map("x", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next Search Result" }) map("o", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next Search Result" }) map("n", "N", "'nN'[v:searchforward].'zv'", { expr = true, desc = "Prev Search Result" }) map("x", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev Search Result" }) map("o", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev Search Result" }) -- Add undo break-points map("i", ",", ",u") map("i", ".", ".u") map("i", ";", ";u") -- save file map({ "i", "x", "n", "s" }, "", "w", { desc = "Save File" }) --keywordprg map("n", "K", "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" }) -- lazy map("n", "l", "Lazy", { desc = "Lazy" }) -- new file map("n", "fn", "enew", { desc = "New File" }) map("n", "xl", "lopen", { desc = "Location List" }) map("n", "xq", "copen", { desc = "Quickfix List" }) map("n", "[q", vim.cmd.cprev, { desc = "Previous Quickfix" }) map("n", "]q", vim.cmd.cnext, { desc = "Next Quickfix" }) -- formatting map({ "n", "v" }, "cf", function() LazyVim.format({ force = true }) end, { desc = "Format" }) -- 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" }) -- stylua: ignore start -- toggle options LazyVim.format.snacks_toggle():map("uf") LazyVim.format.snacks_toggle(true):map("uF") 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}):map("uc") Snacks.toggle.treesitter():map("uT") Snacks.toggle.option("background", { off = "light", on = "dark" , name = "Dark Background"}):map("ub") if vim.lsp.inlay_hint then Snacks.toggle.inlay_hints():map("uh") end -- lazygit if vim.fn.executable("lazygit") == 1 then map("n", "gg", function() Snacks.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) map("n", "gG", function() Snacks.lazygit() end, { desc = "Lazygit (cwd)" }) map("n", "gf", function() Snacks.lazygit.log_file() end, { desc = "Lazygit Current File History" }) map("n", "gl", function() Snacks.lazygit.log({ cwd = LazyVim.root.git() }) end, { desc = "Lazygit Log" }) map("n", "gL", function() Snacks.lazygit.log() end, { desc = "Lazygit Log (cwd)" }) end map("n", "gb", function() Snacks.git.blame_line() end, { desc = "Git Blame Line" }) map({ "n", "x" }, "gB", function() Snacks.gitbrowse() end, { desc = "Git Browse" }) -- quit map("n", "qq", "qa", { desc = "Quit All" }) -- highlights under cursor map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) map("n", "uI", "InspectTree", { desc = "Inspect Tree" }) -- LazyVim Changelog map("n", "L", function() LazyVim.news.changelog() end, { desc = "LazyVim Changelog" }) -- floating terminal map("n", "fT", function() Snacks.terminal() end, { desc = "Terminal (cwd)" }) map("n", "ft", function() Snacks.terminal(nil, { cwd = LazyVim.root() }) end, { desc = "Terminal (Root Dir)" }) map("n", "", function() Snacks.terminal(nil, { cwd = LazyVim.root() }) end, { desc = "Terminal (Root Dir)" }) map("n", "", function() Snacks.terminal(nil, { cwd = LazyVim.root() }) end, { desc = "which_key_ignore" }) -- Terminal Mappings map("t", "", "close", { desc = "Hide Terminal" }) map("t", "", "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.ui.maximize():map("wm") -- 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" }) -- native snippets. only needed on < 0.11, as 0.11 creates these by default if vim.fn.has("nvim-0.11") == 0 then map("s", "", function() return vim.snippet.active({ direction = 1 }) and "lua vim.snippet.jump(1)" or "" end, { expr = true, desc = "Jump Next" }) map({ "i", "s" }, "", function() return vim.snippet.active({ direction = -1 }) and "lua vim.snippet.jump(-1)" or "" end, { expr = true, desc = "Jump Previous" }) end