Checking Python files with Vim

Vim is an ex­cel­lent ed­i­tor, and mas­ter­ing it leads to more pro­duc­tiv­i­ty. Even though is very ex­ten­si­ble and al­lows to be con­fig­ured by many plug-ins I rather keep it as sim­ple as pos­si­ble, try­ing not to use many plug-ins (nei­ther pack­agers like Vun­dle, etc.).

How­ev­er, I do make use of an ex­ten­sion that checks Python files for er­rors, PEP8, a­mong oth­er things: flake8. Be­cause I do not use plug-in plat­forms for Vim, I in­stall just this one man­u­al­ly, by mak­ing the com­mand flake8 avail­able sys­tem-wide [1].

Then the in­stal­la­tion is as sim­ple as down­load­ing the project and coy­ing the files in­to the ~/.vim/ft­­plug­in/python di­rec­to­ry. Make sure you have the fol­low­ing line added on your ~/.vim­rc:

filetype plugin indent on

The fea­tures I use are main­ly the syn­tax and PEP-8 com­pli­ance check­er­s. It can al­so warn you about un­used im­port­s, and cy­clo­mat­ic com­plex­i­ty.

It is use­ful be­cause things like PEP-8 com­pli­ance help to have a good code qual­i­ty, and there­fore a more read­able and main­tain­able code base, spe­cial­ly on large projects with lots of files and mod­ules.

That’s al­l. For more de­tails and oth­er con­fig­u­ra­tion tips check­out my Vim set­up.

[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.