Use snippets in vim

来源:互联网 发布:上海网页美工培训班 编辑:程序博客网 时间:2024/04/30 15:34

0. Introduce

Code snippet is much useful to speed up coding.It allows concentrating more on the main logic. It is code reuse for programmers.

1. Install

  1. Install vim. You may refer to this blog.
  2. If you have already vim installed, add below to .vimrc and PluginInstall.
Plugin 'SirVer/ultisnips'Plugin 'honza/vim-snippets'let g:UltiSnipsExpandTrigger="<tab>"let g:UltiSnipsJumpForwardTrigger="<c-b>"let g:UltiSnipsJumpBackwardTrigger="<c-z>"

2. How

After installation, everything is ready. Have a look at this gif:

Cool, HA?

Use three kinds of keys:
1. tab to trigger expand.
2. control+b to jump forward.
3. control+z to jump backward.
Of course, you can change them in vimrc.

3. More snippets

You can refer to here to find how many snippets you can use. They are also stored in ~/.vim/bundle/vim-snippets/snippets.

If you want to add you own snippets, create a folder named UltiSnips in ~/.vim/. And add you own snippets file in that folder. Refer to those examples to find how to write snippets.

0 0
原创粉丝点击