From 83291d488aa88346f79d15809c8c0dcf5ed271a1 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 7 Jul 2024 12:41:00 +0800 Subject: Update --- vim/lua/mappings.lua | 150 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 57 deletions(-) (limited to 'vim/lua') diff --git a/vim/lua/mappings.lua b/vim/lua/mappings.lua index c417ea4..6aa81f6 100644 --- a/vim/lua/mappings.lua +++ b/vim/lua/mappings.lua @@ -25,11 +25,19 @@ vim.keymap.set("n", "", "NvimTreeToggle", { desc = "nvimtree toggl -- 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", +"/", +"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", +"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" }) @@ -37,30 +45,30 @@ vim.keymap.set("n", "sH", "Telescope help_tags", { desc = "tele 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", "sk", "Telescope keymaps", { desc = "telescope keymaps" }) vim.keymap.set("n", "pt", "Telescope terms", { desc = "telescope pick hidden term" }) -vim.keymap.set('n', 'ss', function() +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', + local cwd = os.getenv("HOME") .. "/snippets" + require("telescope.builtin").find_files({ + prompt_title = "Press to edit a snippet", default_text = 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() + 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) + 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) + require("telescope.actions").close(prompt_bufnr) local prefix_filetype = string.match(file, "([^_]+)") vim.cmd(":e " .. cwd .. "/" .. file) vim.bo.filetype = prefix_filetype @@ -72,42 +80,41 @@ vim.keymap.set('n', 'ss', function() local path = cwd .. "/" .. file if vim.fn.filereadable(path) ~= 0 then local snippet_content = vim.fn.readfile(path) - require('telescope.actions').close(prompt_bufnr) + require("telescope.actions").close(prompt_bufnr) vim.fn.setreg('"', snippet_content) - print('Snippet saved to register') + print("Snippet saved to register") else edit_snippet() end end - map('i', '', insert_selected_snippet) - map('i', '', edit_snippet) - map('n', '', insert_selected_snippet) + map("i", "", insert_selected_snippet) + map("i", "", edit_snippet) + map("n", "", insert_selected_snippet) return true end, - } -end, { desc = '[S]earch [S]nippets' }) + }) +end, { desc = "[S]earch [S]nippets" }) -vim.keymap.set('n', 'sd', function() - require('telescope.builtin').oldfiles { - prompt_title = 'CD to', +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 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) + require("telescope.actions").close(prompt_bufnr) + vim.api.nvim_feedkeys(":cd " .. path, "n", true) end - map('i', '', cd_prompt) - map('n', '', cd_prompt) + map("i", "", cd_prompt) + map("n", "", cd_prompt) return true end, - } -end, { desc = 'Search Directory' }) - + }) +end, { desc = "Search Directory" }) -- map("n", "ma", "Telescope marks", { desc = "telescope find marks" }) -- map("n", "cm", "Telescope git_commits", { desc = "telescope git commits" }) @@ -117,26 +124,31 @@ end, { desc = 'Search Directory' }) -- map("t", "", "", { desc = "terminal escape terminal mode" }) -- new terminals -vim.keymap.set("n", "h", function() require("nvchad.term").new { pos = "sp" } end, - { desc = "terminal new horizontal term" }) -vim.keymap.set("n", "v", function() require("nvchad.term").new { pos = "vsp" } end, - { desc = "terminal new vertical window" }) +vim.keymap.set("n", "h", function() + require("nvchad.term").new({ pos = "sp" }) +end, { desc = "terminal new horizontal term" }) +vim.keymap.set("n", "v", function() + require("nvchad.term").new({ pos = "vsp" }) +end, { desc = "terminal new vertical window" }) -- toggleable -vim.keymap.set({ "n", "t" }, "", function() require("nvchad.term").toggle { pos = "vsp", id = "vtoggleTerm" } end, - { desc = "terminal toggleable vertical term" }) +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" }) +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" }) vim.keymap.set("n", "th", "Telescope themes", { desc = "telescope nvchad themes" }) -- whichkey vim.keymap.set("n", "wK", "WhichKey ", { desc = "whichkey all keymaps" }) vim.keymap.set("n", "wk", function() - vim.cmd("WhichKey " .. vim.fn.input "WhichKey: ") + vim.cmd("WhichKey " .. vim.fn.input("WhichKey: ")) end, { desc = "whichkey query lookup" }) -- blankline @@ -161,21 +173,45 @@ vim.g.mkdp_preview_options = { mkit = { breaks = true }, toc = { containerClass = "toc", - format = 'function format(x, htmlencode) { return `${htmlencode(x)}`; }', - callback = "console.log('foo')", + format = "function format(x, htmlencode) { return `${htmlencode(x)}`; }", + callback = "console.log('foo')", + }, } -} - --- [ Configure Hop ] -vim.keymap.set('n', "", ':HopWord') -vim.keymap.set('n', '', ':HopChar1') - --- [ Configure vim-surround ] -vim.cmd('vmap s S') - --- [ 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') + -- [ Configure Hop ] + vim.keymap.set("n", "", ":HopWord") + vim.keymap.set("n", "", ":HopChar1") + + -- [ Configure vim-surround ] + vim.cmd("vmap s S") + + -- [ 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") + + 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(':%s/\\%x1b\\[[0-9;]*m//g') + end, { desc = "Description" }) -- cgit v1.2.3-70-g09d2