Python with Vim

Using Vim as a Python editor

2014-10-27 — Rylan Santinon

Here is an overview of the way that I configure Vim in order to develop Python programs. On Linux or Mac, your vimrc file if most likely located at ~/.vimrc but to find the exact location of the file type: :version when in Vim. The following settings are meant to go in that file.

General Editor Settings

Some settings that I use for all code editing in Vim:

set textwidth=79
set nu
syntax enable
filetype indent plugin on

Indentation and Whitespace


Many Python projects follow the PEP 8 guide so tabs are to be converted to four spaces:

set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
set smartindent

Visible whitespace

In Python, I often want to be able to see whitespace characters. For this listchars is used:

setlocal listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

And then in the editor just type :set list to toggle this view.

My Dotfiles

You can find my .vimrc file and .gitconfig file in my Dotfile repository.