I know LuaSnip uses json snippets format, but where can I add new ones. If it is hard I maybe will get back to ultisnips. But at least I am asking you guys to give me ideas. Thanks!
I already have found something that seems like a reference: ~/.local/share/nvim/site/pack/packer/start/LuaSnip/Examples/snippets.lua
require("luasnip/loaders/from_vscode").lazy_load({paths = "~/.config/nvim/snippets/"}) -- You can pass { paths = "./my-snippets/"} as well
Now more research gave me
use {
'L3MON4D3/LuaSnip',
-- after = "nvim-cmp",
wants = "friendly-snippets",
-- after = "nvim-cmp",
config = function()
-- require'plugins.config.cmp'
-- require("luasnip/loaders/from_vscode").load()
require("luasnip/loaders/from_vscode").lazy_load({paths = "~/.config/nvim/snippets/"})
end
}
It sounds like you can either assign the snippet (as a Lua object) directly to the snippets or autosnippets table, or put JSON snippets in a directory and use lazy_load({paths = '...'} as you discovered.
-- Define some snippets
require("luasnip").snippets = {
-- Snippets for all filetypes
all = { ... }
-- Snippets for filetype=python
python = { ... }
}
-- Load snippets from JSON files (VSCode syntax)
require("luasnip/loaders/from_vscode").lazy_load({
paths = {
vim.fn.stdpath('config') .. '/snippets',
}
})
You could also do something more sophisticated with the paths, like finding allsnippets/*.json files anywhere in &runtimepath:
--[[ Split a string into lines. ]]
local function split_lines(txt)
return vim.fn.split(txt, '\n')
end
--[[ Find files in the runtime path. ]]
local function glob_runtimepath(pattern)
local runtime_path = vim.fn.escape(vim.o.runtimepath, ' ')
local search_result = vim.fn.globpath(runtime_path, pattern)
return split_lines(search_result)
end
require("luasnip/loaders/from_vscode").lazy_load({
paths = glob_runtimepath('snippets/**/*.json')
})