neovimでAnacondaの環境ごとにpython補完させる
環境:Ubuntu18.04 LTS
Anaconda (Miniconda) のインストール
neovim用環境の作成
conda create -n neovim python=3
pip install neovim
neovimのインストール
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt-get update
sudo apt-get install neovim
Deinの導入
mkdir -p $XDG_CONFIG_HOME/nvim/dein/toml touch $XDG_CONFIG_HOME/nvim/dein/toml/init.viml touch $XDG_CONFIG_HOME/nvim/dein/toml/dein.toml touch $XDG_CONFIG_HOME/nvim/dein/toml/dein_lazy.toml
init.vimを編集。 典型的なinit.vimなのでコピペで動くと思います。
let g:python3_host_prog = $HOME.'/miniconda3/envs/neovim3/bin/python' " initialize if &compatible set nocompatible endif set runtimepath+=~/.cache/dein/repos/github.com/Shougo/dein.vim if dein#load_state('~/.cache/dein') call dein#begin('~/.cache/dein') call dein#load_toml('$XDG_CONFIG_HOME/nvim/dein.toml', {'lazy': 0}) call dein#load_toml('$XDG_CONFIG_HOME/nvim/dein_lazy.toml', {'lazy': 1}) call dein#end() call dein#save_state() endif filetype plugin indent on syntax enable if dein#check_install() call dein#install() endif
Deopleteの導入 dein.tomlへ以下を記入
[[plugins]] repo = 'Shougo/deoplete.nvim' hook_add = 'let g:deoplete#enable_at_startup = 1'
Deoplete-jediの導入 activateしているAnacondaのpython_pathを自動取得してdeopleteへ反映
dein_lazy.tomlへ以下を記入(遅延読み込みさせる)
[[plugins]] repo = 'deoplete-plugins/deoplete-jedi' on_ft = 'python' hook_add = """ let g:deoplete#sources#jedi#python_path = system("which python")[:-2] """
system("which python") でpython pathを取得し、[:-2]で改行文字を落としています。
source activate
またはconda activate
で環境に入ってneovimを起動すれば、自動的にその環境での補完をしてくれます。