From d415bbb33a1c2a3f9a2492668b57c4db0098ef1d Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 26 Jun 2024 00:14:19 +0800 Subject: Update --- vim/lua/mappings.lua | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'vim/lua') diff --git a/vim/lua/mappings.lua b/vim/lua/mappings.lua index 401c0f8..45c44ec 100644 --- a/vim/lua/mappings.lua +++ b/vim/lua/mappings.lua @@ -54,9 +54,10 @@ vim.keymap.set("n", "pt", "Telescope terms", { desc = "telescop vim.keymap.set('n', 'ss', function() local current_filetype = vim.bo.filetype - local cwd = os.getenv("HOME") .. '/snippets/' .. current_filetype + local cwd = os.getenv("HOME") .. '/snippets' require('telescope.builtin').find_files { prompt_title = 'Select a snippet for ' .. current_filetype, + default_text = current_filetype .. "_", cwd = cwd, attach_mappings = function(prompt_bufnr, map) local insert_selected_snippet = function() @@ -95,20 +96,10 @@ vim.keymap.set('n', 'sd', function() end, { desc = 'Search Directory' }) vim.keymap.set('n', 'sn', function() - vim.ui.input({ prompt = 'Snippet Name: ' }, function(snippet_path) - local current_filetype - local snippet - if string.find(snippet_path, "/") then - current_filetype = string.match(snippet_path, "^(.-)/") - snippet = string.match(snippet_path, "/(.-)$") - else - current_filetype = vim.bo.filetype - snippet = snippet_path - end - local dir = os.getenv("HOME") .. '/snippets/' .. current_filetype - local path = dir .. '/' .. snippet - vim.cmd("!mkdir -p" .. dir) - vim.cmd("e " .. path) + local current_filetype = vim.bo.filetype + vim.ui.input({ prompt = 'Snippet Name: ', default = current_filetype .. "_" }, function(snippet) + vim.cmd("cd ~/snippets") + vim.cmd("e " .. snippet) vim.cmd("set filetype=" .. current_filetype) vim.cmd("set filetype?") end) -- cgit v1.2.3-70-g09d2