diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-07-17 20:56:34 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-07-17 20:56:34 +0800 |
commit | ea39a52497685c4f6ca89a467fc88c63a6d86bd3 (patch) | |
tree | 254a1f3277ad1bd010991983a94e27e90ec623e4 /vim | |
parent | 7c9f39515e87544b1b86508e9367cb739545ff03 (diff) |
Update
Diffstat (limited to 'vim')
-rw-r--r-- | vim/init/keymaps.vim | 12 | ||||
-rw-r--r-- | vim/lua/chadrc.lua | 108 | ||||
-rw-r--r-- | vim/mini.lua | 306 |
3 files changed, 337 insertions, 89 deletions
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index aefb337..82c3c07 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim | |||
@@ -50,7 +50,7 @@ map <leader>pp :setlocal paste!<CR> | |||
50 | 50 | ||
51 | " Copy from system clipboard | 51 | " Copy from system clipboard |
52 | nnoremap <leader>P :r !xsel -ob<CR> | 52 | nnoremap <leader>P :r !xsel -ob<CR> |
53 | vnoremap Y :w !xsel -ib<CR> | 53 | vnoremap Y "+y |
54 | 54 | ||
55 | " Move one line up and down | 55 | " Move one line up and down |
56 | nnoremap <C-j> ddp | 56 | nnoremap <C-j> ddp |
@@ -81,6 +81,8 @@ nnoremap <leader>S [s | |||
81 | " Show full path by default | 81 | " Show full path by default |
82 | nnoremap <C-g> 1<C-g> | 82 | nnoremap <C-g> 1<C-g> |
83 | 83 | ||
84 | nnoremap S S<ESC> | ||
85 | |||
84 | " Translate by Google API | 86 | " Translate by Google API |
85 | vnoremap Tz :!trans -t zh-TW -b<CR> | 87 | vnoremap Tz :!trans -t zh-TW -b<CR> |
86 | vnoremap Te :!trans -t en-US -b<CR> | 88 | vnoremap Te :!trans -t en-US -b<CR> |
@@ -478,14 +480,14 @@ vnoremap ` <ESC>`<i`<ESC>`>la`<ESC> | |||
478 | vnoremap Q <ESC>`<i「<ESC>`>la」<ESC> | 480 | vnoremap Q <ESC>`<i「<ESC>`>la」<ESC> |
479 | 481 | ||
480 | function! AddSpaceForSelection() | 482 | function! AddSpaceForSelection() |
481 | if line("'<") == line("'>") | 483 | if line("'<") != line("'>") || (col("'<") == 1 && col("'>") == len(getline('.'))+1) |
484 | '< norm! O | ||
485 | '> norm! o | ||
486 | else | ||
482 | call cursor('.', col("'<")) | 487 | call cursor('.', col("'<")) |
483 | execute "norm! i\<space>" | 488 | execute "norm! i\<space>" |
484 | call cursor('.', col("'>")+1) | 489 | call cursor('.', col("'>")+1) |
485 | execute "norm! a\<space>" | 490 | execute "norm! a\<space>" |
486 | else | ||
487 | '< norm! O | ||
488 | '> norm! o | ||
489 | endif | 491 | endif |
490 | endfunction | 492 | endfunction |
491 | vnoremap <space> :<C-u>call AddSpaceForSelection()<CR> | 493 | vnoremap <space> :<C-u>call AddSpaceForSelection()<CR> |
diff --git a/vim/lua/chadrc.lua b/vim/lua/chadrc.lua index 4b65f52..182ed96 100644 --- a/vim/lua/chadrc.lua +++ b/vim/lua/chadrc.lua | |||
@@ -5,68 +5,68 @@ | |||
5 | local M = {} | 5 | local M = {} |
6 | 6 | ||
7 | M.ui = { | 7 | M.ui = { |
8 | theme = "onedark", | 8 | theme = "onedark", |
9 | hl_override = { | 9 | hl_override = { |
10 | CursorLineNr = { fg = "#eeee00" }, | 10 | CursorLineNr = { fg = "#eeee00" }, |
11 | }, | 11 | }, |
12 | 12 | ||
13 | -- hl_override = { | 13 | -- hl_override = { |
14 | -- Comment = { italic = true }, | 14 | -- Comment = { italic = true }, |
15 | -- ["@comment"] = { italic = true }, | 15 | -- ["@comment"] = { italic = true }, |
16 | -- }, | 16 | -- }, |
17 | tabufline = { | 17 | tabufline = { |
18 | enabled = true, | 18 | enabled = true, |
19 | order = { "treeOffset", "buffers", "tabs" }, | 19 | order = { "treeOffset", "buffers", "tabs" }, |
20 | }, | 20 | }, |
21 | 21 | ||
22 | term = { | 22 | term = { |
23 | hl = "Normal:term,WinSeparator:WinSeparator", | 23 | hl = "Normal:term,WinSeparator:WinSeparator", |
24 | sizes = { sp = 0.4, vsp = 0.4 }, | 24 | sizes = { sp = 0.4, vsp = 0.4 }, |
25 | float = { | 25 | float = { |
26 | relative = "editor", | 26 | relative = "editor", |
27 | row = 0.15, | 27 | row = 0.15, |
28 | col = 0.13, | 28 | col = 0.13, |
29 | width = 0.7, | 29 | width = 0.7, |
30 | height = 0.7, | 30 | height = 0.7, |
31 | border = "single", | 31 | border = "single", |
32 | }, | 32 | }, |
33 | }, | 33 | }, |
34 | } | 34 | } |
35 | 35 | ||
36 | -- For tabufline | 36 | -- For tabufline |
37 | if M.ui.tabufline.enabled then | 37 | if M.ui.tabufline.enabled then |
38 | vim.api.nvim_exec( | 38 | vim.api.nvim_exec( |
39 | [[ | 39 | [[ |
40 | function! CloseBufferSafely() | 40 | function! CloseBufferSafely() |
41 | lua require("nvchad.tabufline").close_buffer() | 41 | lua require("nvchad.tabufline").close_buffer() |
42 | endfunction | 42 | endfunction |
43 | ]], | 43 | ]], |
44 | false | 44 | false |
45 | ) | 45 | ) |
46 | 46 | ||
47 | for i = 1, 9, 1 do | 47 | for i = 1, 9, 1 do |
48 | vim.keymap.set("n", string.format("<A-%s>", i), function() | 48 | vim.keymap.set("n", string.format("<A-%s>", i), function() |
49 | vim.api.nvim_set_current_buf(vim.t.bufs[i]) | 49 | vim.api.nvim_set_current_buf(vim.t.bufs[i]) |
50 | end) | 50 | end) |
51 | end | 51 | end |
52 | vim.keymap.set("n", "<A-h>", function() | 52 | vim.keymap.set("n", "<A-h>", function() |
53 | require("nvchad.tabufline").move_buf(-1) | 53 | require("nvchad.tabufline").move_buf(-1) |
54 | end) | 54 | end) |
55 | vim.keymap.set("n", "<A-l>", function() | 55 | vim.keymap.set("n", "<A-l>", function() |
56 | require("nvchad.tabufline").move_buf(1) | 56 | require("nvchad.tabufline").move_buf(1) |
57 | end) | 57 | end) |
58 | vim.keymap.set("n", "<A-H>", function() | 58 | vim.keymap.set("n", "<A-H>", function() |
59 | vim.cmd("tabprevious") | 59 | vim.cmd("tabprevious") |
60 | end) | 60 | end) |
61 | vim.keymap.set("n", "<A-L>", function() | 61 | vim.keymap.set("n", "<A-L>", function() |
62 | vim.cmd("tabnext") | 62 | vim.cmd("tabnext") |
63 | end) | 63 | end) |
64 | vim.keymap.set("n", "<tab>", function() | 64 | vim.keymap.set("n", "<tab>", function() |
65 | require("nvchad.tabufline").next() | 65 | require("nvchad.tabufline").next() |
66 | end, { desc = "buffer goto next" }) | 66 | end, { desc = "buffer goto next" }) |
67 | vim.keymap.set("n", "<S-tab>", function() | 67 | vim.keymap.set("n", "<S-tab>", function() |
68 | require("nvchad.tabufline").prev() | 68 | require("nvchad.tabufline").prev() |
69 | end, { desc = "buffer goto prev" }) | 69 | end, { desc = "buffer goto prev" }) |
70 | end | 70 | end |
71 | 71 | ||
72 | return M | 72 | return M |
diff --git a/vim/mini.lua b/vim/mini.lua index 1f4ee45..2646ca6 100644 --- a/vim/mini.lua +++ b/vim/mini.lua | |||
@@ -1,10 +1,15 @@ | |||
1 | -- vim: foldmethod=marker foldmarker={{{,}}} | 1 | -- vim: sw=2 foldmethod=marker foldmarker={{{,}}} |
2 | |||
3 | -- Ref: https://github.com/echasnovski/mini.nvim?tab=readme-ov-file | ||
4 | -- TODO | ||
5 | |||
6 | -- Install mini.nvim {{{ | ||
2 | 7 | ||
3 | -- Install mini.nvim -{{{ | ||
4 | -- Put this at the top of 'init.lua' | 8 | -- Put this at the top of 'init.lua' |
5 | local path_package = vim.fn.stdpath('data') .. '/site' | 9 | local path_package = vim.fn.stdpath('data') .. '/site' |
6 | vim.o.packpath=path_package | 10 | vim.o.packpath = path_package |
7 | local mini_path = path_package .. '/pack/deps/start/mini.nvim' | 11 | local mini_path = path_package .. '/pack/deps/start/mini.nvim' |
12 | |||
8 | if not vim.loop.fs_stat(mini_path) then | 13 | if not vim.loop.fs_stat(mini_path) then |
9 | vim.cmd('echo "Installing `mini.nvim`" | redraw') | 14 | vim.cmd('echo "Installing `mini.nvim`" | redraw') |
10 | local clone_cmd = { | 15 | local clone_cmd = { |
@@ -16,8 +21,27 @@ if not vim.loop.fs_stat(mini_path) then | |||
16 | vim.fn.system(clone_cmd) | 21 | vim.fn.system(clone_cmd) |
17 | vim.cmd('packadd mini.nvim | helptags ALL') | 22 | vim.cmd('packadd mini.nvim | helptags ALL') |
18 | end | 23 | end |
24 | |||
25 | -- }}} | ||
26 | -- mini.deps {{{ | ||
27 | require('mini.deps').setup({ | ||
28 | path = { package = path_package } | ||
29 | }) | ||
30 | add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later | ||
31 | -- }}} | ||
32 | -- Disabled: mini.bufremote {{{ | ||
33 | add('echasnovski/mini.bufremove') | ||
34 | vim.g.bufremove_disable = true | ||
35 | --}}} | ||
36 | -- Disabled: mini.animate --{{{ | ||
37 | add('echasnovski/mini.animate') | ||
38 | vim.g.animate_disable = true | ||
39 | -- }}} | ||
40 | -- mini.basics {{{ | ||
41 | require('mini.basics').setup() | ||
19 | -- }}} | 42 | -- }}} |
20 | require('mini.base16').setup({ --{{{ | 43 | -- mini.base16 {{{ |
44 | require('mini.base16').setup({ | ||
21 | palette = { | 45 | palette = { |
22 | -- Default Background | 46 | -- Default Background |
23 | base00 = "#2d2a2e", | 47 | base00 = "#2d2a2e", |
@@ -54,10 +78,15 @@ require('mini.base16').setup({ --{{{ | |||
54 | }, | 78 | }, |
55 | use_cterm = true, | 79 | use_cterm = true, |
56 | }) --}}} | 80 | }) --}}} |
57 | require('mini.misc').setup({ --{{{ | 81 | -- mini.misc {{{ |
82 | require('mini.misc').setup({ | ||
58 | make_global = { 'put', 'put_text', 'zoom'} | 83 | make_global = { 'put', 'put_text', 'zoom'} |
59 | }) --}}} | 84 | }) --}}} |
60 | require('mini.statusline').setup({--{{{ | 85 | -- mini.icons {{{ |
86 | require('mini.icons').setup({ | ||
87 | }) --}}} | ||
88 | -- mini.statusline {{{ | ||
89 | require('mini.statusline').setup({ | ||
61 | content = { | 90 | content = { |
62 | active = status_config | 91 | active = status_config |
63 | }, | 92 | }, |
@@ -84,27 +113,21 @@ function status_config() | |||
84 | local location = MiniStatusline.section_location({ trunc_width = 75 }) | 113 | local location = MiniStatusline.section_location({ trunc_width = 75 }) |
85 | 114 | ||
86 | return MiniStatusline.combine_groups({ | 115 | return MiniStatusline.combine_groups({ |
87 | { hl = mode_hl, strings = { mode } }, | 116 | { hl = mode_hl, strings = { mode } }, |
88 | { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics['s'] } }, | 117 | { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics['s'] } }, |
89 | { hl = 'MiniStatuslineError', strings = { diagnostics['e'] } }, | 118 | { hl = 'MiniStatuslineError', strings = { diagnostics['e'] } }, |
90 | { hl = 'MiniStatuslineWarning', strings = { diagnostics['w'] } }, | 119 | { hl = 'MiniStatuslineWarning', strings = { diagnostics['w'] } }, |
91 | { hl = 'MiniStatuslineInfo', strings = { diagnostics['i'] } }, | 120 | { hl = 'MiniStatuslineInfo', strings = { diagnostics['i'] } }, |
92 | { hl = 'MiniStatuslineHint', strings = { diagnostics['h'] } }, | 121 | { hl = 'MiniStatuslineHint', strings = { diagnostics['h'] } }, |
93 | '%<', -- Mark general truncate point | 122 | '%<', -- Mark general truncate point |
94 | { hl = 'MiniStatuslineFilename', strings = { filename } }, | 123 | { hl = 'MiniStatuslineFilename', strings = { filename } }, |
95 | '%=', -- End left alignment | 124 | '%=', -- End left alignment |
96 | { hl = 'MiniStatuslineFileinfo', strings = { fileinfo } }, | 125 | { hl = 'MiniStatuslineFileinfo', strings = { fileinfo } }, |
97 | { hl = mode_hl, strings = { location } }, | 126 | { hl = mode_hl, strings = { location } }, |
98 | }) | 127 | }) |
99 | end | 128 | end |
100 | -- }}} | 129 | -- }}} |
101 | require('mini.animate').setup()--{{{ | 130 | -- mini.clue {{{ |
102 | -- }}} | ||
103 | require('mini.basics').setup()--{{{ | ||
104 | -- }}} | ||
105 | -- require('mini.bufremove').setup() --{{{ | ||
106 | --}}} | ||
107 | require('mini.clue') --{{{ | ||
108 | local miniclue = require('mini.clue') | 131 | local miniclue = require('mini.clue') |
109 | miniclue.setup({ | 132 | miniclue.setup({ |
110 | triggers = { | 133 | triggers = { |
@@ -149,10 +172,12 @@ miniclue.setup({ | |||
149 | miniclue.gen_clues.z(), | 172 | miniclue.gen_clues.z(), |
150 | }, | 173 | }, |
151 | })-- }}} | 174 | })-- }}} |
152 | require('mini.colors').setup()-- {{{ | 175 | -- mini.colors {{{ |
176 | require('mini.colors').setup() | ||
153 | -- }}} | 177 | -- }}} |
154 | require('mini.comment').setup({-- {{{ | 178 | -- mini.comment {{{ |
155 | -- Module mappings. Use `''` (empty string) to disable one. | 179 | require('mini.comment').setup({ |
180 | -- Module mappings. Use `''` (empty string) to disable one. | ||
156 | mappings = { | 181 | mappings = { |
157 | -- Toggle comment (like `gcip` - comment inner paragraph) for both | 182 | -- Toggle comment (like `gcip` - comment inner paragraph) for both |
158 | -- Normal and Visual modes | 183 | -- Normal and Visual modes |
@@ -169,9 +194,230 @@ require('mini.comment').setup({-- {{{ | |||
169 | textobject = 'gc', | 194 | textobject = 'gc', |
170 | }, | 195 | }, |
171 | })-- }}} | 196 | })-- }}} |
172 | require('mini.cursorword').setup()-- {{{ | 197 | -- mini.cursorword {{{ |
198 | require('mini.cursorword').setup() | ||
199 | -- }}} | ||
200 | -- mini.diff {{{ | ||
201 | require('mini.diff').setup({ | ||
202 | -- Options for how hunks are visualized | ||
203 | view = { | ||
204 | -- Visualization style. Possible values are 'sign' and 'number'. | ||
205 | -- Default: 'number' if line numbers are enabled, 'sign' otherwise. | ||
206 | style = 'sign', | ||
207 | |||
208 | -- Signs used for hunks with 'sign' view | ||
209 | signs = { add = '+', change = '▒', delete = '-' }, | ||
210 | |||
211 | -- Priority of used visualization extmarks | ||
212 | priority = 199, | ||
213 | }, | ||
214 | }) | ||
215 | -- }}} | ||
216 | -- mini.extra {{{ | ||
217 | require('mini.extra').setup() | ||
218 | -- }}} | ||
219 | -- mini.map {{{ | ||
220 | require('mini.map').setup() | ||
221 | -- }}} | ||
222 | -- mini.tabline {{{ | ||
223 | |||
224 | require('mini.tabline').setup() | ||
225 | |||
226 | for i = 1, 9, 1 do | ||
227 | vim.keymap.set("n", string.format("<A-%s>", i), function() | ||
228 | vim.api.nvim_set_current_buf(vim.t.bufs[i]) | ||
229 | end) | ||
230 | end | ||
231 | |||
173 | -- }}} | 232 | -- }}} |
174 | require('mini.cursorword').setup()-- {{{ | 233 | -- mini.visits {{{ |
234 | require('mini.visits').setup() | ||
175 | -- }}} | 235 | -- }}} |
176 | require('mini.diff').setup()-- {{{ | 236 | -- mini.completion {{{ |
237 | require('mini.completion').setup() | ||
177 | -- }}} | 238 | -- }}} |
239 | -- Telescope {{{ | ||
240 | add({ | ||
241 | source = "nvim-telescope/telescope.nvim", | ||
242 | depends = { | ||
243 | 'nvim-lua/plenary.nvim', | ||
244 | }, | ||
245 | hooks = { post_checkout = function() end }, | ||
246 | }) | ||
247 | -- add({ | ||
248 | -- source = 'nvim-telescope/telescope-fzf-native.nvim', | ||
249 | -- hooks = { post_checkout = function() | ||
250 | -- vim.fn.system('make') | ||
251 | -- end }, | ||
252 | -- }) | ||
253 | -- config {{{ | ||
254 | require('telescope').setup({ | ||
255 | defaults = {-- {{{ | ||
256 | mappings = { | ||
257 | i = { | ||
258 | -- ["<c-j>"] = "move_selection_next", | ||
259 | -- ["<c-k>"] = "move_selection_previous", | ||
260 | ["<C-o>"] = require("telescope.actions.layout").toggle_preview, | ||
261 | ["<C-u>"] = false, | ||
262 | ["<C-q>"] = function(p_bufnr) | ||
263 | require("telescope.actions").send_selected_to_qflist(p_bufnr) | ||
264 | vim.cmd.cfdo("edit") | ||
265 | end, | ||
266 | }, | ||
267 | }, | ||
268 | layout_config = { | ||
269 | horizontal = { | ||
270 | prompt_position = "bottom", | ||
271 | }, | ||
272 | vertical = { height = 0.8 }, | ||
273 | -- other layout configuration here | ||
274 | preview_cutoff = 0, | ||
275 | }, | ||
276 | file_ignore_patterns = { | ||
277 | "node_modules" | ||
278 | }, | ||
279 | },-- }}} | ||
280 | pickers = {-- {{{ | ||
281 | buffers = { | ||
282 | show_all_buffers = true, | ||
283 | sort_lastused = true, | ||
284 | theme = "dropdown", | ||
285 | previewer = false, | ||
286 | mappings = { | ||
287 | i = { | ||
288 | ["<c-d>"] = "delete_buffer", | ||
289 | }, | ||
290 | n = { | ||
291 | ["<c-d>"] = "delete_buffer", | ||
292 | } | ||
293 | }, | ||
294 | }, | ||
295 | },-- }}} | ||
296 | extensions = { | ||
297 | fzf = { | ||
298 | fuzzy = true, -- false will only do exact matching | ||
299 | override_generic_sorter = true, -- override the generic sorter | ||
300 | override_file_sorter = true, -- override the file sorter | ||
301 | case_mode = "smart_case", -- or "ignore_case" or "respect_case" | ||
302 | -- the default case_mode is "smart_case" | ||
303 | }, | ||
304 | aerial = { | ||
305 | -- Display symbols as <root>.<parent>.<symbol> | ||
306 | show_nesting = { | ||
307 | ["_"] = false, -- This key will be the default | ||
308 | json = true, -- You can set the option for specific filetypes | ||
309 | yaml = true, | ||
310 | }, | ||
311 | }, | ||
312 | }, | ||
313 | }) | ||
314 | -- }}} | ||
315 | -- require("telescope").load_extension("fzf") | ||
316 | -- require("telescope").load_extension("aerial") | ||
317 | |||
318 | -- Keymaps {{{ | ||
319 | vim.keymap.set("n", "<leader>f", "<cmd>Telescope oldfiles<CR>", { desc = "telescope find oldfiles" }) | ||
320 | vim.keymap.set("n", "<leader>b", "<cmd>Telescope buffers<CR>", { desc = "telescope find buffers" }) | ||
321 | vim.keymap.set("n", "//", "<cmd>Telescope current_buffer_fuzzy_find<CR>", { desc = "telescope find in current buffer" }) | ||
322 | vim.keymap.set("n", "<leader>sf", "<cmd>Telescope find_files<cr>", { desc = "telescope find files" }) | ||
323 | vim.keymap.set( | ||
324 | "n", | ||
325 | "<leader>sF", | ||
326 | "<cmd>Telescope find_files follow=true no_ignore=true hidden=true<CR>", | ||
327 | { desc = "telescope find all files" } | ||
328 | ) | ||
329 | vim.keymap.set("n", "<leader>sg", "<cmd>Telescope live_grep<CR>", { desc = "telescope live grep" }) | ||
330 | vim.keymap.set("n", "<leader>gf", "<cmd>Telescope git_files<CR>", { desc = "telescope git files" }) | ||
331 | vim.keymap.set("n", "<leader>sH", "<cmd>Telescope help_tags<CR>", { desc = "telescope help page" }) | ||
332 | vim.keymap.set("n", "<leader>sm", "<cmd>Telescope marks<CR>", { desc = "telescope marks" }) | ||
333 | vim.keymap.set("n", "<leader>sj", "<cmd>Telescope jumplist<CR>", { desc = "telescope marks" }) | ||
334 | vim.keymap.set("n", "<leader>tt", "<cmd>Telescope<CR>", { desc = "telescope help page" }) | ||
335 | vim.keymap.set("n", "<leader>sk", "<cmd>Telescope keymaps<CR>", { desc = "telescope keymaps" }) | ||
336 | vim.keymap.set("n", "<leader>pt", "<cmd>Telescope terms<CR>", { desc = "telescope pick hidden term" }) | ||
337 | |||
338 | vim.keymap.set("n", "<leader>ss", function() | ||
339 | local current_filetype = vim.bo.filetype | ||
340 | local cwd = os.getenv("HOME") .. "/snippets" | ||
341 | require("telescope.builtin").find_files({ | ||
342 | prompt_title = "Press <C-T> to edit a snippet", | ||
343 | default_text = current_filetype == "" and "" or current_filetype .. "_", | ||
344 | cwd = cwd, | ||
345 | attach_mappings = function(prompt_bufnr, map) | ||
346 | local get_prompt_or_entry = function() | ||
347 | local file_list = require("telescope.actions.state").get_selected_entry() | ||
348 | if file_list then | ||
349 | return file_list[1] | ||
350 | else | ||
351 | local current_picker = require("telescope.actions.state").get_current_picker(prompt_bufnr) | ||
352 | return current_picker:_get_prompt() | ||
353 | end | ||
354 | end | ||
355 | |||
356 | local edit_snippet = function() | ||
357 | local file = get_prompt_or_entry() | ||
358 | require("telescope.actions").close(prompt_bufnr) | ||
359 | local prefix_filetype = string.match(file, "([^_]+)") | ||
360 | vim.cmd(":vs") | ||
361 | vim.cmd(":e " .. cwd .. "/" .. file) | ||
362 | vim.bo.filetype = prefix_filetype | ||
363 | vim.bo.bufhidden = "wipe" | ||
364 | vim.cmd("set filetype?") | ||
365 | end | ||
366 | |||
367 | local insert_selected_snippet = function() | ||
368 | local file = get_prompt_or_entry() | ||
369 | local path = cwd .. "/" .. file | ||
370 | if vim.fn.filereadable(path) ~= 0 then | ||
371 | local snippet_content = vim.fn.readfile(path) | ||
372 | require("telescope.actions").close(prompt_bufnr) | ||
373 | vim.fn.setreg('"', snippet_content) | ||
374 | print("Snippet saved to register") | ||
375 | else | ||
376 | edit_snippet() | ||
377 | end | ||
378 | end | ||
379 | |||
380 | map("i", "<CR>", insert_selected_snippet) | ||
381 | map("i", "<C-T>", edit_snippet) | ||
382 | map("n", "<CR>", insert_selected_snippet) | ||
383 | |||
384 | return true | ||
385 | end, | ||
386 | }) | ||
387 | end, { desc = "[S]earch [S]nippets" }) | ||
388 | |||
389 | vim.keymap.set("n", "<leader>sd", function() | ||
390 | require("telescope.builtin").oldfiles({ | ||
391 | prompt_title = "CD to", | ||
392 | attach_mappings = function(prompt_bufnr, map) | ||
393 | local cd_prompt = function() | ||
394 | local file = require("telescope.actions.state").get_selected_entry()[1] | ||
395 | local path = string.match(file, "(.*[/\\])") | ||
396 | require("telescope.actions").close(prompt_bufnr) | ||
397 | vim.api.nvim_feedkeys(":cd " .. path, "n", true) | ||
398 | end | ||
399 | |||
400 | map("i", "<CR>", cd_prompt) | ||
401 | map("n", "<CR>", cd_prompt) | ||
402 | |||
403 | return true | ||
404 | end, | ||
405 | }) | ||
406 | end, { desc = "Search Directory" })-- }}} | ||
407 | |||
408 | -- }}} | ||
409 | -- toggleterm {{{ | ||
410 | |||
411 | add({ | ||
412 | source = "akinsho/toggleterm.nvim", | ||
413 | hooks = { post_checkout = function() end }, | ||
414 | }) | ||
415 | require("toggleterm").setup{ | ||
416 | persist_size = false, | ||
417 | direction = 'float', | ||
418 | } | ||
419 | |||
420 | vim.keymap.set({ "n", "t" }, "<A-i>", function() vim.cmd("ToggleTerm direction=float") end, { desc = "terminal toggle floating term" }) | ||
421 | vim.keymap.set({ "n", "t" }, "<A-v>", function() vim.cmd("ToggleTerm direction=horizontal") end, { desc = "terminal toggle floating term" }) | ||
422 | |||
423 | --}}} | ||