GithubHelp home page GithubHelp logo

svermeulen / vim-vsnip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hrsh7th/vim-vsnip

0.0 2.0 0.0 273 KB

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

License: MIT License

Vim Script 100.00%

vim-vsnip's Introduction

vim-vsnip

VSCode(LSP)'s snippet feature in vim.

DEMO

nested-snippet-expansion

Concept

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 'microsoft/vscode-python', vsnip will load those snippets.
  • Support many LSP-client & completion-engine
    • You can get 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

" 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        <C-l>   <Plug>(vsnip-select-text)
xmap        <C-l>   <Plug>(vsnip-select-text)
smap        <C-l>   <Plug>(vsnip-select-text)
nmap        <C-j>   <Plug>(vsnip-cut-text)
xmap        <C-j>   <Plug>(vsnip-cut-text)
smap        <C-j>   <Plug>(vsnip-cut-text)

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

The snippet format was described in here or here.

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

vim-vsnip's People

Contributors

hrsh7th avatar ironsigma avatar jandamm avatar kitagry avatar mityu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.