-
Notifications
You must be signed in to change notification settings - Fork 364
PEP8 Checking Using Syntastic
Syntastic is a powerful syntax checking plugin. It can check many languages including applescript, c, coffee, cpp, css, cucumber, cuda, docbk, erlang, eruby, fortran, gentoo_metadata, go, haml, haskell, html, javascript, json, less, lua, matlab, perl, php, puppet, python, rst, ruby, sass/scss, sh, tcl, tex, vala, xhtml, xml, xslt, yaml, zpt. For python, it invokes pyflaks, pylint and flake8. And flake8 can check PEP8.
You can go to https://github.com/scrooloose/syntastic and follow the instruction there. It needs you install another plugin "pathogen" for managing VIM plugins. If you do not want to install "pathogen". Follow the steps here.
- Download the syntastic.zip
- Copy syntastic.zip to your /.vim or $VIMRUNTIME
- Run the commands as follows
$ cd ~/.vim
$ unzip syntastic.zip
$ sudo yum install pylint pyflakes
_$ sudo easy_install flake8
Syntastic can perform checking when file is opened, saved or closed. However, I do not like this behavior. I disable the automatic check, then map F5 to activate the syntax checking. Add the following lines to your /.vimrc
let g:syntastic_mode_map = { 'mode': 'passive',
\ 'active_filetypes': [],
\ 'passive_filetypes': [] }
let g:syntastic_auto_loc_list=1
nnoremap <silent> <F5> :SyntasticCheck<CR>
In the latest version of flake8 and pep8 checking tools, the rules are very strict. If the project you working in applies a less strict rule set, you can ignore some rules not needed, create a file in ~/.config/pep8 and input the text as follow.
[pep8]
ignore=E121,E122,E123,E124,E125,E126,E127,E128,E241
Just press F5, then all the errors will be marked, and a error list box will appear, showing the errors and the reasons. You can select a specific error in the box and press ENTER to jump to the error. Here are a few commands taken from Syntastic's documentation.
:Errors
When errors have been detected, use this command to pop up the |location-list| and display the error messages.
:SyntasticCheck
Manually cause a syntax check to be done. Useful in passive mode, or if the current filetype is set to passive.
See |syntastic_mode_map| for more info.
To move cursor to the bottom box, press "CTRL+W" then press "j" or down arrow key, this means "move to the window downwards". Locate the cursor to a problem in the bottom box, then press "ENTER" to jump to the problem in the upper window.