Snippets
This commit is contained in:
@@ -67,6 +67,7 @@ vim.api.nvim_create_autocmd({ 'User' }, {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
vim.api.nvim_create_autocmd('BufEnter', {
|
vim.api.nvim_create_autocmd('BufEnter', {
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
local windows = vim.api.nvim_list_wins()
|
local windows = vim.api.nvim_list_wins()
|
||||||
@@ -94,4 +95,15 @@ vim.api.nvim_create_autocmd('BufNewFile', {
|
|||||||
command = 'call feedkeys("i")',
|
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')
|
require('helpers').edit_cf('a', '/lua/autocmd.lua')
|
||||||
|
|||||||
@@ -178,4 +178,13 @@ end, { desc = 'Close test panels' })
|
|||||||
-- "A command to properly indent json code
|
-- "A command to properly indent json code
|
||||||
-- command! FormatJSON %!python -m json.tool
|
-- 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', '<Leader>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')
|
require('helpers').edit_cf('k', '/lua/keymap.lua')
|
||||||
|
|||||||
@@ -82,4 +82,6 @@ vim.opt.autowriteall = true
|
|||||||
-- Add lines at 80 and 120 columns
|
-- Add lines at 80 and 120 columns
|
||||||
vim.opt.colorcolumn = '80,120'
|
vim.opt.colorcolumn = '80,120'
|
||||||
|
|
||||||
|
vim.opt.iskeyword:remove '$'
|
||||||
|
|
||||||
require('helpers').edit_cf('o', '/lua/opt.lua')
|
require('helpers').edit_cf('o', '/lua/opt.lua')
|
||||||
|
|||||||
@@ -7,31 +7,7 @@ return {
|
|||||||
-- Compatibility for Avante with Blink (it typically only works with cmp)
|
-- Compatibility for Avante with Blink (it typically only works with cmp)
|
||||||
-- 'Kaiser-Yang/blink-cmp-avante',
|
-- 'Kaiser-Yang/blink-cmp-avante',
|
||||||
-- Snippet Engine
|
-- Snippet Engine
|
||||||
{
|
|
||||||
'L3MON4D3/LuaSnip',
|
'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 = {},
|
|
||||||
},
|
|
||||||
'folke/lazydev.nvim',
|
'folke/lazydev.nvim',
|
||||||
},
|
},
|
||||||
--- @module 'blink.cmp'
|
--- @module 'blink.cmp'
|
||||||
|
|||||||
31
lua/plugins/snippets.lua
Normal file
31
lua/plugins/snippets.lua
Normal file
@@ -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 = {},
|
||||||
|
}
|
||||||
1
lua/snippets/all.json
Normal file
1
lua/snippets/all.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
9
lua/snippets/javascript-vue.json
Normal file
9
lua/snippets/javascript-vue.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Log function": {
|
||||||
|
"prefix": "du",
|
||||||
|
"body": [
|
||||||
|
"console.log($0);"
|
||||||
|
],
|
||||||
|
"description": "Log variable"
|
||||||
|
}
|
||||||
|
}
|
||||||
26
lua/snippets/package.json
Normal file
26
lua/snippets/package.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
17
lua/snippets/php.json
Normal file
17
lua/snippets/php.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"Create doc block": {
|
||||||
|
"prefix": "/**",
|
||||||
|
"body": [
|
||||||
|
"/**",
|
||||||
|
" * $0",
|
||||||
|
" */"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Dump function": {
|
||||||
|
"prefix": "du",
|
||||||
|
"body": [
|
||||||
|
"dump($0);"
|
||||||
|
],
|
||||||
|
"description": "Dump variable"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user