Skip to content

Instantly share code, notes, and snippets.

@za
Last active June 2, 2021 18:41
Show Gist options
  • Save za/983db825aee2dc352d5341da357cbfb4 to your computer and use it in GitHub Desktop.
Save za/983db825aee2dc352d5341da357cbfb4 to your computer and use it in GitHub Desktop.
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