vimからsnippetは以前から利用していますが、環境毎に設定していることがあり、再設定していたので こちらにまとめておく。
環境
.vimrc
.vimrcに追加
...
if &compatible set nocompatible " Be iMproved endif
execute 'set runtimepath^=~/.vim/repos/github.com/Shougo/dein.vim'
" Required:
call dein#begin('~/cache/dein')
call dein#add('Shougo/dein.vim')
call dein#add('Shougo/neocomplete.vim')
" ここから
call dein#add('Shougo/neosnippet')
call dein#add('Shougo/neosnippet-snippets')
" ここまで
call dein#end()
filetype plugin indent on
" ここから
" Plugin key-mappings. " <C-k>でsnippetの展開
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target)
let g:neosnippet#snippets_directory = '~/.vim/snippets/'
if has('conceal')
set conceallevel=2 concealcursor=niv
endif
" ここまで
...
dein#install()
vimを起動して、:call dein#install()
もしくは、vimrcに下記を記述する。
" pluginsがインストール済みか確認 if dein#check_install() call dein#install() endif
使い方
Ctrl + kで利用する。
snippetの追加
独自のsnippetを利用する場合には、snippets_directoryで指定したフォルダにsnipファイルを作成して、追加していくか。
vimを起動してNeoSnippetEditコマンドを叩く。
vim hoge.rbでrubyのファイルを開いているなら、NeoSnippetEditでは、ruby.snipが開かれる。
ファイルがなければ、新規作成する。
参考
GitHub - Shougo/dein.vim: Dark powered Vim/Neovim plugin manager
GitHub - Shougo/neosnippet.vim: neo-snippet plugin contains neocomplcache snippets source