インストール
nvimを開いて以下のコマンドを打つ
:CocInstall coc-snippets
このようなエラーが出てきた
Error on execute python script: request error nvim_command - Vim(pyxfile):E319: No "python3" provider found. Run ":checkhealth provider"
:checkhealth providerを実行するらしい
:checkhealth provider
## Python 3 provider (optional)
- WARNING: No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
- ERROR: Python provider error:
- ADVICE:
- provider/pythonx: Could not load Python 3:
/opt/homebrew/bin/python3 does not have the "neovim" module. :help provider-python
python3.10 not found in search path or not executable.
/opt/homebrew/bin/python3.9 does not have the "neovim" module. :help provider-python
python3.8 not found in search path or not executable.
python3.7 not found in search path or not executable.
python3.6 not found in search path or not executable.
/usr/bin/python is Python 2.7 and cannot provide Python 3.
- INFO: Executable: Not found
今度は:help provider-pythonを実行
:help provider-python
PYTHON QUICKSTART ~
To use Python plugins, you need the "pynvim" module. Run |:checkhealth| to see
if you already have it (some package managers install the module with Nvim
itself).
For Python 3 plugins:
1. Make sure Python 3.4+ is available in your $PATH.
2. Install the module (try "python" if "python3" is missing): >
python3 -m pip install --user --upgrade pynvim
For Python 2 plugins:
1. Make sure Python 2.7 is available in your $PATH.
2. Install the module (try "python" if "python2" is missing): >
python2 -m pip install --user --upgrade pynvim
The pip `--upgrade` flag ensures that you get the latest version even if
a previous version was already installed.
今回はpython3のproviderがないというエラーだったので"For Python 3 Plugins"の項目をチェックする
- シェル上でecho $PATH → 大丈夫そう
- python3 -m pip install --user --upgrade pynvim を実行
再び:checkhealth providerを実行してみると
:checkhealth provider
## Python 3 provider (optional)
- INFO: `g:python3_host_prog` is not set. Searching for python3 in the environment.
- INFO: Multiple python3 executables found. Set `g:python3_host_prog` to avoid surprises.
- INFO: Executable: /opt/homebrew/bin/python3
- INFO: Other python executable: /usr/bin/python3
- INFO: Python version: 3.9.5
- INFO: pynvim version: 0.4.3
- OK: Latest pynvim is installed.
スニペットを登録する
スニペットを登録したいファイルタイプのファイルを開いて以下のコマンドを打つ
今回はpythonのスニペットを登録してみることにするので、hoge.pyを開いてコマンドを打つ
:CocCommand snippets.editSnippets
すると~/.config/coc/ultisnips/python.snippetsが開かれる
~/.config/coc/ultisnips/[ファイルタイプ].snippetsにスニペットを登録するみたい
以下のようにスニペットを登録してみる
snippet fori "for (i=0; i<max; i++) ..."
for (${1:Counter}=0; $1<${2:Max}; $1++):
${3:Implementetion}
endsnippet
このように設定することで"fori"と打つとスニペット機能が選択できます
coc-snippetsのREADMEをみると、デフォルトではCtrl+jとCtrl+kで上記の$1とか$2とかに移動できるみたい
https://github.com/neoclide/coc-snippets
なのでこのスニペットを使うにはpythonファイルを開いてこのようにタイプしてみると
fori → Enter → a → Ctrl+j → MIN → Ctrl+j → hogehoge
以下のように補完される
for (a=0; a<MIN; a++):
hogehoge