require "nvchad.mappings" local map = vim.keymap.set map("n", ";", ":", { desc = "CMD enter command mode" }) -- Allow moving the cursor through wrapped lines with j, k, and -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ -- empty mode is same as using :map -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour map({ "n", "v", "x" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { desc = "General Move down", expr = true }) map({ "n", "v", "x" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { desc = "General Move up", expr = true }) map( { "n", "v", "x" }, "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { desc = "General Move up", expr = true } ) map( { "n", "v", "x" }, "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { desc = "General Move down", expr = true } ) -- Don't escape visual mode when indenting map("v", "<", "", ">gv", { desc = "General Increase indent" }) -- Don't copy the replaced text after pasting in visual mode -- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste map("x", "p", 'p:let @+=@0:let @"=@0', { desc = "General Don't copy replaced text", silent = true }) -- format with conform map("n", "fm", function() require("conform").format() end, { desc = "formatting" }) -- Trim trailing spaces map("n", "s", function() local curpos = vim.api.nvim_win_get_cursor(0) vim.cmd [[keeppatterns %s/\s\+$//e]] vim.api.nvim_win_set_cursor(0, curpos) end, { desc = "Shortcuts Trim trailing whitespaces" }) -- Tabularize map("n", "t:", ":Tabularize /^[^:]*\\zs:", { desc = "Shortcuts tabularize :" }) map("n", "t=", ":Tabularize /^[^7]*\\zs=>", { desc = "Shortcuts tabularize =>" }) map( "n", "ti", ":Tabularize /\\(\\\\|\\\\|\\\\)", { desc = "Shortcuts tabularize port directions" } ) map("v", "t:", ":GTabularize /^[^:]*\\zs:", { desc = "Shortcuts block tabularize :" }) map("v", "t=", ":GTabularize /^[^=]*\\zs=>", { desc = "Shortcuts block tabularize =>" }) map( "v", "ti", ":GTabularize /\\(\\\\|\\\\|\\\\)", { desc = "Shortcuts block tabularize port directions" } ) -- Gitsigns map("n", "]c", function() if vim.wo.diff then return "]c" end vim.schedule(function() require("gitsigns").next_hunk() end) return "" end, { desc = "Gitsigns Jump to next hunk", expr = true }) map("n", "[c", function() if vim.wo.diff then return "[c" end vim.schedule(function() require("gitsigns").prev_hunk() end) return "" end, { desc = "Gitsigns Jump to prev hunk", expr = true }) map("n", "rh", function() require("gitsigns").reset_hunk() end, { desc = "Gitsigns Reset hunk" }) map("n", "ph", function() require("gitsigns").preview_hunk() end, { desc = "Gitsigns Preview hunk" }) map("n", "gb", function() package.loaded.gitsigns.blame_line() end, { desc = "Gitsigns Blame line" }) map("n", "td", function() require("gitsigns").toggle_deleted() end, { desc = "Gitsigns Toggle deleted" }) -- molten related mappings map("n", "ip", function() local venv = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") if venv ~= nil then -- in the form of /home/ha5pls/.local/state/virtualenvs/VENV_NAME venv = string.match(venv, "/.+/(.+)") vim.cmd(("MoltenInit %s"):format(venv)) else vim.cmd("MoltenInit python3") end end, { desc = "Initialize Molten for python3" }) map("n", "mi", ":MoltenInit") map("n", "me", ":MoltenEvaluateOperator") map("n", "rr", ":MoltenReevaluateCell") map("v", "r", ":MoltenEvaluateVisualgv") map("n", "os", ":noautocmd MoltenEnterOutput") map("n", "oh", ":MoltenHideOutput") map("n", "md", ":MoltenDelete")