LoginSignup
2
2

More than 5 years have passed since last update.

【vimめも】 13. プラグイン

Last updated at Posted at 2018-04-15

プラグイン

vimを更に便利にするために、様々な機能が開発されてgitで公開されている

vimスクリプトだけでなく、様々な言語で書くことができるらしい(詳しくは知らない)

プラグイン管理

10以上のプラグインを使用するようになると、すべてを自分でcloneしてupdateして・・・
など大変

そんな管理を楽にするためのプラグインも、もちろんあります

種類や人気度は@b4b4r07さんのこちらの記事を。

導入(dein)

ここでは私が使用しているdeinの使い方を載せます

余談:vim-plugの導入でわかりやすくい記事はこちら
↑乗り換えようとしたけどvim-plugが合わなかったのでやめた

それ以外のものを使いたい際は自分で調べてください

流れ

1. deinを用意(git clone)
2. deinが読み込まれるようにruntimepathを通す
3. deinの書き方で、入れたいpluginを書いていく
4. call dein#install()にてプラグインをインストール

1、2

手作業の場合は、任意のディレクトリにcloneしてruntimepathを通す

set runtimepath+=#{cloneしたディレクトリ}

もしくは、ここもvimrcを読み込んだ際に自動で行われるようにしましょう

if has('nvim')
  let s:dein_cache_path = expand('~/.vim/cache/nvim/dein')
else
  let s:dein_cache_path = expand('~/.vim/cache/vim/dein')
endif

" dein本体を準備
if &runtimepath !~ '/dein.vim'
  let s:repos_path = s:dein_cache_path . '/repos/github.com/Shougo/dein.vim'
  if !isdirectory(s:repos_path)
    execute '!git clone https://github.com/Shougo/dein.vim.git ' . s:repos_path
  endif
  execute 'set runtimepath+=' . s:repos_path
endif

3

下記の2つの間に記載する

if dein#load_state(s:dein_cache_path)
  call dein#begin(s:dein_cache_path)
  call dein#end()
  call dein#save_state()
end

記載の方法が2種類ある

  • vimスクリプト
  • tomlファイル

vimスクリプトでの記載

下記のようにgitのアカウント・リポジトリを指定する
https://github.com/Shougo/neocomplete.vim の場合

call dein#add('Shougo/unite.vim')
call dein#add('Shougo/neocomplete.vim')

第2引数に辞書型でオプションを指定できる

call dein#add('Shougo/vimfiler.vim', {
\ 'hook_add': 'nnoremap <silent>   [Space]v
\              :<C-u>VimFiler -invisible<CR>'
\ })

詳しくは下記を参考に
https://github.com/Shougo/dein.vim#options

tomlファイルでの記載

tomlファイルを生成し、記載

dein.toml
[[plugins]]
repo = 'Shougo/unite.vim'

[[plugins]]
repo = 'Shougo/denite.nvim'
if = "has('python3')"
hook_post_source = '''
source $XDG_CONFIG_HOME/plugins/denite.rc.vim
'''

vimrcからtomlを読み込む

  call dein#load_toml($XDG_CONFIG_HOME . '/dein.toml', {'lazy' : 0})
  call dein#load_toml($XDG_CONFIG_HOME . '/deinlazy.toml', {'lazy' : 1})

4

インストール

" 未インストールがあればインストール
if dein#check_install()
  call dein#install()
endif

最終系

私のvimrcの内容をそのまま貼っておきます

if has('nvim')
  let s:dein_cache_path = expand('~/.vim/cache/nvim/dein')
else
  let s:dein_cache_path = expand('~/.vim/cache/vim/dein')
endif

if &runtimepath !~ '/dein.vim'
  let s:repos_path = s:dein_cache_path . '/repos/github.com/Shougo/dein.vim'
  if !isdirectory(s:repos_path)
    execute '!git clone https://github.com/Shougo/dein.vim.git ' . s:repos_path
  endif
  execute 'set runtimepath+=' . s:repos_path
endif

syntax enable

if dein#load_state(s:dein_cache_path)
  call dein#begin(s:dein_cache_path)

  call dein#load_toml($XDG_CONFIG_HOME . '/dein.toml', {'lazy' : 0})
  call dein#load_toml($XDG_CONFIG_HOME . '/deinlazy.toml', {'lazy' : 1})
  call dein#end()
  call dein#save_state()
endif

" vimprocだけ先にインストールしておく
if dein#check_install(['vimproc.vim'])
 call dein#install(['vimproc.vim'])
endif

" 未インストールのものがあればインストール
if dein#check_install()
  call dein#install()
endif

前回: 【vimめも】 12. タブ
次回: 【vimめも】 14. grep

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2