local set = vim.keymap.set set("i", "jk", "l") -- super help docs everywhere set("n", "vK", "help!") set("n", "H", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }), { bufnr = 0 }) vim.notify(vim.lsp.inlay_hint.is_enabled() and "Inlay Hint Enabled" or "Inlay Hint Disabled") end) set("n", "gra", function() local ok, tiny = pcall(require, "tiny-code-action") if ok then tiny.code_action({}) else vim.lsp.buf.code_action() end end) set("n", "", "Obsidian media_search", { desc = "New Media DB Entry" }) set({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { desc = "Down", expr = true, silent = true }) set({ "n", "x" }, "", "v:count == 0 ? 'gj' : 'j'", { desc = "Down", expr = true, silent = true }) set({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { desc = "Up", expr = true, silent = true }) set({ "n", "x" }, "", "v:count == 0 ? 'gk' : 'k'", { desc = "Up", expr = true, silent = true }) set("n", "", require("qol.search").query_browser, { remap = true }) -- mini version control! set("n", "ycc", function() return "yy" .. vim.v.count1 .. "gcc']p" end, { remap = true, expr = true }) -- fix previous spell error set("i", "", "[s1z=`]a") -- Copy/paste with system clipboard set({ "n", "x" }, "gY", '"+Y', { desc = "Copy to system clipboard" }) set({ "n", "x" }, "gy", '"+y', { desc = "Copy to system clipboard" }) set("n", "gp", '"+p', { desc = "Paste from system clipboard" }) -- - Paste in Visual with `P` to not copy selected text (`:h v_P`) set("x", "gp", '"+P', { desc = "Paste from system clipboard" }) set("n", "U", "Undotree", { desc = "Toggle UndoTree" }) set("n", "", "restart") set("n", "", function() local buf = vim.api.nvim_get_current_buf() local file = vim.api.nvim_buf_get_name(buf) vim.ui.input({ prompt = "To copy: ", default = file }, function(input) if input then vim.fn.setreg("+", input) vim.notify("Copied filename to clipboard", 2) end end) end) --search within visual selection - this is magic set("x", "/", "/\\%V") -- better J: keep cursor in place set("n", "J", "mzJ`z:delmarks z") -- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n set("n", "n", "'Nn'[v:searchforward].'zv'", { expr = true, desc = "Next Search Result" }) set("x", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next Search Result" }) set("o", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next Search Result" }) set("n", "N", "'nN'[v:searchforward].'zv'", { expr = true, desc = "Prev Search Result" }) set("x", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev Search Result" }) set("o", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev Search Result" }) -- Add undo break-points set("i", ",", ",u") set("i", ".", ".u") set("i", ";", ";u") -- better indenting set("v", "<", "", ">gv") local nmap_leader = function(suffix, rhs, desc, opts) opts = opts or {} vim.keymap.set("n", "" .. suffix, rhs, vim.tbl_extend("keep", { desc = desc }, opts)) end nmap_leader("x", function() local file = vim.fn.expand("%") local base = vim.fs.basename(file) if vim.endswith(base, ".qml") then vim.system({ "qs" }) elseif vim.startswith(base, "test_") then return "lua MiniTest.run_file()" elseif vim.endswith(base, "_spec.lua") then local has_neotest, neotest = pcall(require, "neotest") if has_neotest then neotest.run.run(file) return "Neotest output-panel" else return "!busted %" end else return "wso %" end end, "", { expr = true }) nmap_leader("X", function() return "lua MiniTest.run_at_location()" end, "", { expr = true }) --- zen mode (no neck pain) nmap_leader("z", "NoNeckPain") nmap_leader("qc", "cclose") nmap_leader("qo", "copen") nmap_leader("oS", "Obsidian search") nmap_leader("os", "Obsidian quick_switch") nmap_leader("od", "Obsidian today") nmap_leader("on", "Obsidian new") nmap_leader("ow", "Obsidian workspace") nmap_leader("O", "Obsidian") nmap_leader("S", "Obsidian sync") -- u for "Neovim UI and highlights" nmap_leader("ui", vim.show_pos, "Inspect Pos") nmap_leader("uI", "InspectTree", "Inspect Tree") nmap_leader("go", function() MiniDiff.toggle_overlay(0) end, "Toggle Minidiff Overlay") nmap_leader("gg", function() Snacks.lazygit() end, "Open Lazygit") -- t is for 'Terminal' nmap_leader("tT", "horizontal term", "Terminal (horizontal)") nmap_leader("tt", "vertical term", "Terminal (vertical)") -- b is for 'Buffer' local new_scratch_buffer = function() vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(true, true)) end nmap_leader("ba", "b#", "alternate") nmap_leader("bs", new_scratch_buffer, "scratch") set("n", "", "bprevious", { desc = "Prev Buffer" }) set("n", "", "bnext", { desc = "Next Buffer" }) -- e is for 'Explore' and 'Edit' local explore_quickfix = function() for _, win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do if vim.fn.getwininfo(win_id).quickfix == 1 then return vim.cmd("cclose") end end vim.cmd("copen") end nmap_leader("ei", "edit $MYVIMRC", "init.lua") nmap_leader("ep", "edit ~/.config/nvim/init.md", "plugins") nmap_leader("eq", explore_quickfix, "quickfix") -- nmap_leader("ed", "lua MiniFiles.open()", "Directory") -- nmap_leader("ef", explore_at_file, "File directory") -- nmap_leader("em", edit_plugin_file("30_mini.lua"), "MINI config") -- nmap_leader("en", "lua MiniNotify.show_history()", "Notifications") -- nmap_leader("eo", edit_plugin_file("10_options.lua"), "Options config") -- nmap_leader("ep", edit_plugin_file("40_plugins.lua"), "Plugins config") -- Create a new tab nmap_leader("tn", "tabnew", "New [t]ab") nmap_leader("tx", "tabclose", "E[x]clude tab") -- Toggle showing the tabline nmap_leader("tt", function() if vim.o.showtabline == 2 then vim.o.showtabline = 0 else vim.o.showtabline = 2 end end, "Toggle [t]abs") -- Navigate tabs set("n", "]t", ":tabnext", { desc = "Next tab", silent = true }) set("n", "[t", ":tabprevious", { desc = "Previous tab", silent = true }) nmap_leader("/", function() Snacks.picker.grep() end, "Grep") nmap_leader("ff", function() Snacks.picker.files() end, "Find files") nmap_leader("fc", function() Snacks.picker.files({ cwd = vim.fn.stdpath("config"), }) end, "Find Config File") nmap_leader(",", function() Snacks.picker.buffers() end, "Buffers") nmap_leader("N", function() Snacks.notifier.show_history() end, "Notification History") nmap_leader("un", function() Snacks.notifier.hide() end, "Hide Notifications") set("n", "fp", function() Snacks.picker.projects() end, { desc = "Find Prject" }) set("n", "fR", function() Snacks.picker.resume() end, { desc = "Resume" }) -- NOTE: `:bro ol` set("n", "fr", function() Snacks.picker.recent() end, { desc = "Recent" }) set("n", ".", function() Snacks.scratch() end, { desc = "Scratch Pad" }) set("n", "fp", function() Snacks.picker.projects() end, { desc = "Projects" }) set("n", "P", function() Snacks.picker({}) end, { desc = "All pickers" })