neosnippet.vim/README.md
2015-04-11 12:44:14 +09:00

4.7 KiB

Neosnippet

The Neosnippet plug-In adds snippet support to Vim. Snippets are small templates for commonly used code that you can fill in on the fly. To use snippets can increase your productivity in Vim a lot. The functionality of this plug-in is quite similar to plug-ins like snipMate.vim or snippetsEmu.vim. But since you can choose snippets with the neocomplcache / neocomplete interface, you might have less trouble using them, because you do not have to remember each snippet name.

Installation

To install neosnippet and other Vim plug-ins it is recommended to use one of the popular package managers for Vim, rather than installing by drag and drop all required files into your .vim folder.

Notes:

  • Default snippets files are available in: neosnippet-snippets
  • Installing default snippets is optional. If choose not to install them, you must deactivate them with g:neosnippet#disable_runtime_snippets.
  • neocomplcache/neocomplete is not required to use neosnippet, but it's highly recommended.
  • Extra snippets files can be found in: vim-snippets.
  1. Install the neocomplcache/ neocomplete and neosnippet-snippets first.
  2. Put files in your Vim directory (usually ~/.vim/ or %PROGRAMFILES%/Vim/vimfiles on Windows).

Vundle

  1. Setup the vundle package manager

  2. Set the bundles for neocomplcache or neocomplete And neosnippet And neosnippet-snippets

    Bundle 'Shougo/neocomplcache'
    or
    Bundle 'Shougo/neocomplete'
    
    Bundle 'Shougo/neosnippet'
    Bundle 'Shougo/neosnippet-snippets'
    
  3. Open up Vim and start installation with :BundleInstall

Neobundle

  1. Setup the neobundle package manager

  2. Set the bundles for neocomplcache or neocomplete And neosnippet And neosnippet-snippets

    NeoBundle 'Shougo/neocomplcache'
    or
    NeoBundle 'Shougo/neocomplete'
    
    NeoBundle 'Shougo/neosnippet'
    NeoBundle 'Shougo/neosnippet-snippets'
    
  3. Open up Vim and start installation with :NeoBundleInstall

VAM (vim-addon-manager)

  1. Setup the vim-addon-manager package manager.

  2. Add neosnippet to the list of addons in your vimrc:

    call vam#ActivateAddons(['neosnippet', 'neosnippet-snippets'])
    

    . Installation will start automatically when you open vim next time.

Configuration

This is an example ~/.vimrc configuration for Neosnippet. It is assumes you already have Neocomplcache configured. With the settings of the example, you can use the following keys:

  • C-k to select-and-expand a snippet from the Neocomplcache popup (Use C-n and C-p to select it). C-k can also be used to jump to the next field in the snippet.
  • Tab to select the next field to fill in the snippet.
" Plugin key-mappings.
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)

" SuperTab like snippets behavior.
imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)"
\: pumvisible() ? "\<C-n>" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)"
\: "\<TAB>"

" For snippet_complete marker.
if has('conceal')
  set conceallevel=2 concealcursor=niv
endif

If you want to use a different collection of snippets than the built-in ones, then you can set a path to the snippets with the g:neosnippet#snippets_directory variable (e.g Honza's Snippets)

But if you enable g:neosnippet#enable_snipmate_compatibility, neosnippet will load snipMate snippets from runtime path automatically.

" Enable snipMate compatibility feature.
let g:neosnippet#enable_snipmate_compatibility = 1

" Tell Neosnippet about the other snippets
let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'