今回したいこと
Vimにpython3のコード補完機能を導入する
Vimを使いこなしてるようにみせてイキる
Vimをインストールする(インストールされていない場合のみ)
sudo apt update
sudo apt install vim
Vimの設定を行う
自分でもいまいちよく理解していないが、今回はVimの設定を完了することが目的なのでよしとする。
dein.vimというプラグイン管理をするものを入れる
```
cd ~ mkdir ~/.cache mkdir ~/.cache/dein cd .cache/dein/ wget https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh sh ./installer.sh ~/.cache/dein/
##### [プラグイン](http://d.hatena.ne.jp/keyword/%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3)の管理ファイルを作成する
今回は<u>plugin.toml</u>と<u>plugin_lazy.toml</u>を作成し、次のように使い分ける。
- <u>plugin.toml</u>は、起動時に必ず読み込むような[プラグイン](http://d.hatena.ne.jp/keyword/%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3)を設定する記述をする。
- <u>plugin_lazy.toml</u>は、[Python](http://d.hatena.ne.jp/keyword/Python)の場合や、他の言語のファイルの場合など、開くファイルの種類に応じて読み込む[プラグイン](http://d.hatena.ne.jp/keyword/%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3)を設定する記述をする。
##### 作成した管理ファイルに設定情報を書き込む
cd ~/.cache/ mkdir userconfig cd userconfig/ vi plugin.toml
<b>plugin.tomlに以下の記述をする</b>
[[plugins]] repo = ‘Shougo/dein.vim’ [[plugins]] repo = ‘Shougo/vimproc.vim’
vi plugin_lazy.toml
<b>plugin_lazy.tomlに以下の記述をする</b>
[[plugins]] repo = ‘Shougo/unite.vim’ [[plugins]] repo = ‘Shougo/neomru.vim’ on_source = [‘unite.vim’] [[plugins]] repo = “davidhalter/jedi-vim” on_ft = [‘python’]
##### [Vim](http://d.hatena.ne.jp/keyword/Vim)の設定ファイルに[プラグイン](http://d.hatena.ne.jp/keyword/%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3)の設定を書き込む
cd ~
vi ~/.vimrc</pre>
<b>vimrcに以下の記述をする</b>
```vim
"dein Scripts-----------------------------
if &compatible
set nocompatible " Be iMproved
endif
let s:dein_path = expand('~/.cache/dein')
let s:dein_repo_path = s:dein_path . '/repos/github.com/Shougo/dein.vim'
if &runtimepath !~# '/dein.vim'
if !isdirectory(s:dein_repo_path)
execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_path
endif
execute 'set runtimepath^=' . fnamemodify(s:dein_repo_path, ':p')
endif
if dein#load_state(s:dein_path)
call dein#begin(s:dein_path)
let g:config_dir = expand('~/.cache/userconfig')
let s:toml = g:config_dir . '/plugin.toml'
let s:lazy_toml = g:config_dir . '/plugin_lazy.toml'
" TOML 読み込み
call dein#load_toml(s:toml, {'lazy': })
call dein#load_toml(s:lazy_toml, {'lazy': 1})
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-------------------------
保存して、Vimを再起動するとプラグインのダウンロードがスタートします。
できているか確認する
てきとうなpythonファイルを開き、Vimのコマンドモードで以下のコマンドを入力するとjediのヘルプが表示されるはずです。
vi test.py
:help jedi
```
#### 最後に
僕も[Vim](http://d.hatena.ne.jp/keyword/Vim)初心者ということもあり、たくさんの記事を参考にさせていただきました。間違っているところや説明が不十分なところがいっぱいあるかと思います。そのへんはどうかご容赦いただき、コメント等で教えていただけると幸いです。