Open6

Vim8 + venv + deoplate

heavenshellheavenshell

Vim8 + venv + deoplate を最小で動かす

deoplate のドキュメント

You can enable Python3 interface with pip: >

    pip3 install --user pynvim

と書いてあるが、自分のマシンはグローバルに pip でインストールできないように

export PIP_REQUIRE_VIRTUALENV=true

してるので、venv の中に依存を閉じ込めたい。

heavenshellheavenshell

まずは Vim は自分でビルドする。

#!/bin/sh
cd vim
git checkout master
git fetch --all --prune
git reset --hard origin/master
make distclean
./configure --prefix=/path/to/vim/build \
  --with-features=huge \
  --enable-multibyte \
  --enable-terminal \
  --enable-netbeans \
  --enable-cscope \
  --enable-fail-if-missing \
  --enable-perlinterp=dynamic \
  --enable-rubyinterp \
  --enable-python3interp=dynamic \
  --enable-luainterp \
  --with-luajit \
  --with-python3-command=/opt/local/bin/python \
  --with-ruby-command=/opt/local/bin/ruby \
  --with-tlib=ncurses \
  --with-local-dir=/opt/local \
  --with-lua-prefix=/opt/local
make
make install

というのを作ってあるので、これを叩くだけ。

git clone git://github.com/vim/vim.git
bash build.sh

ビルドが終わったら起動して :echo has('python3') を実行する

:echo has('python3')
1
heavenshellheavenshell

deoplate に必要なものを適当なディレクトリーに入れて、最小の vimrc を作り、読み込むだけにする

$ mkdir ~/.vim/bundle/
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $
$ pip install wheel
Collecting wheel
  Using cached wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel
Successfully installed wheel-0.36.2
$ pip install pynvim
Collecting pynvim
  Using cached pynvim-0.4.2-py3-none-any.whl
Collecting greenlet
  Using cached greenlet-1.0.0-cp39-cp39-macosx_10_14_x86_64.whl (86 kB)
Collecting msgpack>=0.5.0
  Using cached msgpack-1.0.2-cp39-cp39-macosx_10_14_x86_64.whl (74 kB)
Installing collected packages: msgpack, greenlet, pynvim
Successfully installed greenlet-1.0.0 msgpack-1.0.2 pynvim-0.4.2
heavenshellheavenshell

venv に pynvim が入ったので、こいつに PATH を通す。
Vim はビルド時に指定した Python の PATH を見るので、:python import sys; print(sys.path) した際に venv の PATH を追加する必要がある。

export PYTHONPATH="$HOME/.vim/bundle/venv/lib/python3.9/site-packages:$PYTHONPATH"

zsh を使ってるので zshenv とかに venv の PATH を先頭に追加。

heavenshellheavenshell

必要な他のプラグインを入れる。

git clone https://github.com/Shougo/deoplete.nvim.git
git clone https://github.com/roxma/vim-hug-neovim-rpc.git
git clone https://github.com/roxma/nvim-yarp.git

最小の vimrc を作る。

set nocompatible

set runtimepath+=~/.vim/bundle/vim-hug-neovim-rpc
set runtimepath+=~/.vim/bundle/nvim-yarp
set runtimepath+=~/.vim/bundle/deoplete.nvim

let g:deoplete#enable_at_startup = 1

syntax enable
filetype plugin indent on
heavenshellheavenshell

起動する。

buffer 補完されていることを確認する。