There are several cases where this plugin comes in handy:
Other reasons may include:
SnippetConverter can convert snippets between the following formats:
Is there any other snippet engine or custom format that you think should be supported? Let me know by creating an issue!
To get started, pass a Lua table with a list of templates to the setup
function. A template must contain
sources
(the formats and paths of your input snippets) and output
tables (the target formats and paths).
Here's an example to convert a set of UltiSnips and SnipMate snippets to the VSCode snippets format (using packer.nvim):
use {
"smjonas/snippet-converter.nvim",
-- SnippetConverter uses semantic versioning. Example: use version = "1.*" to avoid breaking changes on version 1.
-- Uncomment the next line to follow stable releases only.
-- tag = "*",
config = function()
local template = {
-- name = "t1", (optionally give your template a name to refer to it in the `ConvertSnippets` command)
sources = {
ultisnips = {
-- Add snippets from (plugin) folders or individual files on your runtimepath...
"./vim-snippets/UltiSnips",
"./latex-snippets/tex.snippets",
-- ...or use absolute paths on your system.
vim.fn.stdpath("config") .. "/UltiSnips",
},
snipmate = {
"vim-snippets/snippets",
},
},
output = {
-- Specify the output formats and paths
vscode_luasnip = {
vim.fn.stdpath("config") .. "/luasnip_snippets",
},
},
}
require("snippet_converter").setup {
templates = { template },
-- To change the default settings (see configuration section in the documentation)
-- settings = {},
}
end
}
Then simply run the command :ConvertSnippets
to convert all snippets to your specified
output locations and formats. To see which output folders you should choose depending on
your snippet engine, have a look at the section Recommended output paths in the docs.
For more detailed instructions, info about customization and examples check out the
documentation or help file with :h snippet-converter
.
I want to thank
scandir
utility function in my plugin!dedent
utility function that is used in this plugin after slight modification.