{"id":13479558,"url":"https://github.com/hrsh7th/vim-vsnip","last_synced_at":"2025-05-15T00:11:53.253Z","repository":{"id":36534263,"uuid":"203639872","full_name":"hrsh7th/vim-vsnip","owner":"hrsh7th","description":"Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.","archived":false,"fork":false,"pushed_at":"2025-03-28T03:05:53.000Z","size":444,"stargazers_count":905,"open_issues_count":34,"forks_count":36,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-03T09:09:06.854Z","etag":null,"topics":["neovim","neovim-plugin","snippets","vim","vim-plugin"],"latest_commit_sha":null,"homepage":"","language":"Vim Script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrsh7th.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["hrsh7th"]}},"created_at":"2019-08-21T18:13:26.000Z","updated_at":"2025-04-02T00:40:36.000Z","dependencies_parsed_at":"2023-01-17T02:30:27.322Z","dependency_job_id":"d7388bfa-b009-4215-8448-2b7b3ac9d965","html_url":"https://github.com/hrsh7th/vim-vsnip","commit_stats":{"total_commits":330,"total_committers":25,"mean_commits":13.2,"dds":"0.16060606060606064","last_synced_commit":"be277461265f1e5c7db470aa479f30956597ea9e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrsh7th%2Fvim-vsnip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrsh7th%2Fvim-vsnip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrsh7th%2Fvim-vsnip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrsh7th%2Fvim-vsnip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrsh7th","download_url":"https://codeload.github.com/hrsh7th/vim-vsnip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248544036,"owners_count":21121880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["neovim","neovim-plugin","snippets","vim","vim-plugin"],"created_at":"2024-07-31T16:02:19.172Z","updated_at":"2025-04-12T09:21:23.384Z","avatar_url":"https://github.com/hrsh7th.png","language":"Vim Script","readme":"# vim-vsnip\n\nVSCode(LSP)'s snippet feature in vim/nvim.\n\n# Features\n\n- Nested placeholders\n  - You can define snippet like `console.log($1${2:, $1})$0`\n- Nested snippet expansion\n  - You can expand snippet even if you already activated other snippet (it will be merged as one snippet)\n- Load snippet from VSCode extension\n  - If you install VSCode extension via `Plug 'golang/vscode-go'`, vsnip will load those snippets.\n- Support many LSP-client \u0026 completion-engine by [vim-vsnip-integ](https://github.com/hrsh7th/vim-vsnip-integ)\n  - LSP-client\n    - [vim-lsp](https://github.com/prabirshrestha/vim-lsp)\n    - [vim-lsc](https://github.com/natebosch/vim-lsc)\n    - [yegappan-lsp](https://github.com/yegappan/lsp)\n    - [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)\n    - [neovim built-in lsp](https://github.com/neovim/neovim)\n  - completion-engine\n    - [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim)\n    - [vim-mucomplete](https://github.com/lifepillar/vim-mucomplete)\n    - [vimcomplete](https://github.com/girishji/vimcomplete)\n    - [ddc.vim](https://github.com/Shougo/ddc.vim)\n    - [vim-easycompletion](https://github.com/jayli/vim-easycomplete)\n- Vim script interpolation\n  - You can use Vim script interpolation as `${VIM:...Vim script expression...}`.\n- SnipMate-like syntax support\n  - Snippet files in SnipMate format with the extension `.snippets` can be load.\n  - NOTE: Full compatibility is not guaranteed. It is intended to easily create user-defined snippets.\n\n# Concept\n\n- Pure Vim script\n- Well tested (neovim/0.4.4, vim/8.0.1567)\n- Support VSCode snippet format\n- Provide integration with many plugins\n\n# Related repository\n\n[friendly-snippets](https://github.com/rafamadriz/friendly-snippets) - Set of preconfigured snippets for all kind of programming languages that integrates really well with [vim-vsnip](https://github.com/hrsh7th/vim-vsnip), so all users can benefit from them and not to worry about setting up snippets on their own.\n\n# Usage\n\n### 1. Install\n\nYou can use your favorite plugin managers to install this plugin.\n\n```viml\nPlug 'hrsh7th/vim-vsnip'\nPlug 'hrsh7th/vim-vsnip-integ'\n\ncall dein#add('hrsh7th/vim-vsnip')\ncall dein#add('hrsh7th/vim-vsnip-integ')\n\nNeoBundle 'hrsh7th/vim-vsnip'\nNeoBundle 'hrsh7th/vim-vsnip-integ'\n```\n\n### 2. Setting\n\n```viml\n\" NOTE: You can use other key to expand snippet.\n\n\" Expand\nimap \u003cexpr\u003e \u003cC-j\u003e   vsnip#expandable()  ? '\u003cPlug\u003e(vsnip-expand)'         : '\u003cC-j\u003e'\nsmap \u003cexpr\u003e \u003cC-j\u003e   vsnip#expandable()  ? '\u003cPlug\u003e(vsnip-expand)'         : '\u003cC-j\u003e'\n\n\" Expand or jump\nimap \u003cexpr\u003e \u003cC-l\u003e   vsnip#available(1)  ? '\u003cPlug\u003e(vsnip-expand-or-jump)' : '\u003cC-l\u003e'\nsmap \u003cexpr\u003e \u003cC-l\u003e   vsnip#available(1)  ? '\u003cPlug\u003e(vsnip-expand-or-jump)' : '\u003cC-l\u003e'\n\n\" Jump forward or backward\nimap \u003cexpr\u003e \u003cTab\u003e   vsnip#jumpable(1)   ? '\u003cPlug\u003e(vsnip-jump-next)'      : '\u003cTab\u003e'\nsmap \u003cexpr\u003e \u003cTab\u003e   vsnip#jumpable(1)   ? '\u003cPlug\u003e(vsnip-jump-next)'      : '\u003cTab\u003e'\nimap \u003cexpr\u003e \u003cS-Tab\u003e vsnip#jumpable(-1)  ? '\u003cPlug\u003e(vsnip-jump-prev)'      : '\u003cS-Tab\u003e'\nsmap \u003cexpr\u003e \u003cS-Tab\u003e vsnip#jumpable(-1)  ? '\u003cPlug\u003e(vsnip-jump-prev)'      : '\u003cS-Tab\u003e'\n\n\" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.\n\" See https://github.com/hrsh7th/vim-vsnip/pull/50\nnmap        s   \u003cPlug\u003e(vsnip-select-text)\nxmap        s   \u003cPlug\u003e(vsnip-select-text)\nnmap        S   \u003cPlug\u003e(vsnip-cut-text)\nxmap        S   \u003cPlug\u003e(vsnip-cut-text)\n\n\" If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it.\nlet g:vsnip_filetypes = {}\nlet g:vsnip_filetypes.javascriptreact = ['javascript']\nlet g:vsnip_filetypes.typescriptreact = ['typescript']\n```\n\n### 3. Create your own snippet\n\nSnippet file will store to `g:vsnip_snippet_dir` per filetype.\n\n1. Open some file (example: `Sample.js`)\n2. Invoke `:VsnipOpen` command.\n3. Edit snippet.\n\n```json\n{\n  \"Class\": {\n    \"prefix\": [\"class\"],\n    \"body\": [\n      \"/**\",\n      \" * @author ${VIM:\\\\$USER}\",\n      \" */\",\n      \"class $1 ${2:extends ${3:Parent} }{\",\n      \"\\tconstructor() {\",\n      \"\\t\\t$0\",\n      \"\\t}\",\n      \"}\"\n    ],\n    \"description\": \"Class definition template.\"\n  }\n}\n```\n\nThe snippet format was described in [here](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax) or [here](https://github.com/Microsoft/language-server-protocol/blob/master/snippetSyntax.md).\n\n# Recipe\n\n### $TM\\_FILENAME\\_BASE\n\nYou can insert the filename via `fname\\\u003cPlug\u003e(vsnip-expand)`.\n\n```json\n{\n  \"filename\": {\n    \"prefix\": [\"fname\"],\n    \"body\": \"$TM_FILENAME_BASE\"\n  }\n}\n```\n\n### Log $TM\\_SELECTED\\_TEXT\n\nYou can fill `$TM_SELECTED_TEXT` by `\u003cPlug\u003e(vsnip-select-text)` or `\u003cPlug\u003e(vsnip-cut-text)`.\n\n```json\n{\n  \"log\": {\n    \"prefix\": [\"log\"],\n    \"body\": \"console.log(${1:$TM_SELECTED_TEXT});\"\n  }\n}\n```\n\n### Insert environment vars\n\nYou can insert value by Vim script expression.\n\n```json\n{\n  \"user\": {\n    \"prefix\": \"username\",\n    \"body\": \"${VIM:\\\\$USER}\"\n  }\n}\n```\n\n### Insert UUID via python\n\nYou can insert UUID via python.\n\n```json\n{\n  \"uuid\": {\n    \"prefix\": \"uuid\",\n    \"body\": [\n      \"${VIM:system('python -c \\\"import uuid, sys;sys.stdout.write(str(uuid.uuid4()))\\\"')}\"\n    ]\n  }\n}\n```\n\nNOTE: `$VIM` is only in vsnip. So that makes to lost the snippet portability.\n\n# DEMO\n\n### LSP integration\n\n\u003cimg src=\"https://user-images.githubusercontent.com/629908/90160819-3bd3ec80-ddcd-11ea-919b-577d7eb559a4.gif\" width=\"480\" alt=\"Nested snippet expansion\" /\u003e\n\n### `\u003cPlug(vsnip-cut-text)` with `$TM_SELECTED_TEXT`\n\n\u003cimg src=\"https://user-images.githubusercontent.com/629908/90157756-17761100-ddc9-11ea-843f-d8b0d529ac61.gif\" width=\"480\" alt=\"\u0026lt;Plug\u0026rt;(vsnip-cut-text) with $TM_SELECTED_TEXT\" /\u003e\n\n# Development\n\n### How to run test it?\n\nYou can run `npm run test` after install [vim-themis](https://github.com/thinca/vim-themis).\n\n### How sync same tabstop placeholders?\n\n1. compute the `user-diff` ... `s:Session.flush_changes`\n2. reflect the `user-diff` to snippet ast ... `s:Snippet.follow`\n3. reflect the `sync-diff` to buffer content ... `s:Snippet.sync \u0026 s:Session.flush_changes`\n","funding_links":["https://github.com/sponsors/hrsh7th"],"categories":["Vim Script","vim"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrsh7th%2Fvim-vsnip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrsh7th%2Fvim-vsnip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrsh7th%2Fvim-vsnip/lists"}