このまえ,知り合いに自分のpythonコードを渡したら,emacsのプラグインか何かで,表記がみやすくないところを,自動チェックして表示していた.vimでもあるらしいので,探してきて,使えるようにした.
pythonコードを見やすく書く作法に反する箇所を指摘するプログラムにflake8というのがあるらしい.
syntasticをvimで管理するのに,deinというものが使えるらしい.
手順:
1.flake8のインストール
sudo apt-get install flake8
(condaなどほかのやり方もあるだろうが..)
2. deinのインストール
mkdir -p ~/.vim/dein/repos/github.com/Shougo/dein.vim
git clone https://github.com/Shougo/dein.vim.git ~/.vim/dein/repos/github.com/Shougo/dein.vim
cd .vim/dein/repos/github.com/Shougo/dein.vim/
git clone https://github.com/Shougo/dein.vim.git ~/.vim/dein/repos/github.com/Shougo/dein.vim
cd .vim/dein/repos/github.com/Shougo/dein.vim/
git reset --hard a80906fbc2a2e2b371276d34e159997724796da9
最後のgitでツリーを古いもの(リリース1.5)に変更している.これは,使っているvimのバージョンが7.4であり,この場合はリリース1.5を使うようにdeinのgitのdocに記載されていたためである.
3. deinの設定
.vimrcに以下を記載
let s:dein_dir = expand('~/.vim/dein')
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
if &runtimepath !~# '/dein.vim'
execute 'set runtimepath^=' . fnamemodify(s:dein_repo_dir, ':p')
endif
if dein#load_state(s:dein_dir)
call dein#begin(s:dein_dir)
let g:rc_dir = expand('~/.vim/rc')
let s:toml = g:rc_dir . '/dein.toml'
let s:lazy_toml = g:rc_dir . '/dein_lazy.toml'
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
if &runtimepath !~# '/dein.vim'
execute 'set runtimepath^=' . fnamemodify(s:dein_repo_dir, ':p')
endif
if dein#load_state(s:dein_dir)
call dein#begin(s:dein_dir)
let g:rc_dir = expand('~/.vim/rc')
let s:toml = g:rc_dir . '/dein.toml'
let s:lazy_toml = g:rc_dir . '/dein_lazy.toml'
call dein#load_toml(s:toml, {'lazy': 0})
call dein#load_toml(s:lazy_toml, {'lazy': 1})
call dein#end()
call dein#save_state()
endif
if dein#check_install()
call dein#install()
endif
let g:syntastic_python_checkers = ["flake8"]
syntax enable
call dein#load_toml(s:lazy_toml, {'lazy': 1})
call dein#end()
call dein#save_state()
endif
if dein#check_install()
call dein#install()
endif
let g:syntastic_python_checkers = ["flake8"]
syntax enable
ここでsyntax enableは,最後のほうに持ってこないと,スクリプトのhighlightが効かなくなった.
3. tomlファイルの作成,編集
このままだと,
.vim/rc/dein.toml
.vim/rc/dein_lazy.toml
が無いと,vimを起動すると文句をいわれるので,作成.
dein.tomlに
vimrcには,flake8をその作法書に指定している.
:SyntasticCheck
と打つと,作法に則らないところが明示される.