LoginSignup
67
71

More than 5 years have passed since last update.

neovimをインストールしてプラグイン管理をdein.tomlでやってみた

Last updated at Posted at 2016-07-11

neovimの説明などは他の投稿やneovimを御覧ください。

概要

  • コピペしていくとneovimの環境が整う
  • neovimから採用されたtomlファイルによるプラグイン管理を試してみる

自身の環境

OS: OS X Yosemite 10.10.5
Shell: Zsh

インストール

インストールについてはNeoVim と dein.vim を使ってみる!を参考にしました。
まずはneovimのインストール

$ brew install neovim/neovim/neovim

インストール後には nvim というコマンドが使えるようになります。
deopleteという補完のプラグインにはpython3が必要ですのでpython3が入ってない方は入れましょう。pipを用いてneovimをインストールします。

$ brew install python3
$ pip3 install neovim

deopleteとは "dark powered neo-completion"の省略らしいです。か、かっこいいですね。
続いて

$ nvim

のようにとりあえずneovimを開いてみてノーマルモード状態で:echo has("python3")と打ってみます。1という結果が表示されるとOKです。

設定

シェルによりますが私はzshを使用しているので.zshrcにXDG_COONFIG_HOMEを設定します。

~/.zshrc
export XDG_CONFIG_HOME=~/.config

次にviでいうところの.vimrcを設定します。
neovimでは$XDG_CONFIG_HOME/nvim配下にinit.vimという名前で設定ファイルを記述するのが良いそうです。
参考: NeoVimの.nvimrcの場所が変更された

後で必要になるプラグインを管理するファイルを事前に作っておきましょう。

$ touch $XDG_CONFIG_HOME/nvim/dein.toml
$ touch $XDG_CONFIG_HOME/nvim/dein_lazy.toml

init.vim

現時点での私のinit.vimを貼っておきます。大部分をNeoBundle から dein.vim に乗り換えたら爆速だった話から引用いたしました。

~/.config/nvim/init.vim
" 行数
set number

set noswapfile


" insertモードから抜ける
inoremap <silent> jj <ESC>
inoremap <silent> <C-j> j
inoremap <silent> kk <ESC>
inoremap <silent> <C-k> k

filetype indent on
set tabstop=2
set shiftwidth=2
set expandtab

" プラグインがインストールされるディレクトリ
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 から落としてくる
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)

  " プラグインリストを収めた TOML ファイル
  " 予め TOML ファイルを用意しておく
  let g:rc_dir    = expand("~/.config/nvim/")
  let s:toml      = g:rc_dir . '/dein.toml'
  let s:lazy_toml = g:rc_dir . '/dein_lazy.toml'

  " TOML を読み込み、キャッシュしておく
  call dein#load_toml(s:toml,      {'lazy': 0})
  call dein#load_toml(s:lazy_toml, {'lazy': 1})

  " 設定終了
  call dein#end()
  call dein#save_state()
endif

" もし、未インストールものものがあったらインストール
if dein#check_install()
  call dein#install()
endif

vimではNeoBundleを使用してしましたが、neovimではdein.vimを使用することにしました。上記のinit.vimをコピペすると問題なくdein.vimを取ってくるようになっています。
init.vimでは.vimrcと同様の書き方で jj でインサートモードを抜けるですとか, tabのサイズを指定するといったことが可能です。

dein.toml

さきほどのinit.vim内にプラグインの情報はdein.tomlから読み取るといったことが書かれています。
別ファイルでプラグインを管理できるのでinit.vimがすっきりして良いですね。
deopleteを導入するためのdein.tomlを以下に記載します。

~/.config/nvim/dein.toml
[[plugins]]
repo = 'Shougo/deoplete.nvim'
hook_add = 'let g:deoplete#enable_at_startup = 1'

hookの使い方は[dein.vim] hook の便利な使い方
を参考にしました。
基本的には repo = レポジトリ名 と hookを組み合わせるとほとんどのプラグインの設定が書けるはずです(たぶん)。
上記の投稿を参考にして作ったものですが、現状での自身のdein.tomlを貼っておきます。

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

[[plugins]]
repo = 'Shougo/vimproc.vim'
hook_post_update = '''
  if dein#util#_is_windows()
    let cmd = 'tools\\update-dll-mingw'
  elseif dein#util#_is_cygwin()
    let cmd = 'make -f make_cygwin.mak'
  elseif executable('gmake')
    let cmd = 'gmake'
  else
    let cmd = 'make'
  endif
  let g:dein#plugin.build = cmd
'''

[[plugins]]
repo = 'thinca/vim-quickrun'
hook_post_update = '''
  let g:quickrun_config = {'*': {'hook/time/enable': '1'},}
'''

[[plugins]]
repo = 'Shougo/deoplete.nvim'
hook_add = 'let g:deoplete#enable_at_startup = 1'

[[plugins]]
repo = 'cespare/vim-toml'

これで設定は以上です。
問題なく設定が終わっていれば、deopleteのリボジトリのREADMEにあるような補完ができるはずです。

67
71
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
67
71