diff --git a/lua/autocmd.lua b/lua/autocmd.lua index c6389a2..6ea4bd6 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -67,6 +67,7 @@ vim.api.nvim_create_autocmd({ 'User' }, { end, }) +<<<<<<< HEAD vim.api.nvim_create_autocmd('BufEnter', { callback = function(event) local windows = vim.api.nvim_list_wins() @@ -94,4 +95,15 @@ vim.api.nvim_create_autocmd('BufNewFile', { command = 'call feedkeys("i")', }) +-- Reload LuaSnip snippets when saving files in the snippets directory +local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets' +vim.api.nvim_create_autocmd('BufWritePost', { + pattern = snippets_dir .. '/*.json', -- Adjust the path to match your snippets directory + desc = 'Reload LuaSnip snippets on save', + callback = function() + require('luasnip.loaders.from_vscode').lazy_load { paths = { snippets_dir } } + vim.notify('Snippets reloaded!', vim.log.levels.INFO) + end, +}) + require('helpers').edit_cf('a', '/lua/autocmd.lua') diff --git a/lua/keymap.lua b/lua/keymap.lua index 13baeb1..bee604a 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -178,4 +178,13 @@ end, { desc = 'Close test panels' }) -- "A command to properly indent json code -- command! FormatJSON %!python -m json.tool +-- Edit the snippet file for the current buffer filetype or the snippets +-- directory if the file does not exist +vim.keymap.set('n', 'es', function() + local ft = vim.bo.filetype + local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets' + local snippets_file = snippets_dir .. '/' .. ft .. '.json' + vim.cmd('tabedit ' .. snippets_file) +end, { desc = 'Edit snippets file' }) + require('helpers').edit_cf('k', '/lua/keymap.lua') diff --git a/lua/opt.lua b/lua/opt.lua index 8b6e711..15f8466 100644 --- a/lua/opt.lua +++ b/lua/opt.lua @@ -82,4 +82,6 @@ vim.opt.autowriteall = true -- Add lines at 80 and 120 columns vim.opt.colorcolumn = '80,120' +vim.opt.iskeyword:remove '$' + require('helpers').edit_cf('o', '/lua/opt.lua') diff --git a/lua/plugins/blink.lua b/lua/plugins/blink.lua index 8b3b0c4..f9d50d8 100644 --- a/lua/plugins/blink.lua +++ b/lua/plugins/blink.lua @@ -7,31 +7,7 @@ return { -- Compatibility for Avante with Blink (it typically only works with cmp) -- 'Kaiser-Yang/blink-cmp-avante', -- Snippet Engine - { - 'L3MON4D3/LuaSnip', - version = '2.*', - build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then - return - end - return 'make install_jsregexp' - end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - { - 'rafamadriz/friendly-snippets', - config = function() - require('luasnip.loaders.from_vscode').lazy_load() - end, - }, - }, - opts = {}, - }, + 'L3MON4D3/LuaSnip', 'folke/lazydev.nvim', }, --- @module 'blink.cmp' diff --git a/lua/plugins/snippets.lua b/lua/plugins/snippets.lua new file mode 100644 index 0000000..30f5a6c --- /dev/null +++ b/lua/plugins/snippets.lua @@ -0,0 +1,31 @@ +return { + 'L3MON4D3/LuaSnip', + version = '2.*', + build = (function() + -- Build Step is needed for regex support in snippets. + -- This step is not supported in many windows environments. + -- Remove the below condition to re-enable on windows. + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end + return 'make install_jsregexp' + end)(), + config = function() + local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets' + require('luasnip.loaders.from_vscode').lazy_load { + paths = { snippets_dir }, + } + end, + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, + }, + opts = {}, +} diff --git a/lua/snippets/all.json b/lua/snippets/all.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/lua/snippets/all.json @@ -0,0 +1 @@ +{} diff --git a/lua/snippets/javascript-vue.json b/lua/snippets/javascript-vue.json new file mode 100644 index 0000000..e331a1f --- /dev/null +++ b/lua/snippets/javascript-vue.json @@ -0,0 +1,9 @@ +{ + "Log function": { + "prefix": "du", + "body": [ + "console.log($0);" + ], + "description": "Log variable" + } +} diff --git a/lua/snippets/package.json b/lua/snippets/package.json new file mode 100644 index 0000000..d9d5fa8 --- /dev/null +++ b/lua/snippets/package.json @@ -0,0 +1,26 @@ +{ + "name": "example-snippets", + "contributes": { + "snippets": [ + { + "language": [ + "all" + ], + "path": "./snippets/all.json" + }, + { + "language": [ + "php" + ], + "path": "./php.json" + }, + { + "language": [ + "javascript", + "vue" + ], + "path": "./javascript-vue.json" + } + ] + } +} diff --git a/lua/snippets/php.json b/lua/snippets/php.json new file mode 100644 index 0000000..8b1cf74 --- /dev/null +++ b/lua/snippets/php.json @@ -0,0 +1,17 @@ +{ + "Create doc block": { + "prefix": "/**", + "body": [ + "/**", + " * $0", + " */" + ] + }, + "Dump function": { + "prefix": "du", + "body": [ + "dump($0);" + ], + "description": "Dump variable" + } +}