-- For NvChad -- require "nvchad.mappings" vim.keymap.set("n", "ch", "NvCheatsheet", { desc = "toggle nvcheatsheet" }) vim.keymap.set("n", "th", "Telescope themes", { desc = "telescope nvchad themes" }) -- General vim.keymap.set("i", "jk", "") vim.keymap.set("n", "cdconfig", "cd ~/.config/nvimpwd") vim.cmd("command! W execute 'SudaWrite %'") -- global lsp mappings vim.keymap.set("n", "ds", vim.diagnostic.setloclist, { desc = "lsp diagnostic loclist" }) -- nvimtree vim.keymap.set("n", "", "NvimTreeToggle", { desc = "nvimtree toggle window" }) -- telescope vim.keymap.set("n", "f", "Telescope oldfiles", { desc = "telescope find oldfiles" }) vim.keymap.set("n", "b", "Telescope buffers", { desc = "telescope find buffers" }) vim.keymap.set("n", "//", "Telescope current_buffer_fuzzy_find", { desc = "telescope find in current buffer" }) vim.keymap.set("n", "sf", "Telescope find_files", { desc = "telescope find files" }) vim.keymap.set( "n", "sF", "Telescope find_files follow=true no_ignore=true hidden=true", { desc = "telescope find all files" } ) vim.keymap.set("n", "sg", "Telescope live_grep", { desc = "telescope live grep" }) vim.keymap.set("n", "gf", "Telescope git_files", { desc = "telescope git files" }) vim.keymap.set("n", "sH", "Telescope help_tags", { desc = "telescope help page" }) vim.keymap.set("n", "sm", "Telescope marks", { desc = "telescope marks" }) vim.keymap.set("n", "sj", "Telescope jumplist", { desc = "telescope marks" }) vim.keymap.set("n", "tt", "Telescope", { desc = "telescope help page" }) vim.keymap.set("n", "sk", "Telescope keymaps", { desc = "telescope keymaps" }) vim.keymap.set("n", "pt", "Telescope terms", { desc = "telescope pick hidden term" }) vim.keymap.set("n", "ss", function() local current_filetype = vim.bo.filetype local cwd = os.getenv("HOME") .. "/snippets" require("telescope.builtin").find_files({ prompt_title = "Press to edit a snippet", default_text = current_filetype == "" and "" or current_filetype .. "_", cwd = cwd, attach_mappings = function(prompt_bufnr, map) local get_prompt_or_entry = function() local file_list = require("telescope.actions.state").get_selected_entry() if file_list then return file_list[1] else local current_picker = require("telescope.actions.state").get_current_picker(prompt_bufnr) return current_picker:_get_prompt() end end local edit_snippet = function() local file = get_prompt_or_entry() require("telescope.actions").close(prompt_bufnr) local prefix_filetype = string.match(file, "([^_]+)") vim.cmd(":vs") vim.cmd(":e " .. cwd .. "/" .. file) vim.bo.filetype = prefix_filetype vim.bo.bufhidden = "wipe" vim.cmd("set filetype?") end local insert_selected_snippet = function() local file = get_prompt_or_entry() local path = cwd .. "/" .. file if vim.fn.filereadable(path) ~= 0 then local snippet_content = vim.fn.readfile(path) require("telescope.actions").close(prompt_bufnr) vim.fn.setreg('"', snippet_content) print("Snippet saved to register") else edit_snippet() end end map("i", "", insert_selected_snippet) map("i", "", edit_snippet) map("n", "", insert_selected_snippet) return true end, }) end, { desc = "[S]earch [S]nippets" }) vim.keymap.set("n", "sd", function() require("telescope.builtin").oldfiles({ prompt_title = "CD to", attach_mappings = function(prompt_bufnr, map) local cd_prompt = function() local file = require("telescope.actions.state").get_selected_entry()[1] local path = string.match(file, "(.*[/\\])") require("telescope.actions").close(prompt_bufnr) vim.api.nvim_feedkeys(":cd " .. path, "n", true) end map("i", "", cd_prompt) map("n", "", cd_prompt) return true end, }) end, { desc = "Search Directory" }) -- new terminals vim.keymap.set({ "n", "t" }, "", function() require("nvchad.term").toggle({ pos = "vsp", id = "vtoggleTerm" }) end, { desc = "terminal toggleable vertical term" }) vim.keymap.set("t", "", "", { desc = "terminal escape terminal mode" }) vim.keymap.set({ "t" }, "", "|_i", { desc = "terminal toggleable vertical term" }) vim.keymap.set({ "n", "t" }, "", function() require("nvchad.term").toggle({ pos = "sp", id = "htoggleTerm" }) end, { desc = "terminal new horizontal term" }) vim.keymap.set({ "n", "t" }, "", function() require("nvchad.term").toggle({ pos = "float", id = "floatTerm" }) end, { desc = "terminal toggle floating term" }) -- whichkey vim.keymap.set("n", "sK", function() vim.cmd("WhichKey " .. vim.fn.input("WhichKey: ")) end, { desc = "whichkey query lookup" }) -- blankline vim.keymap.set("n", "cc", function() local config = { scope = {} } config.scope.exclude = { language = {}, node_type = {} } config.scope.include = { node_type = {} } local node = require("ibl.scope").get(vim.api.nvim_get_current_buf(), config) if node then local start_row, _, end_row, _ = node:range() if start_row ~= end_row then vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start_row + 1, 0 }) vim.api.nvim_feedkeys("_", "n", true) end end end, { desc = "blankline jump to current context" }) -- [ Configure Hop ] vim.keymap.set("n", "", ":HopWord") vim.keymap.set("n", "", ":HopChar1") -- [ Aerial ]"" "AerialNext", {}) vim.keymap.set("n", "gL", "Telescope aerial") vim.keymap.set("n", "gl", function() require("aerial").toggle({ direction = "left" }) end) --[ TrunZen ] vim.keymap.set("n", "z", ":TZAtaraxis") -- Use floating window for translation vim.keymap.set("v", "tz", function() vim.cmd('norm o^zt"ty') local translated_text = vim.fn.system("trans -t zh-TW -b", vim.fn.getreg("t")) local lines = vim.split(translated_text, "\n") table.remove(lines) local new_buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(new_buf, 0, -1, true, lines) vim.api.nvim_open_win(new_buf, true, { relative = "cursor", width = 80, height = #lines, row = #lines, col = 0, }) vim.cmd("setl nocul nonu nornu") vim.cmd("hi ActiveWindow guibg=#2a5a6a guifg=White | setl winhighlight=Normal:ActiveWindow") vim.cmd(":silent! %s/\\%x1b\\[[0-9;]*m//g") end, { desc = "Description" })