LoginSignup
76
66

More than 5 years have passed since last update.

dein.vimでプラグイン管理のはじめ方

Posted at

はじめに

前回、macにneovimをインストールしました。今回はそのneovimに便利なプラグインを入れていくためにプラグインマネージャーを導入したいと思います。

プラグインマネージャー

有名なところでは以下の二つです。

それぞれざっと特徴を調べてみたところtomlファイルでプラグインを管理できるということでdein.vimに決定。vimに詳しい人たちにとってはもっともっと色んな理由があると思いますが、、、

インストール

cd ~/

curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh

mkdir ~/.cache/dein

sh ./installer.sh ~/.cache/dein

以上です。

少しポイントがあって、dein.vimはデフォルトのインストールディレクトリは決まっていないということです。デフォルトのディレクトが決まっていないので、インストール前に自分で決める必要があります。

githubのREADMEには例として

"~/.vim/bundles" or "~/.cache/dein" or "~/.local/share/dein"

とありますので、今回特に理由がないので上記から~/.cache/deinを選択。

設定

vimの.vimrcに当たるneovimの設定ファイルは~/.config/nvim/init.vimです。

init.vimに処理を追加してdein.vimを使えるようにしていきます。READMEにどのような処理を追加すれば良いか記載がありますが、調べて以下のような設定を行いました。

  • tomlファイルを使う
    • 起動時に読み込みたいプラグイン → dein.toml
    • 遅延読み込みしたいプラグイン → dein_lazy.toml

具体的な設定内容は以下になります。

init.vim
if &compatible
  set nocompatible
endif

# dein.vimインストール時に指定したディレクトリをセット
let s:dein_dir = expand('~/.cache/dein')

# dein.vimの実体があるディレクトリをセット
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'

" dein.vimが存在していない場合はgithubからclone
if &runtimepath !~# '/dein.vim'
  if !isdirectory(s:dein_repo_dir)
    execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
  endif
  execute 'set runtimepath^=' . fnamemodify(s:dein_repo_dir, ':p')
endif

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

  # dein.toml, dein_layz.tomlファイルのディレクトリをセット
  let s:toml_dir = expand('~/.config/nvim')

  # 起動時に読み込むプラグイン群
  call dein#load_toml(s:toml_dir . '/dein.toml', {'lazy': 0})

  # 遅延読み込みしたいプラグイン群
  call dein#load_toml(s:toml_dir . '/dein_lazy.toml', {'lazy': 1})

  call dein#end()
  call dein#save_state()
endif

filetype plugin indent on
syntax enable

" If you want to install not installed plugins on startup.
if dein#check_install()
  call dein#install()
endif

dein.tomlの設定
(とりあえずtree構造を見れるようにするやつを追加してみた)

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

[[plugins]]
repo = 'scrooloose/nerdtree'

dein_lazy.toml
(とりあえずgolangとmarkdown用の設定追加)

dein_lazy.toml
[[plugins]]
repo = 'fatih/vim-go'
on_ft = ['go']

[[plugins]]
repo = 'rcmdnk/vim-markdown'
on_ft = ['md', 'markdown']

以上になります。
プラグインは、インストールされていなければnvimで起動した時インストールされます。
ちなみにインストールされたプラグインは自分の場合、~/.cache/dein/repos以下に格納されます。treeコマンドで構造をみてみると

tree ~/.cache/dein/repos
└── github.com
    ├── Shougo
    │   ├── dein.vim
    │   │   ├── LICENSE
    │   │   ├── README.md
    │   │   ├── autoload
    │   │   │   ├── dein
    │   │   │   │   ├── autoload.vim
    │   │   │   │   ├── install.vim
    │   │   │   │   ├── job.vim
    │   │   │   │   ├── parse.vim
    │   │   │   │   ├── toml.vim
    │   │   │   │   ├── types
    │   │   │   │   │   ├── git.vim
    │   │   │   │   │   └── raw.vim
    │   │   │   │   └── util.vim
    │   │   │   ├── dein.vim
    │   │   │   └── unite
    │   │   │       ├── kinds
    │   │   │       │   └── dein.vim
    │   │   │       └── sources
    │   │   │           ├── dein.vim
    │   │   │           └── dein_log.vim
    │   │   ├── bin
    │   │   │   └── installer.sh
    │   │   ├── doc
    │   │   │   └── dein.txt
    │   │   ├── rplugin
    │   │   │   └── python3
    │   │   │       └── denite
    │   │   │           └── source
    │   │   │               └── dein.py
    │   │   └── test
    │   │       ├── base.vim
    │   │       ├── git.vim
    │   │       ├── install.vim
    │   │       ├── install_base.vim
    │   │       ├── parse.vim
    │   │       ├── raw.vim
    │   │       ├── state.vim
    │   │       └── toml.vim
    ├── fatih
    │   └── vim-go
    ├── scrooloose
    │   └── nerdtree

※途中省略
golangのパッケージ管理みたいです。

おわりに

プラグインの設定が簡単にtomlファイルに外出しできました。

76
66
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
76
66