Automatic Python syntax and PEP 8 checking in VIM

I fiddled a bit for making my VIM tell me when obvious (statically detectable) mistakes sit in my code when saving. This speeds up the testing process a bit when e.g. syntax errors exist and helps me adhere to PEP 8.

I use vim’s ftplugin which has the following settings in ~/.vim/ftplugin/python.vim:

setlocal makeprg=pep8\ --repeat\ %
autocmd BufWritePost  call Checkpep8()

In my ~/.vimrc the Checkpep8 function is defined as follows:

function Checkpep8 ()
 silent make
 redraw!
 if len(getqflist())
    cl
 endif
endfunction Checkpep8

The effort of the custom function is in avoiding to get the <PRESS ENTER> message from the shell command if no errors exist. The only minor annoyance with my solution is that the message “file written…” disappears more quickly than normally.

1 thought on “Automatic Python syntax and PEP 8 checking in VIM”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s