vim-vsnip


Ⅰ. 插件描述

Ⅱ. 基本信息

创建日期:  2019-08-21
使用用户:  12
Github星:  39
插件作者:  hrsh7th

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'hrsh7th/vim-vsnip'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'hrsh7th/vim-vsnip'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'hrsh7th/vim-vsnip'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/hrsh7th/vim-vsnip

Ⅳ. 文档说明

# vim-vsnip

VSCode(LSP)'s snippet feature in vim.

vsnip can integrate some other plugins via vim-vsnip-integ. (e.g. vim-lsp)

DEMO

vsnip-demo

Concept

  • Standard features written in Pure Vim script.
  • Support VSCode(LSP)'s snippet format.
  • Some LSP client integration.

Features

  • VSCode's snippet format support.
  • Load snippet from VSCode's extension.

    • You can load snippet via Plug 'microsoft/vscode-python' etc.
    • If you use dein.nvim, You should set merged flag to 0.
  • Some LSP client integration.

    • You can find how to integrate those plugins in here.

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

" You can use other key to expand snippet.
imap <expr> <C-j>   vsnip#available(1)  ? '<Plug>(vsnip-expand)'         : '<C-j>'
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>'
imap <expr> <Tab>   vsnip#available(1)  ? '<Plug>(vsnip-jump-next)'      : '<Tab>'
smap <expr> <Tab>   vsnip#available(1)  ? '<Plug>(vsnip-jump-next)'      : '<Tab>'
imap <expr> <S-Tab> vsnip#available(-1) ? '<Plug>(vsnip-jump-prev)'      : '<S-Tab>'
smap <expr> <S-Tab> vsnip#available(-1) ? '<Plug>(vsnip-jump-prev)'      : '<S-Tab>'

3. Create your own snippet

Snippet source 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": [
      "class $1 ${2:extends ${3:Parent} }{",
      "\tconstructor() {",
      "\t\t$0",
      "\t}",
      "}"
    ],
    "description": "Class definition template."
  }
}

The snippet format was described in here or here.

Documentation

See ./doc/vsnip.txt

Integration

Why create vim-vsnip?

  • I want to support VSCode(LSP)'s snippet format.

    • Some LSP client plugins has no snippet feature.
    • This plugin aims to integrate those plugins.
  • I want to snippet plugin that written in Pure Vim script.

    • For example, vim-lsp, vim-lsc are written in Pure Vim script.
    • If snippet plugin needs python, lua etc, will breaks those plugins advantage.
  • I want to study parser combinator.

TODO

  • Should convert filetype to LSP's languageId.

    • It's breaking change...
  • Support more features in VSCode(LSP) spec.

    • regex transform
  • Some other useful features.

    • feel free to send request.

添加新评论