-- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here local wk = require("which-key") require("colemak").init() -- vim.keymap.del("n", "n") -- vim.keymap.del("n", "N") local map = vim.keymap.set -- required to remap special sequence -- when inside tmux :) -- require("tmux-remap").setup({ -- special = "←", -- remap = "", -- autoset = true, -- }) local special_key = "←" vim.keymap.set({ "n", "i" }, special_key, "", { remap = true }) vim.keymap.set({ "i", "n" }, "", "") -- map({ "n" }, "", function() -- vim.notify("test") -- end) map({ "n", "x" }, "\\", function() LazyVim.format({ force = true }) end, { desc = "Format" }) -- preserve indent on insert -- only do this if autoindent is on and we're on an empty line? -- map({ "n" }, "i", "i") map({ "n" }, "n", "tabnew", { desc = "New Tab" }) map({ "n" }, "i", "tabnext", { desc = "Next Tab" }) map({ "n" }, "m", "tabprevious", { desc = "Previous Tab" }) map({ "n" }, "D", "tabonly", { desc = "Close Other Tabs" }) vim.keymap.del("n", "f") vim.keymap.del("n", "l") vim.keymap.del("n", "[") vim.keymap.del("n", "]") vim.keymap.del("n", "o") vim.keymap.del("n", "") map({ "n" }, "", function() -- the `a` is necessary to return the cursor to the same -- position it was before vim.cmd("normal! zz") end, { remap = false, noremap = true, desc = "Center Screen" }) map({ "i" }, "", function() -- the `a` is necessary to return the cursor to the same -- position it was before vim.api.nvim_input("zza") end, { remap = false, noremap = true, desc = "Center Screen (Insert mode)" }) map("n", "", "stop", { desc = "Suspend" }) map({ "n", "i", "x", "o" }, "", "", { noremap = true, desc = "Escape" }) -- Better Scroll map({ "n" }, "", "", { noremap = true, desc = "Scroll Up" }) map({ "n" }, "", "", { noremap = true, desc = "Scroll Down" }) -- Snacks.toggle.zen():map("uz") map({ "n" }, "cl", "vgu", { noremap = true, desc = "Lowercase current char" }) map({ "n" }, "cu", "vgU", { noremap = true, desc = "Uppercase current char" }) -- local colemak = false if colemak then -- Bind arrows to hjkl to my colemak-dh motions work as expected map({ "n", "x" }, "", "k", { desc = "Up", remap = true }) map({ "n", "x" }, "", "j", { desc = "Down", remap = true }) map({ "n", "x" }, "", "h", { desc = "Left", remap = true }) map({ "n", "x" }, "", "l", { desc = "Right", remap = true }) map({ "n", "t", "i" }, "", "h", { desc = "Switch Window Left", remap = true }) map({ "n", "t", "i" }, "", "l", { desc = "Switch Window Right", remap = true }) map({ "n", "t", "i" }, "", "k", { remap = true }) map({ "n", "t", "i" }, "", "j", { desc = "Switch Window Down", remap = true }) map({ "n" }, "d", "q", { desc = "Close window", remap = true }) map({ "x" }, "", "", { remap = true }) map({ "x" }, "", "", { remap = true }) map({ "n", "x", "v" }, "", "", { remap = true }) map({ "n", "x", "v" }, "", "", { remap = true }) map({ "n" }, "", "BufferLineCyclePrev", { desc = "Previous Buffer", remap = true }) map({ "n" }, "", "BufferLineCycleNext", { desc = "Next Buffer", remap = true }) map({ "i" }, "", "", { desc = "Escape insert mode", remap = true }) -- better navigation map({ "n" }, "", "zz", { remap = false }) map({ "n" }, "", "zz", { remap = false }) map({ "n" }, "n", "nzz", { remap = false }) map({ "n" }, "N", "Nzz", { remap = false }) map({ "n" }, "{", "{zz", { remap = false }) map({ "n" }, "}", "}zz", { remap = false }) map({ "n" }, "", "zz", { remap = false }) map({ "n" }, "", "zz", { remap = false }) map({ "n", "x" }, "", "$", { remap = false }) map({ "n", "x" }, "", "0", { remap = false }) -- easily access null register -- map({ "n", "x" }, "n", '"_', { remap = false, silent = true, desc = "Null Register" }) -- remove the default lazyvim, and also swap H and L (for move cursor) to make more sense on colemak vim.keymap.del({ "n" }, "") vim.keymap.del({ "n" }, "") map({ "n" }, "", "L", { remap = false }) map({ "n" }, "", "H", { remap = false }) else vim.api.nvim_create_autocmd("UIEnter", { callback = function() require("colemak").init() vim.notify("colemak") end, }) end -- better delete and put map({ "n", "x", "v", "o" }, "", '"_', { remap = false, silent = true, desc = "Null Register" }) -- Duplicate and comment line map({ "n" }, "yc", '"zyygcc"zp', { remap = true, silent = true, desc = "Duplicate and comment line" }) -- better quit map("n", "", "qa", { desc = "Quit All" }) map({ "n", "x" }, "", "", { desc = "Increment" }) map({ "n", "x" }, "", "", { desc = "Decrement" }) map("n", "", function() Snacks.bufdelete() end, { remap = false, desc = "Delete Buffer" }) map("n", "", "bd", { desc = "Delete buffer and window" }) map("n", "", "c", { desc = "Close window" }) -- yank history map({ "n", "x" }, "fp", function() if LazyVim.pick.picker.name == "telescope" then require("telescope").extensions.yank_history.yank_history({}) else vim.cmd([[YankyRingHistory]]) end end, { desc = "Open Yank History", remap = false }) -- TODO: add leader + y for save current buf, leader + Y to write all -- map({ "n", "x" }, "y", ":w", { desc = "Save" }) map({ "n", "x" }, "Y", ":wa", { desc = "Save All" }) -- Zen Mode -- map("n", "uz", "ZenMode", { desc = "Toggle Zen Mode" }) -- Source Current File -- map("n", "x", "source %", { desc = "Source current file" }) -- Obsidian -- o is the prefix for all Obsidian bindings wk.add({ { "O", group = "Obsidian" }, { "Od", group = "Daily Note" }, { "Ol", group = "Follow Link" }, }) map("n", "Oo", "ObsidianQuickSwitch", { desc = "Obsidian Quick Switch" }) map("n", "O/", "ObsidianSearch", { desc = "Obsidian Grep" }) -- This one will open the command line and let the user type the arg map("n", "On", "ObsidianNew", { desc = "Obsidian New Note" }) -- map("n", "On", function() -- require("command-key").command("ObsidianNew") -- end, { desc = "Obsidian New Note" }) map("n", "Ob", "ObsidianBacklinks", { desc = "Obsidian Backlinks" }) map("n", "Ot", "ObsidianTags", { desc = "Obsidian Tags" }) map("n", "Olv", "ObsidianFollowLink vsplit", { desc = "Obsidian Follow Link Vsplit" }) map("n", "Olh", "ObsidianFollowLink hsplit", { desc = "Obsidian Follow Link Hsplit" }) map("n", "Odt", "ObsidianToday", { desc = "Obsidian Open Today's Daily" }) map("n", "Ods", "ObsidianDailies", { desc = "Obsidian Search Dailies" }) map("n", "Ols", "ObsidianLinks", { desc = "Obsidian Search Links" }) map("x", "Oll", function() require("command-key").command("ObsidianLink") end, { desc = "Obsidian Link Visual To Existing Note" }) map("x", "Oln", function() require("command-key").command("ObsidianLinkNew") end, { desc = "Obsidian Link Visual To New Note" }) map("x", "Ole", function() require("command-key").command("ObsidianExtractNote") end, { desc = "Obsidian Copy Selection To New Note & Link" }) map("n", "Or", function() require("command-key").command("ObsidianRename") end, { desc = "Obsidian Rename" }) map("n", "Oc", "ObsidianTOC", { desc = "Obsidian Table Of Contents" }) -- TODO: Add binds for templates -- cmdh.fix_hjkl() -- cmdh.fix_all()