diff options
Diffstat (limited to 'vim/lua')
| -rw-r--r-- | vim/lua/mappings.lua | 211 |
1 files changed, 105 insertions, 106 deletions
diff --git a/vim/lua/mappings.lua b/vim/lua/mappings.lua index 07107e5..5eea577 100644 --- a/vim/lua/mappings.lua +++ b/vim/lua/mappings.lua | |||
| @@ -20,10 +20,10 @@ vim.keymap.set("n", "<leader>b", "<cmd>Telescope buffers<CR>", { desc = "telesco | |||
| 20 | vim.keymap.set("n", "//", "<cmd>Telescope current_buffer_fuzzy_find<CR>", { desc = "telescope find in current buffer" }) | 20 | vim.keymap.set("n", "//", "<cmd>Telescope current_buffer_fuzzy_find<CR>", { desc = "telescope find in current buffer" }) |
| 21 | vim.keymap.set("n", "<leader>sf", "<cmd>Telescope find_files<cr>", { desc = "telescope find files" }) | 21 | vim.keymap.set("n", "<leader>sf", "<cmd>Telescope find_files<cr>", { desc = "telescope find files" }) |
| 22 | vim.keymap.set( | 22 | vim.keymap.set( |
| 23 | "n", | 23 | "n", |
| 24 | "<leader>sF", | 24 | "<leader>sF", |
| 25 | "<cmd>Telescope find_files follow=true no_ignore=true hidden=true<CR>", | 25 | "<cmd>Telescope find_files follow=true no_ignore=true hidden=true<CR>", |
| 26 | { desc = "telescope find all files" } | 26 | { desc = "telescope find all files" } |
| 27 | ) | 27 | ) |
| 28 | vim.keymap.set("n", "<leader>sg", "<cmd>Telescope live_grep<CR>", { desc = "telescope live grep" }) | 28 | vim.keymap.set("n", "<leader>sg", "<cmd>Telescope live_grep<CR>", { desc = "telescope live grep" }) |
| 29 | vim.keymap.set("n", "<leader>gf", "<cmd>Telescope git_files<CR>", { desc = "telescope git files" }) | 29 | vim.keymap.set("n", "<leader>gf", "<cmd>Telescope git_files<CR>", { desc = "telescope git files" }) |
| @@ -35,110 +35,109 @@ vim.keymap.set("n", "<leader>sk", "<cmd>Telescope keymaps<CR>", { desc = "telesc | |||
| 35 | vim.keymap.set("n", "<leader>pt", "<cmd>Telescope terms<CR>", { desc = "telescope pick hidden term" }) | 35 | vim.keymap.set("n", "<leader>pt", "<cmd>Telescope terms<CR>", { desc = "telescope pick hidden term" }) |
| 36 | 36 | ||
| 37 | vim.keymap.set("n", "<leader>ss", function() | 37 | vim.keymap.set("n", "<leader>ss", function() |
| 38 | local current_filetype = vim.bo.filetype | 38 | local current_filetype = vim.bo.filetype |
| 39 | local cwd = os.getenv("HOME") .. "/snippets" | 39 | local cwd = os.getenv("HOME") .. "/snippets" |
| 40 | require("telescope.builtin").find_files({ | 40 | require("telescope.builtin").find_files({ |
| 41 | prompt_title = "Press <C-T> to edit a snippet", | 41 | prompt_title = "Press <C-T> to edit a snippet", |
| 42 | default_text = current_filetype == "" and "" or current_filetype .. "_", | 42 | default_text = current_filetype == "" and "" or current_filetype .. "_", |
| 43 | cwd = cwd, | 43 | cwd = cwd, |
| 44 | attach_mappings = function(prompt_bufnr, map) | 44 | attach_mappings = function(prompt_bufnr, map) |
| 45 | local get_prompt_or_entry = function() | 45 | local get_prompt_or_entry = function() |
| 46 | local file_list = require("telescope.actions.state").get_selected_entry() | 46 | local file_list = require("telescope.actions.state").get_selected_entry() |
| 47 | if file_list then | 47 | if file_list then |
| 48 | return file_list[1] | 48 | return file_list[1] |
| 49 | else | 49 | else |
| 50 | local current_picker = require("telescope.actions.state").get_current_picker(prompt_bufnr) | 50 | local current_picker = require("telescope.actions.state").get_current_picker(prompt_bufnr) |
| 51 | return current_picker:_get_prompt() | 51 | return current_picker:_get_prompt() |
| 52 | end | 52 | end |
| 53 | end | 53 | end |
| 54 | 54 | ||
| 55 | local edit_snippet = function() | 55 | local edit_snippet = function() |
| 56 | local file = get_prompt_or_entry() | 56 | local file = get_prompt_or_entry() |
| 57 | require("telescope.actions").close(prompt_bufnr) | 57 | require("telescope.actions").close(prompt_bufnr) |
| 58 | local prefix_filetype = string.match(file, "([^_]+)") | 58 | local prefix_filetype = string.match(file, "([^_]+)") |
| 59 | vim.cmd(":vs") | 59 | vim.cmd(":vs") |
| 60 | vim.cmd(":e " .. cwd .. "/" .. file) | 60 | vim.cmd(":e " .. cwd .. "/" .. file) |
| 61 | vim.bo.filetype = prefix_filetype | 61 | vim.bo.filetype = prefix_filetype |
| 62 | vim.bo.bufhidden = "wipe" | 62 | vim.bo.bufhidden = "wipe" |
| 63 | vim.cmd("set filetype?") | 63 | vim.cmd("set filetype?") |
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | local insert_selected_snippet = function() | 66 | local insert_selected_snippet = function() |
| 67 | local file = get_prompt_or_entry() | 67 | local file = get_prompt_or_entry() |
| 68 | local path = cwd .. "/" .. file | 68 | local path = cwd .. "/" .. file |
| 69 | if vim.fn.filereadable(path) ~= 0 then | 69 | if vim.fn.filereadable(path) ~= 0 then |
| 70 | local snippet_content = vim.fn.readfile(path) | 70 | local snippet_content = vim.fn.readfile(path) |
| 71 | require("telescope.actions").close(prompt_bufnr) | 71 | require("telescope.actions").close(prompt_bufnr) |
| 72 | vim.fn.setreg('"', snippet_content) | 72 | vim.fn.setreg('"', snippet_content) |
| 73 | print("Snippet saved to register") | 73 | print("Snippet saved to register") |
| 74 | else | 74 | else |
| 75 | edit_snippet() | 75 | edit_snippet() |
| 76 | end | 76 | end |
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | map("i", "<CR>", insert_selected_snippet) | 79 | map("i", "<CR>", insert_selected_snippet) |
| 80 | map("i", "<C-T>", edit_snippet) | 80 | map("i", "<C-T>", edit_snippet) |
| 81 | map("n", "<CR>", insert_selected_snippet) | 81 | map("n", "<CR>", insert_selected_snippet) |
| 82 | 82 | ||
| 83 | return true | 83 | return true |
| 84 | end, | 84 | end, |
| 85 | }) | 85 | }) |
| 86 | end, { desc = "[S]earch [S]nippets" }) | 86 | end, { desc = "[S]earch [S]nippets" }) |
| 87 | 87 | ||
| 88 | vim.keymap.set("n", "<leader>sd", function() | 88 | vim.keymap.set("n", "<leader>sd", function() |
| 89 | require("telescope.builtin").oldfiles({ | 89 | require("telescope.builtin").oldfiles({ |
| 90 | prompt_title = "CD to", | 90 | prompt_title = "CD to", |
| 91 | attach_mappings = function(prompt_bufnr, map) | 91 | attach_mappings = function(prompt_bufnr, map) |
| 92 | local cd_prompt = function() | 92 | local cd_prompt = function() |
| 93 | local file = require("telescope.actions.state").get_selected_entry()[1] | 93 | local file = require("telescope.actions.state").get_selected_entry()[1] |
| 94 | local path = string.match(file, "(.*[/\\])") | 94 | local path = string.match(file, "(.*[/\\])") |
| 95 | require("telescope.actions").close(prompt_bufnr) | 95 | require("telescope.actions").close(prompt_bufnr) |
| 96 | vim.api.nvim_feedkeys(":cd " .. path, "n", true) | 96 | vim.api.nvim_feedkeys(":cd " .. path, "n", true) |
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | map("i", "<CR>", cd_prompt) | 99 | map("i", "<CR>", cd_prompt) |
| 100 | map("n", "<CR>", cd_prompt) | 100 | map("n", "<CR>", cd_prompt) |
| 101 | 101 | ||
| 102 | return true | 102 | return true |
| 103 | end, | 103 | end, |
| 104 | }) | 104 | }) |
| 105 | end, { desc = "Search Directory" }) | 105 | end, { desc = "Search Directory" }) |
| 106 | 106 | ||
| 107 | -- new terminals | 107 | -- new terminals |
| 108 | vim.keymap.set({ "n", "t" }, "<A-v>", function() | 108 | vim.keymap.set({ "n", "t" }, "<A-v>", function() |
| 109 | require("nvchad.term").toggle({ pos = "vsp", id = "vtoggleTerm" }) | 109 | require("nvchad.term").toggle({ pos = "vsp", id = "vtoggleTerm" }) |
| 110 | end, { desc = "terminal toggleable vertical term" }) | 110 | end, { desc = "terminal toggleable vertical term" }) |
| 111 | vim.keymap.set("t", "<C-x>", "<C-\\><C-N>", { desc = "terminal escape terminal mode" }) | 111 | vim.keymap.set("t", "<C-x>", "<C-\\><C-N>", { desc = "terminal escape terminal mode" }) |
| 112 | vim.keymap.set({ "t" }, "<A-e>", "<C-\\><C-N><C-W>|<C-W>_i", { desc = "terminal toggleable vertical term" }) | 112 | vim.keymap.set({ "t" }, "<A-e>", "<C-\\><C-N><C-W>|<C-W>_i", { desc = "terminal toggleable vertical term" }) |
| 113 | vim.keymap.set({ "n", "t" }, "<A-t>", function() | 113 | vim.keymap.set({ "n", "t" }, "<A-t>", function() |
| 114 | require("nvchad.term").toggle({ pos = "sp", id = "htoggleTerm" }) | 114 | require("nvchad.term").toggle({ pos = "sp", id = "htoggleTerm" }) |
| 115 | end, { desc = "terminal new horizontal term" }) | 115 | end, { desc = "terminal new horizontal term" }) |
| 116 | vim.keymap.set({ "n", "t" }, "<A-i>", function() | 116 | vim.keymap.set({ "n", "t" }, "<A-i>", function() |
| 117 | require("nvchad.term").toggle({ pos = "float", id = "floatTerm" }) | 117 | require("nvchad.term").toggle({ pos = "float", id = "floatTerm" }) |
| 118 | end, { desc = "terminal toggle floating term" }) | 118 | end, { desc = "terminal toggle floating term" }) |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | -- whichkey | 121 | -- whichkey |
| 122 | vim.keymap.set("n", "<leader>wK", "<cmd>WhichKey <CR>", { desc = "whichkey all keymaps" }) | 122 | vim.keymap.set("n", "<leader>sK", function() |
| 123 | vim.keymap.set("n", "<leader>wk", function() | 123 | vim.cmd("WhichKey " .. vim.fn.input("WhichKey: ")) |
| 124 | vim.cmd("WhichKey " .. vim.fn.input("WhichKey: ")) | ||
| 125 | end, { desc = "whichkey query lookup" }) | 124 | end, { desc = "whichkey query lookup" }) |
| 126 | 125 | ||
| 127 | 126 | ||
| 128 | -- blankline | 127 | -- blankline |
| 129 | vim.keymap.set("n", "<leader>cc", function() | 128 | vim.keymap.set("n", "<leader>cc", function() |
| 130 | local config = { scope = {} } | 129 | local config = { scope = {} } |
| 131 | config.scope.exclude = { language = {}, node_type = {} } | 130 | config.scope.exclude = { language = {}, node_type = {} } |
| 132 | config.scope.include = { node_type = {} } | 131 | config.scope.include = { node_type = {} } |
| 133 | local node = require("ibl.scope").get(vim.api.nvim_get_current_buf(), config) | 132 | local node = require("ibl.scope").get(vim.api.nvim_get_current_buf(), config) |
| 134 | 133 | ||
| 135 | if node then | 134 | if node then |
| 136 | local start_row, _, end_row, _ = node:range() | 135 | local start_row, _, end_row, _ = node:range() |
| 137 | if start_row ~= end_row then | 136 | if start_row ~= end_row then |
| 138 | vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start_row + 1, 0 }) | 137 | vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start_row + 1, 0 }) |
| 139 | vim.api.nvim_feedkeys("_", "n", true) | 138 | vim.api.nvim_feedkeys("_", "n", true) |
| 140 | end | 139 | end |
| 141 | end | 140 | end |
| 142 | end, { desc = "blankline jump to current context" }) | 141 | end, { desc = "blankline jump to current context" }) |
| 143 | 142 | ||
| 144 | 143 | ||
| @@ -150,7 +149,7 @@ vim.keymap.set("n", "<C-.>", ":HopChar1<CR>") | |||
| 150 | -- [ Aerial ]"" "<cmd>AerialNext<CR>", {}) | 149 | -- [ Aerial ]"" "<cmd>AerialNext<CR>", {}) |
| 151 | vim.keymap.set("n", "gL", "<cmd>Telescope aerial<CR>") | 150 | vim.keymap.set("n", "gL", "<cmd>Telescope aerial<CR>") |
| 152 | vim.keymap.set("n", "gl", function() | 151 | vim.keymap.set("n", "gl", function() |
| 153 | require("aerial").toggle({ direction = "left" }) | 152 | require("aerial").toggle({ direction = "left" }) |
| 154 | end) | 153 | end) |
| 155 | 154 | ||
| 156 | 155 | ||
| @@ -160,23 +159,23 @@ vim.keymap.set("n", "<leader>z", ":TZAtaraxis<CR>") | |||
| 160 | 159 | ||
| 161 | -- Use floating window for translation | 160 | -- Use floating window for translation |
| 162 | vim.keymap.set("v", "<leader><leader>tz", function() | 161 | vim.keymap.set("v", "<leader><leader>tz", function() |
| 163 | vim.cmd('norm o^zt"ty') | 162 | vim.cmd('norm o^zt"ty') |
| 164 | local translated_text = vim.fn.system("trans -t zh-TW -b", vim.fn.getreg("t")) | 163 | local translated_text = vim.fn.system("trans -t zh-TW -b", vim.fn.getreg("t")) |
| 165 | local lines = vim.split(translated_text, "\n") | 164 | local lines = vim.split(translated_text, "\n") |
| 166 | table.remove(lines) | 165 | table.remove(lines) |
| 167 | 166 | ||
| 168 | local new_buf = vim.api.nvim_create_buf(false, true) | 167 | local new_buf = vim.api.nvim_create_buf(false, true) |
| 169 | vim.api.nvim_buf_set_lines(new_buf, 0, -1, true, lines) | 168 | vim.api.nvim_buf_set_lines(new_buf, 0, -1, true, lines) |
| 170 | 169 | ||
| 171 | vim.api.nvim_open_win(new_buf, true, { | 170 | vim.api.nvim_open_win(new_buf, true, { |
| 172 | relative = "cursor", | 171 | relative = "cursor", |
| 173 | width = 80, | 172 | width = 80, |
| 174 | height = #lines, | 173 | height = #lines, |
| 175 | row = #lines, | 174 | row = #lines, |
| 176 | col = 0, | 175 | col = 0, |
| 177 | }) | 176 | }) |
| 178 | 177 | ||
| 179 | vim.cmd("setl nocul nonu nornu") | 178 | vim.cmd("setl nocul nonu nornu") |
| 180 | vim.cmd("hi ActiveWindow guibg=#2a5a6a guifg=White | setl winhighlight=Normal:ActiveWindow") | 179 | vim.cmd("hi ActiveWindow guibg=#2a5a6a guifg=White | setl winhighlight=Normal:ActiveWindow") |
| 181 | vim.cmd(":silent! %s/\\%x1b\\[[0-9;]*m//g") | 180 | vim.cmd(":silent! %s/\\%x1b\\[[0-9;]*m//g") |
| 182 | end, { desc = "Description" }) | 181 | end, { desc = "Description" }) |