Skip to content

Instantly share code, notes, and snippets.

@za
Last active Jun 2, 2021
Embed
What would you like to do?
Step-by-step on setting up vim-flake8

This is how to automatically check your Python code style to comply with PEP8 when you use vim as your text editor. The first thing to do is, make sure you have vim running 😁

$ vim

You need to setup vim-pathogen first:

$ mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Add this to .vimrc file:

execute pathogen#infect()
filetype plugin indent on

Now copy vim-flake8 and put it at vim bundle directory:

$ cd ~/.vim/bundle && git clone git@github.com:nvie/vim-flake8.git

Add also add this to .vimrc to automatically check the style everytime you write a Python code:

autocmd BufWritePost *.py call Flake8()

Let's give it a try, create a Python file:

$ vim voila.py
import django
from datetime import datetime

now = datetime.now()

Try to save it: :w then you should see this kind of warning:

voila.py|1 col 1| F401 'django' imported but unused 

✌️

Footnote:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment