Checking Python files with Vim

Vim is an ex­ce­llent edi­to­r, and mas­te­ring it lea­ds to mo­re pro­duc­ti­vi­ty. Even thou­gh is ve­r­y ex­ten­si­ble and allo­ws to be con­fi­gu­red by many plu­g-ins I ra­ther keep it as sim­ple as po­s­si­ble, ­tr­ying not to use many plu­g-ins (nei­ther pa­cka­gers like Vund­le, etc.).

Ho­we­ve­r, I do make use of an ex­ten­sion that che­cks Py­thon fi­les for error­s, PE­P8, a­mong other things: flake8. Be­cau­se I do not use plu­g-in pla­tfor­ms for Vi­m, I ins­ta­ll just this one ma­nua­ll­y, by making the co­m­mand flake8 avai­la­ble sys­te­m-wi­de [1].

Then the ins­ta­lla­tion is as sim­ple as do­wn­loading the pro­ject and co­ying the fi­les in­to the ~/.­­vi­­m/­­ftplu­­gi­n/­­p­­y­­thon di­rec­to­r­y. Make su­re you ha­ve the fo­llo­wing li­ne added on your ~/.­­vi­­mrc:

filetype plugin indent on

The fea­tu­res I use are main­ly the syn­tax and PE­­P-8 com­plian­ce che­cker­s. It can al­so warn you about unu­s­ed im­por­ts, and cy­clo­ma­tic com­ple­xi­ty.

It is use­ful be­cau­se things like PE­­P-8 com­plian­ce help to ha­ve a good co­de qua­li­ty, and the­re­fo­re a mo­re rea­da­ble and main­tai­na­ble co­de ba­se, spe­cia­lly on lar­ge pro­jec­ts wi­th lo­ts of fi­les and mo­du­le­s.

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

[1] Another option would be to install it on your virtual environment, but then you have to make sure to install it once per project. It is actually better, because you are not using the global system environment, but for packages like this, it should not be an issue, it’s your choice.