LoginSignup
3
10

More than 5 years have passed since last update.

NeoVim & Dein.vimの環境構築に手間取った話

Posted at

タイトル通り、neovim&dein.vimのインストールその他諸々手こずったのでメモ
@ Bash on Ubuntu on Windows

Install NeoVim

  • 現時点ではubuxtuのパッケージリストに追加されてないのでppaに追加
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt-get update
sudo apt-get -y install neovim
  • denite.vimでPython3も要求されるのでついでにインストール
sudo apt-get -y install python-dev python-pip python3-dev python3-pip

About Config File

  • vimでは設定ファイルは~/.vimrcだったが、neovimではXDG Base Directoryを採用しているので

    ~/.bashrcにXDG_CONFIG_HOME=hogeを書く

    なので設定ファイルはhoge/nvim/init.vimになるのだが、

  • ここで、hoge/nvimの/nvimは名前変更してはいけない!!

    自分はわかりやすいように/nvim_deinとかに書き換えて、

    「あれ?設定ファイル読み込まれてない?」ってなりました(泣)

Install Dein.vim

curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
  • そしてこのinstaller.shは引数にインストールディレクトリを指定する必要がある
    ~/.cache/deinにインストールするのが一般的らしいので
mkdir -p ~/.cache/dein
sh /installer.shのあるディレクトリ/installer.sh ~/.cache/dein
  • installer.shを実行した時に表示される文字列"dein Scripts----以下をXDG_CONFIG_HOME/nvim/init.dにコピべ

  • この"dein Scripts----以下の最後の3行

"if dein#check_install()
" call dein#install()
"endif

はコメントアウトしておく(プラグインを自動インストールさせるため)

  • あとはneovimを起動すればインストールが始まる

Dein Config Files

  • init.vimの"dein Scripts----以下に色々書くのだが、そのサンプルはいろいろなブログで公開されてる

  • そしてとても初歩的なことだが、最初にコピベでくっつけたものは消してもいいのか?と思った

    • 結果、最初にコピべしたのは最初にインストールするプラグインが書かれていて、さらに公開されているサンプルに必要なものが書かれているので消してもよかった

toml files

  • プラグインをtomlファイルで一括で管理できる

  • tomlを使うには、以下をinit.vimに書く必要がある

init.vim
let s:dein_cache_dir =$XDG_CACHE_HOME . '/dein'
let s:dein_config_home = $XDG_CONFIG_HOME . '/nvim'

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

  let s:toml = s:dein_config_dir . '/dein.toml'
  let s:toml_lazy = s:dein_config_dir . '/dein_lazy.toml'

  call dein#load_toml(s:toml, {'lazy': 0})
  call dein#load_toml(s:toml_lazy, {'lazy': 1})

  call dein#end()
  call dein#save_state()
endif
  • dein.tomlにはインストールしたいプラグインを書き、dein_lazy.tomlには遅延読み込みしたいものを書く
dein.toml
[[plugins]]
repo = 'Shougo/dein.vim'

[[plugins]]
repo = 'Shougo/vimproc.vim'
build = 'make'

[[plugins]]
repo = 'fatih/vim-go'
hook_post_source = '''
    let g:go_highlight_functions = 1
    let g:go_highlight_methods = 1
    let g:go_highlight_structs = 1
'''
dein_lazy.toml
[[plugins]]
repo = 'Shougo/dein.vim'

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

[[plugins]]
repo = 'tomtom/tcomment_vim'

[[plugins]]
repo = 'Shougo/deoplete.nvim'
if = 'has("python3")'
on_event = 'InsertEnter' #InsertEnter = 挿入モードを開始したとき

[[plugins]]
repo = 'Shougo/denite.nvim'
if = 'has("python3")'
on_cmd = 'Denite'
on_i = 1

[[plugins]]
repo = 'Shougo/neomru.vim'
depends = 'denite.nvim'

[[plugins]]
repo = 'Shougo/neoyank.vim'
depends = 'deinte.nvim'
on_event = 'YextYankPost'
  • 解説は自分の知識が間違っている可能性大なので省略

最後に

現在はこんな感じですが、また追記していくかもです

解説をあまり書かなくて申し訳ない...

3
10
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
3
10