-- 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", "", "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 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", LazyVim.ui.bufremove, { desc = "Delete Buffer" }) 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 map("n", "uf", function() LazyVim.format.toggle() end, { desc = "Toggle Auto Format (Global)" }) map("n", "uF", function() LazyVim.format.toggle(true) end, { desc = "Toggle Auto Format (Buffer)" }) map("n", "us", function() LazyVim.toggle("spell") end, { desc = "Toggle Spelling" }) map("n", "uw", function() LazyVim.toggle("wrap") end, { desc = "Toggle Word Wrap" }) map("n", "uL", function() LazyVim.toggle("relativenumber") end, { desc = "Toggle Relative Line Numbers" }) map("n", "ul", function() LazyVim.toggle.number() end, { desc = "Toggle Line Numbers" }) map("n", "ud", function() LazyVim.toggle.diagnostics() end, { desc = "Toggle Diagnostics" }) local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 map("n", "uc", function() LazyVim.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" }) if vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint then map( "n", "uh", function() LazyVim.toggle.inlay_hints() end, { desc = "Toggle Inlay Hints" }) end map("n", "uT", function() if vim.b.ts_highlight then vim.treesitter.stop() else vim.treesitter.start() end end, { desc = "Toggle Treesitter Highlight" }) map("n", "ub", function() LazyVim.toggle("background", false, {"light", "dark"}) end, { desc = "Toggle Background" }) -- lazygit map("n", "gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) map("n", "gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) map("n", "gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) map("n", "gB", LazyVim.lazygit.browse, { desc = "Git Browse" }) map("n", "gf", function() local git_path = vim.api.nvim_buf_get_name(0) LazyVim.lazygit({args = { "-f", vim.trim(git_path) }}) end, { desc = "Lazygit Current File History" }) map("n", "gl", function() LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() }) end, { desc = "Lazygit Log" }) map("n", "gL", function() LazyVim.lazygit({ args = { "log" } }) end, { desc = "Lazygit Log (cwd)" }) -- 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 local lazyterm = function() LazyVim.terminal(nil, { cwd = LazyVim.root() }) end map("n", "ft", lazyterm, { desc = "Terminal (Root Dir)" }) map("n", "fT", function() LazyVim.terminal() end, { desc = "Terminal (cwd)" }) map("n", "", lazyterm, { desc = "Terminal (Root Dir)" }) map("n", "", lazyterm, { desc = "which_key_ignore" }) -- Terminal Mappings map("t", "", "", { desc = "Enter Normal Mode" }) map("t", "", "wincmd h", { desc = "Go to Left Window" }) map("t", "", "wincmd j", { desc = "Go to Lower Window" }) map("t", "", "wincmd k", { desc = "Go to Upper Window" }) map("t", "", "wincmd l", { desc = "Go to Right Window" }) map("t", "", "close", { desc = "Hide Terminal" }) map("t", "", "close", { desc = "which_key_ignore" }) -- windows map("n", "ww", "p", { desc = "Other Window", remap = true }) map("n", "wd", "c", { desc = "Delete Window", remap = true }) map("n", "w-", "s", { desc = "Split Window Below", remap = true }) map("n", "w|", "v", { desc = "Split Window Right", remap = true }) map("n", "-", "s", { desc = "Split Window Below", remap = true }) map("n", "|", "v", { desc = "Split Window Right", remap = true }) map("n", "wm", function() LazyVim.toggle.maximize() end, { desc = "Maximize Toggle" }) -- 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" })