All Projects → hrsh7th → Vim Vsnip

hrsh7th / Vim Vsnip

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

Projects that are alternatives of or similar to Vim Vsnip

Indent Blankline.nvim
Indent guides for Neovim
Stars: ✭ 203 (-9.37%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Targets.vim
Vim plugin that provides additional text objects
Stars: ✭ 2,114 (+843.75%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Context.vim
Vim plugin that shows the context of the currently visible buffer contents
Stars: ✭ 688 (+207.14%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Neotex
latex live preview - plugin for neovim and vim 8
Stars: ✭ 170 (-24.11%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Neovim Fuzzy
Fuzzy file finding for neovim
Stars: ✭ 103 (-54.02%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Dadbod Completion
Database autocompletion powered by https://github.com/tpope/vim-dadbod
Stars: ✭ 163 (-27.23%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Visual Split.vim
Vim plugin to control splits with visual selections or text objects
Stars: ✭ 190 (-15.18%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Lens.vim
A Vim Automatic Window Resizing Plugin
Stars: ✭ 381 (+70.09%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Ncm R
R autocompletion for Neovim and vim 8 📝 📊 ⚡️
Stars: ✭ 102 (-54.46%)
Mutual labels:  snippets, neovim, vim-plugin
Asyncrun.vim
🚀 Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
Stars: ✭ 1,332 (+494.64%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Alchemist.vim
Elixir Integration Into Vim
Stars: ✭ 632 (+182.14%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Clap
👏 Modern performant fuzzy picker for Vim and NeoVim
Stars: ✭ 1,802 (+704.46%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Markdown Composer
An asynchronous markdown preview plugin for Vim and Neovim.
Stars: ✭ 501 (+123.66%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Animate.vim
A Vim Window Animation Library
Stars: ✭ 173 (-22.77%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Tmux Complete.vim
Vim plugin for insert mode completion of words in adjacent tmux panes
Stars: ✭ 447 (+99.55%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Crease.vim
Easy foldtext customization for [neo]vim.
Stars: ✭ 19 (-91.52%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Dashboard Nvim
vim dashboard
Stars: ✭ 294 (+31.25%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Barbar.nvim
A neovim tabline plugin.
Stars: ✭ 359 (+60.27%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Todoist.nvim
A todoist extension for neovim
Stars: ✭ 84 (-62.5%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Nvim Treesitter Context
Show code context
Stars: ✭ 113 (-49.55%)
Mutual labels:  neovim, vim-plugin, neovim-plugin

vim-vsnip

VSCode(LSP)'s snippet feature in vim.

Features

Concept

  • Pure Vim script
  • Well tested
  • Support VSCode snippet format
  • Provide integration with many plugins

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].