require "nvchad.mappings" -- add yours here local vim = vim local map = vim.keymap.set local g = vim.g local diag = vim.diagnostic map("n", ";", ":", { desc = "CMD enter command mode" }) map("i", "jk", "") map("n", "j", "gj", { desc = "Move down" }) map("n", "k", "gk", { desc = "Move up" }) map("n", "tt", function() require("base46").toggle_transparency() end, { desc = "Toggle transparency" }) map("n", "J", "mzJ`z", { desc = "Concatenate line below cursor but does not move the cursor" }) map("n", "o", ':call append(line("."), repeat([""], v:count1))', { desc = "Insert line below" }) map("n", "O", ':call append(line(".")-1, repeat([""], v:count1))', { desc = "Insert line above" }) map("n", "", "zz") map("n", "", "zz") map("n", "lg", " LazyGit", { desc = "LazyGit" }) -- Visual mode map("v", "J", ":m '>+1gv=gv", { desc = "Move line w/indentation" }) map("v", "K", ":m '<-2gv=gv", { desc = "Move line w/indentation" }) map("v", ">", ">gv", { desc = "indent" }) map("v", "<", "lt", Toggle_diagnostics, { noremap = true, silent = true, desc = "Toggle vim diagnostics" }) -- select a session to load map("n", "qs", function() require("persistence").select() end, { desc = "Select session to load" }) -- load the last session map("n", "ql", function() require("persistence").load { last = true } end, { desc = "Load last session" }) -- stop Persistence => session won't be saved on exit map("n", "qd", function() require("persistence").stop() end, { desc = "Stop persistence" }) -- debug related stuff local dap = require "dap" map("n", "db", function() dap.toggle_breakpoint() end, { desc = "Toggle breakpoint" }) map("n", "dc", function() dap.continue() end, { desc = "Continue" }) map("n", "dr", function() dap.repl.open() end, { desc = "Open REPL" }) map("n", "ds", function() dap.step_over() end, { desc = "Step over" }) map("n", "di", function() dap.step_into() end, { desc = "Step into" }) map("n", "do", function() dap.step_out() end, { desc = "Step out" }) map("n", "dT", function() dap.terminate() end, { desc = "Terminate" }) map("n", "dl", function() dap.run_last() end, { desc = "Run Last" }) map("n", "dC", function() dap.run_to_cursor() end, { desc = "Run to Cursor" }) -- dapui local dapui = require "dapui" local widgets = require "dap.ui.widgets" map("n", "du", function() dapui.toggle() end, { desc = "Toggle UI" }) map({ "n", "v" }, "dh", function() widgets.hover() end, { desc = "Hover" }) map({ "n", "v" }, "dp", function() widgets.preview() end, { desc = "Preview" }) map("n", "df", function() widgets.centered_float(widgets.frames) end, { desc = "Frames" }) map("n", "ds", function() widgets.centered_float(widgets.scopes) end, { desc = "Scopes" }) -- CodeCompletion mappings map({ "n", "v" }, "", "CodeCompanionActions", { noremap = true, silent = true, desc = "Code Actions" }) map({ "n", "v" }, "a", "CodeCompanionChat Toggle", { noremap = true, silent = true, desc = "Code Chat" }) map("v", "ga", "CodeCompanionChat Add", { noremap = true, silent = true, desc = "Code Chat Add Visual" }) map("v", "ce", function() require("codecompanion").prompt("explain") end, { noremap = true, silent = true, desc = "Explain Selection" } ) -- Expand 'cc' into 'CodeCompanion' in the command line vim.cmd([[cab cc CodeCompanion]]) -- mappings for wiki.vim map("n", "iw", function () require("telescope.builtin").live_grep({ prompt_title = "Search Wiki", cwd = vim.fn.expand("~/wiki"), }) end, { desc = "Search Wiki" }) map("n", "jn", "WikiJournalNext", { desc = "Next Journal" }) map("n", "jp", "WikiJournalPrev", { desc = "Previous Journal" }) -- Mappings for Man using ripgrep local actions = require("telescope.actions") local action_state = require("telescope.actions.state") local previewers = require("telescope.previewers") -- Define a custom previewer that runs 'man' in a terminal job: local man_previewer = previewers.new_termopen_previewer({ get_command = function(entry) -- 'entry.value' will be the man-topic, e.g. "ls" if not entry or not entry.value then return { "echo", "" } end -- The pager string (col -bx | bat -l man -p) must be passed as one argument -- so that 'man' interprets it as a shell command for the pager: return { "man", "-P", "col -bx | bat -l man -p", -- all as a single argument to -P entry.value } end, }) -- Create a mapping that invokes Telescope with our custom previewer map("n", "mp", function() require("telescope.builtin").find_files({ prompt_title = "Man Pages", find_command = { "bash", "-c", table.concat({ -- Pipeline: -- 1) 'rg --files /usr/share/man' -- 2) strip directory paths (xargs basename) -- 3) remove trailing .x or .x.gz (sed) -- 4) sort + unique "rg --files /usr/share/man", "| xargs basename", "| sed 's/\\.[^.]*$//'", "| sort -u", }, " ") }, -- Provide our custom previewer previewer = man_previewer, -- 3) attach_mappings() lets us override what happens when we press attach_mappings = function(prompt_bufnr, map_telescope) local function open_man_page() local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) -- Actually open the man page inside Neovim: vim.cmd("Man " .. selection.value) end -- Bind in insert + normal mode to open the man page map_telescope("i", "", open_man_page) map_telescope("n", "", open_man_page) return true end, }) end, { desc = "Search manpages" }) -- Mappings for Gitsigns -- Git blame map("v", "gb", "lua require('gitsigns').blame_line()", { desc = "Git Blame line" }) map("n", "gb", "lua require('gitsigns').blame()", { desc = "Git Blame" })