• Stars
    star
    872
  • Rank 52,158 (Top 2 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created about 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.

vim-vsnip

VSCode(LSP)'s snippet feature in vim/nvim.

Features

  • Nested placeholders
    • You can define snippet like console.log($1${2:, $1})$0
  • Nested snippet expansion
    • You can expand snippet even if you already activated other snippet (it will be merged as one snippet)
  • Load snippet from VSCode extension
    • If you install VSCode extension via Plug 'golang/vscode-go', vsnip will load those snippets.
  • Support many LSP-client & completion-engine by vim-vsnip-integ
  • Vim script interpolation
    • You can use Vim script interpolation as ${VIM:...Vim script expression...}.
  • SnipMate-like syntax support
    • Snippet files in SnipMate format with the extension .snippets can be load.
    • NOTE: Full compatibility is not guaranteed. It is intended to easily create user-defined snippets.

Concept

  • Pure Vim script
  • Well tested (neovim/0.4.4, vim/8.0.1567)
  • Support VSCode snippet format
  • Provide integration with many plugins

Related repository

friendly-snippets - Set of preconfigured snippets for all kind of programming languages that integrates really well with vim-vsnip, so all users can benefit from them and not to worry about setting up snippets on their own.

Usage

1. Install

You can use your favorite plugin managers to install this plugin.

Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'

call dein#add('hrsh7th/vim-vsnip')
call dein#add('hrsh7th/vim-vsnip-integ')

NeoBundle 'hrsh7th/vim-vsnip'
NeoBundle 'hrsh7th/vim-vsnip-integ'

2. Setting

" NOTE: You can use other key to expand snippet.

" Expand
imap <expr> <C-j>   vsnip#expandable()  ? '<Plug>(vsnip-expand)'         : '<C-j>'
smap <expr> <C-j>   vsnip#expandable()  ? '<Plug>(vsnip-expand)'         : '<C-j>'

" Expand or jump
imap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'

" Jump forward or backward
imap <expr> <Tab>   vsnip#jumpable(1)   ? '<Plug>(vsnip-jump-next)'      : '<Tab>'
smap <expr> <Tab>   vsnip#jumpable(1)   ? '<Plug>(vsnip-jump-next)'      : '<Tab>'
imap <expr> <S-Tab> vsnip#jumpable(-1)  ? '<Plug>(vsnip-jump-prev)'      : '<S-Tab>'
smap <expr> <S-Tab> vsnip#jumpable(-1)  ? '<Plug>(vsnip-jump-prev)'      : '<S-Tab>'

" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.
" See https://github.com/hrsh7th/vim-vsnip/pull/50
nmap        s   <Plug>(vsnip-select-text)
xmap        s   <Plug>(vsnip-select-text)
nmap        S   <Plug>(vsnip-cut-text)
xmap        S   <Plug>(vsnip-cut-text)

" If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it.
let g:vsnip_filetypes = {}
let g:vsnip_filetypes.javascriptreact = ['javascript']
let g:vsnip_filetypes.typescriptreact = ['typescript']

3. Create your own snippet

Snippet file will store to g:vsnip_snippet_dir per filetype.

  1. Open some file (example: Sample.js)
  2. Invoke :VsnipOpen command.
  3. Edit snippet.
{
  "Class": {
    "prefix": ["class"],
    "body": [
      "/**",
      " * @author ${VIM:\\$USER}",
      " */",
      "class $1 ${2:extends ${3:Parent} }{",
      "\tconstructor() {",
      "\t\t$0",
      "\t}",
      "}"
    ],
    "description": "Class definition template."
  }
}

The snippet format was described in here or here.

Recipe

$TM_FILENAME_BASE

You can insert the filename via fname\<Plug>(vsnip-expand).

{
  "filename": {
    "prefix": ["fname"],
    "body": "$TM_FILENAME_BASE"
  }
}

Log $TM_SELECTED_TEXT

You can fill $TM_SELECTED_TEXT by <Plug>(vsnip-select-text) or <Plug>(vsnip-cut-text).

{
  "log": {
    "prefix": ["log"],
    "body": "console.log(${1:$TM_SELECTED_TEXT});"
  }
}

Insert environment vars

You can insert value by Vim script expression.

{
  "user": {
    "prefix": "username",
    "body": "${VIM:\\$USER}"
  }
}

Insert UUID via python

You can insert UUID via python.

{
  "uuid": {
    "prefix": "uuid",
    "body": [
      "${VIM:system('python -c \"import uuid, sys;sys.stdout.write(str(uuid.uuid4()))\"')}"
    ]
  }
}

NOTE: $VIM is only in vsnip. So that makes to lost the snippet portability.

DEMO

LSP integration

Nested snippet expansion

<Plug(vsnip-cut-text) with $TM_SELECTED_TEXT

<Plug&rt;(vsnip-cut-text) with $TM_SELECTED_TEXT

Development

How to run test it?

You can run npm run test after install vim-themis.

How sync same tabstop placeholders?

  1. compute the user-diff ... s:Session.flush_changes
  2. reflect the user-diff to snippet ast ... s:Snippet.follow
  3. reflect the sync-diff to buffer content ... s:Snippet.sync & s:Session.flush_changes

More Repositories

1

nvim-cmp

A completion plugin for neovim coded in Lua.
Lua
7,735
star
2

nvim-compe

Auto completion Lua plugin for nvim
Lua
1,284
star
3

cmp-nvim-lsp

nvim-cmp source for neovim builtin LSP client
Lua
1,184
star
4

cmp-buffer

nvim-cmp source for buffer words
Lua
586
star
5

cmp-nvim-lsp-signature-help

cmp-nvim-lsp-signature-help
Lua
585
star
6

cmp-path

nvim-cmp source for path
Lua
581
star
7

vscode-langservers-extracted

vscode-langservers bin collection.
Shell
560
star
8

cmp-cmdline

nvim-cmp source for vim's cmdline
Lua
514
star
9

cmp-nvim-lua

nvim-cmp source for nvim lua
Lua
308
star
10

cmp-nvim-lsp-document-symbol

nvim-cmp source for textDocument/documentSymbol via nvim-lsp.
Lua
179
star
11

nvim-insx

Flexible key mapping manager.
Lua
173
star
12

cmp-emoji

nvim-cmp source for emoji
Lua
170
star
13

cmp-calc

nvim-cmp source for math calculation
Lua
142
star
14

cmp-copilot

copilot.vim source for nvim-cmp
Lua
129
star
15

vim-vsnip-integ

vim-vsnip integrations to other plugins.
Vim Script
125
star
16

nvim-pasta

The yank/paste enhancement plugin for neovim.
Lua
103
star
17

cmp-vsnip

nvim-cmp source for vim-vsnip
Lua
90
star
18

vim-searchx

The extended search motion.
Vim Script
76
star
19

vim-eft

enhanced f/t
Vim Script
75
star
20

cmp-omni

nvim-cmp source for omnifunc
Lua
43
star
21

nvim-gtd

LSP's Go to definition plugin for neovim.
Lua
36
star
22

vim-seak

search + seek = seak. The plugin that enhances the `/` and `?`.
Vim Script
35
star
23

js-co-on

co based event emitter handling.
JavaScript
33
star
24

vim-lamp

💡Language Server Protocol client for Vim.
Vim Script
32
star
25

nvim-kit

My personal Lua utilities for neovim.
Lua
27
star
26

nvim-automa

Automatic macro recorder for neovim.
Lua
21
star
27

nvim-dansa

Guess the indent from lines of around.
Lua
19
star
28

vim-vital-vs

Vim Script
18
star
29

denops-popup

https://deno.land/x/denops_popup
Vim Script
17
star
30

vim-gindent

General indentexpr plugin for vim and nvim.
Lua
17
star
31

nvim-lua-rpc-example

Lua
16
star
32

nvim-linkedit

Lua
14
star
33

nvim-automa-poc

POC of plugin that will be called `nvim-automa`
Lua
13
star
34

vim-candle

Candidates listing engine for vim/nvim built on yaegi on golang.
Vim Script
12
star
35

nvim-matcha

A fuzzy finding plugin for neovim (for my personal use)
11
star
36

cmp-core-example

Lua
11
star
37

nvim-lua-rpc-example-with-headless

Use nvim --headless for asynchronous processing
Lua
11
star
38

vim-neco-calc

neocomplcache/neocomplete/deoplete calculates plugin.
Vim Script
10
star
39

vim-versions

useful interface for version control.
Vim Script
9
star
40

vim-compete

Auto completion plugin for vim/nvim that supports fuzzy match.
Vim Script
9
star
41

state-use

Simple state manager for React
TypeScript
8
star
42

deno-json-rpc

Strongly typed json-rpc module for deno.
TypeScript
7
star
43

nvim-plugin-template

Makefile
7
star
44

srimmer

Srimmer provides simple api to use react and immer.
TypeScript
6
star
45

vim-unmatchparen

highlight unmatch parens.
Vim Script
6
star
46

vim-denite-gitto

denite with vim-gitto
Python
6
star
47

msw-snapshot

Transparently create an API cache for testing.
TypeScript
5
star
48

deno-nvim-types

The Nvim API type definition for TypeScript.
TypeScript
5
star
49

completion-snippet

The vim-vsnip snippet collection for completion.
5
star
50

vim-foolish-move

Vim Script
5
star
51

fern-mapping-collapse-or-leave.vim

Vim Script
5
star
52

hrsh7th

My profile.
4
star
53

deoplete-vim-lsc

deoplete source for vim-lsc.
Vim Script
4
star
54

fern-mapping-call-function.vim

Vim Script
4
star
55

vim-minx

Extended insert-mode mapping manager.
Vim Script
3
star
56

vim-aim

This plugin provides motion that similar to /. (experimental)
Vim Script
3
star
57

js-gulp-component-build

gulp plugin to build component.
JavaScript
3
star
58

js-modelis

Modelis javascript modeling support.
JavaScript
2
star
59

vim-lamp-extensions

Vim Script
2
star
60

node-monores

monorepo scripts.
TypeScript
2
star
61

nvim-tuil

nvim plugin utilities that can be embed your plugin.
Lua
2
star
62

frontend-testing-demo

https://hrsh7th.github.io/frontend-testing-demo/main/storybook
TypeScript
2
star
63

vim-compete-lamp

Vim Script
2
star
64

vim-gitto

vim-gitto
Vim Script
2
star
65

vim-feeling-move

Vim Script
1
star
66

vsnip-snippet-plugin-demo

Vim Script
1
star
67

deoplete-lamp

deoplete source for vim-lamp.
Vim Script
1
star
68

denite-converter-prioritize-basename

Python
1
star
69

denops-sandbox

TypeScript
1
star
70

vim-neco-snippets

neocomplcache my snippets.
1
star
71

compe-lamp

vim-lamp source for compe for my personal use.
Vim Script
1
star
72

deoplete-calc

calculates at completion.
Python
1
star
73

nvim-lapi

1
star
74

js-modelis-assurance

assucrance plugin for modelis.
JavaScript
1
star
75

refnew-react

refnew react binding.
TypeScript
1
star
76

deoplete-fname

filename completion for deoplete.nvim.
Python
1
star
77

vim-diffkit

Buffer diff management in VimL. Improve performance for getting buffer's diff.
Vim Script
1
star
78

vim-picka

Vim Script
1
star
79

asyncomplete-lamp

asyncomplete source for vim-lamp.
Vim Script
1
star
80

react-inview-hook

react hooks & intersection-observer
TypeScript
1
star
81

vim-locon

local config in vimrc.
Vim Script
1
star
82

vim-compete-omnifunc

Vim Script
1
star
83

vim-vital-deno

vim x deno (experimental)
1
star
84

diagnostics.nvim

Experimental diagnostics service for neovim.
Vim Script
1
star
85

immer-deps

Auto update dependencies, when immer's produce.
TypeScript
1
star
86

vim-effort-gf

Vim Script
1
star
87

sandbox

Lua
1
star
88

slow-lsp-demo

TypeScript
1
star
89

vim-compete-lsp

vim-lsp source for vim-compete.
Vim Script
1
star
90

xhr-snapshot

TypeScript
1
star
91

refnew

proxy based state management utility.
TypeScript
1
star
92

compe-conjure

compe-nvim source for conjure
Lua
1
star
93

babel-plugin-tree-shakable

good manner cjs files to mjs. this is very very experimental. do not use.
JavaScript
1
star