smjonas / snippet-converter.nvim

Bundle snippets from multiple sources and convert them to your format of choice.
Mozilla Public License 2.0
174 stars 4 forks source link
neovim neovim-plugin snippets
# snippet-converter.nvim Parse, transform and convert snippets. Supports a variety of formats and snippet engines. [![Neovim](https://img.shields.io/badge/Neovim%200.7+-green.svg?style=for-the-badge&logo=neovim)](https://neovim.io) [![Lua](https://img.shields.io/badge/Lua-blue.svg?style=for-the-badge&logo=lua)](http://www.lua.org)

Primary objectives

Use cases

There are several cases where this plugin comes in handy:

Other reasons may include:

Supported snippet engines

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!

Requirements

Getting started

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.

Documentation

For more detailed instructions, info about customization and examples check out the documentation or help file with :h snippet-converter.

Credits

I want to thank