local map = vim.keymap.set map({ "n", "v" }, "", ":w ++p", { desc = "save file" }) map({ "i" }, "", ":w ++pa", { desc = "save file" }) map("n", ";", ":", { desc = "command with ;" }) map("v", ";", ":", { desc = "command with ;" }) map("n", "q", ":bd", { desc = "close buffer" }) map("n", "Q", ":%bd", { desc = "close all buffers" }) map({ "n", "v" }, "d", '"_d', { desc = "delete without cut" }) map({ "n", "v" }, "c", '"_c', { desc = "delete without cut" }) map({ "v", "n" }, "vv", "", { desc = "vv for visual block" }) map("i", "jj", "", { silent = true, desc = "back to normal with jj" }) map("v", "p", '"_dP', { desc = "do not overwrite 0 register when pasting over selection" }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to pres , which -- is not what someone will guess without a bit more experience. -- -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping -- or just use to exit terminal mode map("t", "", "", { desc = "Exit terminal mode" }) -- TIP: Disable arrow keys in normal mode map("n", "", function() vim.notify("Use h to move!!") end) map("n", "", function() vim.notify("Use l to move!!") end) map("n", "", function() vim.notify("Use k to move!!") end) map("n", "", function() vim.notify("Use j to move!!") end) map("n", "", "", { silent = true, desc = "go back with mouse" }) map("n", "", "", { silent = true, desc = "go forward with mouse" }) map("n", "bb", "e #", { desc = "Switch to Other Buffer" }) map("n", "`", "e #", { desc = "Switch to Other Buffer" }) -- Keybindings to make split navigation easier. -- Use CTRL+ to switch between windows -- -- See `:help wincmd` for a list of all window commands map("n", "", "", { desc = "Move focus to the left window" }) map("n", "", "", { desc = "Move focus to the right window" }) map("n", "", "", { desc = "Move focus to the lower window" }) map("n", "", "", { desc = "Move focus to the upper window" }) map("n", "", ":bprevious", { desc = "Previous buffer" }) map("n", "", ":bnext", { desc = "Next buffer" }) map("v", "", function() -- get contents of visual selection -- handle unpack deprecation table.unpack = table.unpack or unpack local function get_visual() local _, ls, cs = table.unpack(vim.fn.getpos("v")) local _, le, ce = table.unpack(vim.fn.getpos(".")) return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {}) end local pattern = table.concat(get_visual()) -- escape regex and line endings pattern = vim.fn.substitute(vim.fn.escape(pattern, "^$.*\\/~[]"), "\n", "\\n", "g") -- send parsed substitution command to command line vim.api.nvim_input(":%s/" .. pattern .. "//") end) -- diagnostics -- Show virtual lines diagnostics and hide when moved local default_diagnostics = function() vim.api.nvim_create_autocmd("CursorMoved", { group = vim.api.nvim_create_augroup("line-diagnostics", { clear = true }), callback = function() vim.diagnostic.config({ virtual_lines = false, virtual_text = true }) return true end, }) end map("n", "dd", function() vim.diagnostic.config({ virtual_lines = { current_line = true }, virtual_text = false }) default_diagnostics() end, { desc = "show diagnostics in virtual lines" }) map("n", "df", function() vim.diagnostic.config({ virtual_text = false }) vim.diagnostic.open_float({ scope = "line" }) default_diagnostics() end, { desc = "show diagnostics in floating window" }) map("n", "j", ":try | cprev | catch | clast | catch | endtryzz", { desc = "quickfix prev" }) map("n", "k", ":try | cnext | catch | cfirst | catch | endtryzz", { desc = "quickfix next" }) map("n", "qf", ":Cfilter! ", { desc = "quickfix filter" }) map("n", "K", function() vim.lsp.buf.hover({ border = "rounded" }) end, { desc = "vim.lsp.buf.hover()" }) -- Move lines map("n", "", ":execute 'move .-' . (v:count1 + 1)==", { desc = "Move Up" }) map("n", "", ":execute 'move .+' . v:count1==", { desc = "Move Down" }) map("v", "", ":execute \"'<,'>move '>+\" . v:count1gv=gv", { desc = "Move Down" }) map("v", "", ":execute \"'<,'>move '<-\" . (v:count1 + 1)gv=gv", { desc = "Move Up" }) map("v", "<", "", ">gv")