Checking Python files with Vim

Vim is an excellent editor, and mastering it leads to more productivity. Even though is very extensible and allows to be configured by many plug-ins I rather keep it as simple as possible, trying not to use many plug-ins (neither packagers like Vundle, etc.).

However, I do make use of an extension that checks Python files for errors, PEP8, among other things: flake8. Because I do not use plug-in platforms for Vim, I install just this one manually, by making the command flake8 available system-wide 1.

Then the installation is as simple as downloading the project and coying the files into the ~/.­vi­m/­ftplu­gi­n/­p­y­thon directory. Make sure you have the following line added on your ~/.­vi­mrc:

filetype plugin indent on

The features I use are mainly the syntax and PE­P-8 compliance checkers. It can also warn you about unused imports, and cyclomatic complexity.

It is useful because things like PE­P-8 compliance help to have a good code quality, and therefore a more readable and maintainable code base, specially on large projects with lots of files and modules.

Tha­t’s all. For mo­re de­tails and other con­fi­gu­ra­tion tips che­ckout my Vim se­tup.


Ano­ther op­tion would be to ins­ta­ll it on your vir­tual en­vi­ron­men­t, but then you ha­ve to­ ­make su­re to ins­ta­ll it on­ce per pro­jec­t. It is ac­tua­lly be­tte­r, be­cau­se you are not using the ­glo­bal sys­tem en­vi­ron­men­t, but for pa­cka­ges like this, it should not be an is­sue, it’s your choi­ce.