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
 if len(getqflist())
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.

One 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: Logo

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: