-- ╭─────────────────────────────────────────────────────────╮ -- │ Keymaps │ -- ╰─────────────────────────────────────────────────────────╯ -- Create keymap function local mapkey = function(mode, key, desc, action, plugin) local keymapper = plugin and require("lz.n").keymap(plugin).set or vim.keymap.set keymapper(mode, key, action, { noremap = true, silent = true, desc = desc }) end -- Set the leader key vim.g.mapleader = " " -- Pickers mapkey("n", "f", "Open file picker", ":Pick files", "mini.pick") mapkey("n", "o", "Open old file picker", ":Pick oldfiles", "mini.pick") mapkey("n", "/", "Open live grep picker", ":Pick grep_live", "mini.pick") mapkey("n", "k", "Open colorscheme picker", ":Pick colorschemes", "mini.pick") mapkey("n", "z", "Open zoxide picker", ":Zi", "zoxide.vim") mapkey("n", "l", "Open tab directory picker", function () local dirstr = vim.fn.system("fd -t d") local pos,dirtbl = 0,{} for st,sp in function() return string.find(dirstr, "\n", pos, true) end do table.insert(dirtbl, string.sub(dirstr, pos, st - 1)) pos = sp + 1 end table.insert(dirtbl, string.sub(dirstr, pos)) vim.ui.select( dirtbl, {}, function (choice) vim.cmd.tcd(choice) end ) end, "mini.pick") mapkey("n", "L", "Open directory picker", function () local dirstr = vim.fn.system("fd -t d") local pos,dirtbl = 0,{} for st,sp in function() return string.find(dirstr, "\n", pos, true) end do table.insert(dirtbl, string.sub(dirstr, pos, st - 1)) pos = sp + 1 end table.insert(dirtbl, string.sub(dirstr, pos)) vim.ui.select( dirtbl, {}, function (choice) vim.cmd.cd(choice) end ) end, "mini.pick") -- File manager mapkey("n", "e", "Open file manager", ":lua MiniFiles.open()", "mini.files") -- Git mapkey("n", "g", "Manage git", "") mapkey("n", "gg", "Open neogit", ":Neogit", "neogit") mapkey("n", "ga", "Git add", ":Git add %:p", "mini-git") mapkey("n", "gA", "Git add cwd", function() vim.cmd("Git add " .. vim.fn.getcwd() .. "/.") end, "mini-git") mapkey("n", "gr", "Git remove", ":Git rm %:p", "mini-git") mapkey("n", "gc", "Git commit", ":Git commit", "mini-git") mapkey("n", "gs", "Git status", ":Git status", "mini-git") mapkey("n", "gp", "Git pull", ":Git pull", "mini-git") mapkey("n", "gP", "Git push", ":Git push", "mini-git") -- Tabs mapkey("n", "t", "Manage tabs", "") mapkey("n", "tt", "Go to next tab", ":tabn") mapkey("n", "tT", "Go to previous tab", ":tabp") mapkey("n", "to", "Open new tab", ":tabnew") mapkey("n", "tc", "Close current tab", ":tabclose") -- Buffers mapkey("n", "b", "Manage buffers", "") mapkey("n", "bb", "Open buffer picker", ":Pick buffers", "mini.pick") mapkey("n", "bc", "Clear invisible buffers", function () local bufinfos = vim.fn.getbufinfo({buflisted = 1}) vim.tbl_map(function (bufinfo) if bufinfo.changed == 0 and (not bufinfo.windows or #bufinfo.windows == 0) then vim.api.nvim_buf_delete(bufinfo.bufnr, {force = false, unload = false}) vim.cmd.redrawtabline() end end, bufinfos) end) -- Comment box mapkey("n", "j", "Manage comment graphics", "") mapkey("n", "jb", "Create comment box", ":CB") -- Session mapkey("n", "w", "Manage sessions", "") mapkey("n", "ww", "Open a session", ":Autosession search", "mini.pick") mapkey("n", "wd", "Delete a session", ":Autosession delete", "mini.pick") mapkey("n", "wr", "Restore last session", ":SessionRestore") mapkey("n", "wp", "Purge orphaned sessions", ":SessionPurgeOrphaned") mapkey("n", "ws", "Save session", ":SessionSave") -- Terminal mapkey("n", "n", "Open terminal", ":botright terminal") -- Markview mapkey("n", "v", "Toggle markview", ":Markview", "markview.nvim") -- Toggle spellcheck mapkey("n", "zq", "Toggle spellcheck", ":set spell!") -- Spelling suggestions mapkey("n", "z=", "Pick spelling suggestions", ":Pick spellsuggest") -- Do operations without yanking mapkey({ "n", "v" }, "d", "Fully delete", [["_d]]) mapkey({ "n", "v" }, "D", "Fully delete line", [["_D]]) mapkey({ "n", "v" }, "x", "Fully delete character", [["_x]]) mapkey({ "n", "v" }, "X", "Fully delete previous character", [["_X]]) mapkey({ "n", "v" }, "c", "Fully change", [["_c]]) mapkey({ "n", "v" }, "C", "Fully change line", [["_C]]) mapkey({ "v" }, "p", "Fully put", [[P]]) -- Paste on newline mapkey("n", "p", "Paste on newline", ":pu") -- Visual Movement Keys mapkey({ "n", "v" }, "j", "Go down visually", "gj") mapkey({ "n", "v" }, "k", "Go up visually", "gk") mapkey({ "n", "v" }, "", "Go down visually", "g") mapkey({ "n", "v" }, "", "Go up visually", "g") -- Falling key mapkey("n", "u", "Make it rain", ":CellularAutomaton make_it_rain", "cellular-automaton.nvim") -- QOL Keys mapkey("t", "", "Exit terminal insert mode", "") vim.keymap.set("c", "", function() if vim.fn.pumvisible() == 1 then return '' end return '' end, { expr = true }) -- Make enter complete command. mapkey("n", "", "Clear highlights", ":noh") -- Make esc clear highlights