diff options
Diffstat (limited to 'vim/lua')
| -rw-r--r-- | vim/lua/mappings.lua | 21 |
1 files changed, 6 insertions, 15 deletions
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", "<leader>pt", "<cmd>Telescope terms<CR>", { desc = "telescop | |||
| 54 | 54 | ||
| 55 | vim.keymap.set('n', '<leader>ss', function() | 55 | vim.keymap.set('n', '<leader>ss', function() |
| 56 | local current_filetype = vim.bo.filetype | 56 | local current_filetype = vim.bo.filetype |
| 57 | local cwd = os.getenv("HOME") .. '/snippets/' .. current_filetype | 57 | local cwd = os.getenv("HOME") .. '/snippets' |
| 58 | require('telescope.builtin').find_files { | 58 | require('telescope.builtin').find_files { |
| 59 | prompt_title = 'Select a snippet for ' .. current_filetype, | 59 | prompt_title = 'Select a snippet for ' .. current_filetype, |
| 60 | default_text = current_filetype .. "_", | ||
| 60 | cwd = cwd, | 61 | cwd = cwd, |
| 61 | attach_mappings = function(prompt_bufnr, map) | 62 | attach_mappings = function(prompt_bufnr, map) |
| 62 | local insert_selected_snippet = function() | 63 | local insert_selected_snippet = function() |
| @@ -95,20 +96,10 @@ vim.keymap.set('n', '<leader>sd', function() | |||
| 95 | end, { desc = 'Search Directory' }) | 96 | end, { desc = 'Search Directory' }) |
| 96 | 97 | ||
| 97 | vim.keymap.set('n', '<leader>sn', function() | 98 | vim.keymap.set('n', '<leader>sn', function() |
| 98 | vim.ui.input({ prompt = 'Snippet Name: ' }, function(snippet_path) | 99 | local current_filetype = vim.bo.filetype |
| 99 | local current_filetype | 100 | vim.ui.input({ prompt = 'Snippet Name: ', default = current_filetype .. "_" }, function(snippet) |
| 100 | local snippet | 101 | vim.cmd("cd ~/snippets") |
| 101 | if string.find(snippet_path, "/") then | 102 | vim.cmd("e " .. snippet) |
| 102 | current_filetype = string.match(snippet_path, "^(.-)/") | ||
| 103 | snippet = string.match(snippet_path, "/(.-)$") | ||
| 104 | else | ||
| 105 | current_filetype = vim.bo.filetype | ||
| 106 | snippet = snippet_path | ||
| 107 | end | ||
| 108 | local dir = os.getenv("HOME") .. '/snippets/' .. current_filetype | ||
| 109 | local path = dir .. '/' .. snippet | ||
| 110 | vim.cmd("!mkdir -p" .. dir) | ||
| 111 | vim.cmd("e " .. path) | ||
| 112 | vim.cmd("set filetype=" .. current_filetype) | 103 | vim.cmd("set filetype=" .. current_filetype) |
| 113 | vim.cmd("set filetype?") | 104 | vim.cmd("set filetype?") |
| 114 | end) | 105 | end) |