neovimを入れてみた

きっかけ

neovimはvimより良い(諸説あり)と耳にしたのでとりあえず試してみようと思いました.

ちなみに普段使ってるのはIntelliJ(Ultimateも学生はタダ!学生最高!!).

環境

  • Ubuntu 18.04 LTS
  • neovim 0.3.1
  • pyenv 1.2.8
  • python 2.7.15
  • python3 3.6.7

参考

こちらの記事を参考にさせていただきました.感謝.

poyo.hatenablog.jp

neovimをインストールする

公式ページを見ながらやっていきます.

github.com

sudo apt update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt-get update
sudo apt-get install neovim

シェルを再読込してnvim --versionがうまく機能すれば成功です.

python用ライブラリを入れる

普段利用している,pyenvを利用してpythonの任意のバージョンのインストールします(ここでは2.7.15と3.7.1).

pyenv isntall 2.7.15 3.7.1
pyenv global 2.7.15 3.7.1

# pyenv-virtualenvを利用する場合
pyenv isntall 2.7.15 3.7.1
pyenv virtualenv 2.7.15 neovim2
pyenv virtualenv 3.7.1 neovim3
pyenv global neovim2 neovim3

neovimのpython用ライブラリをインストールします.

pip install --upgrade neovim
pip3 install --upgrade neovim

設定ファイルをつくる

環境変数を設定します.自分はfish使いなのでconfig.fishに以下を追加します.

set -x XDG_CONFIG_HOME $HOME/.config
set -x XDG_CACHE_HOME $HOME/.cache

設定ファイルを作成します.

mkdir ~/.config/nvim
touch ~/.config/nvim/init.vim

aliasを設定する.

config.fishに追加します

alias vi 'nvim'
alias vim 'nvim'

プラグインを管理する

プラグイン管理はdein.vim一択のようなのでそれを使っていきたいと思います. 我に暗黒の力を!!!

github.com

インストール

READMEを見ながらやっていきます.インストール先はREADMEの記述通り,~./cacheにしました.

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

# install.shを消しとく
rm installer.sh

tomlに記述していく

init.vimに設定を追記

さっき手に入れた暗黒の力を解放するためにinit.vimに設定を記述します.

" ============== dein =================
" Pythonインタプリタへのパスを指定
let g:python3_host_prog = '/home/shanpu/.anyenv/envs/pyenv/shims/python3'
let g:python_host_prog = '/home/shanpu/.anyenv/envs/pyenv/shims/python'


" 各種ファイルへのパス
let s:dein_cache_dir = $XDG_CACHE_HOME . '/dein'
let s:dein_config_dir = $XDG_CONFIG_HOME . '/nvim'
let s:dein_repo_dir = s:dein_cache_dir . '/repos/github.com/Shougo/dein.vim'
let s:toml = s:dein_config_dir . '/dein.toml'
let s:toml_lazy = s:dein_config_dir . '/dein_lazy.toml'

"dein Scripts-----------------------------
if &compatible
  set nocompatible
endif

" Required:
let &runtimepath = s:dein_repo_dir .",". &runtimepath

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

  " Let dein manage dein
  " Required:
  call dein#add(s:dein_repo_dir)
  
  " tomlファイルからプラグインのリストをロードしキャッシュする
  call dein#load_toml(s:toml, {'lazy': 0})
  call dein#load_toml(s:toml_lazy, {'lazy': 1})
  
  " Required:
  call dein#end()
  call dein#save_state()
endif

" Required:
filetype plugin indent on
syntax enable

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

"End dein Scripts-------------------------

dein.tomlを編集

~/.config/nvim/dein.tomlに管理するプラグインを記述,インサートモード時に使うなど遅延して読み込むプラグイン~/.config/nvim/dein_lazy.tomlに記述していきます.

どんなプラグインを入れるかは選択肢は無限大ですが,ここでは試しにdein.tomlに適当に記述した例を紹介します.dein_lazy.tomlの内容は割愛しますが(そのうちプラグインの特集記事を書くかもしれない)記法は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
'''

カラースキーム

スキーム探しに以下のサイトが役に立ちます.今回はhybridを使ってみることにしました.

vimcolors.com

さいごに

適当にプラグイン入れたりしたら見た目も使い心地も良くなりました.プラグインの設定が固まってきたら,また記事でも書こうと思います(書くとは言ってない).

f:id:tech_shanpu:20190102212802p:plain
とりあえずこんなかんじで

なお設定ファイルはGithubで管理しているのでよければ活用してください.

github.com