vim snippetの利用
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