Python Bibliotheca
Python resources for teachers and students.

Using vim as a Python IDE

Here is a little .vimrc that makes vim an excellent Python IDE:

" .vimrc
"
" Created by Jeff Elkner 23 January 2006
" Last modified 25 September 2018
" Works on Ubuntu GNU/Linux 20.04 and Debian 11 (Bullseye)
"
" Turn on syntax highlighting and autoindenting
syntax enable
filetype indent on
" set autoindent width to 4 spaces (see
" http://www.vim.org/tips/tip.php?tip_id=83)
set et
set sw=4
set smarttab
set background=dark

" Bind <f3> key to run python3
map <f3> :w\|!python3 % <cr>
" Bind <f4> key to run doctests in a python3 module
map <f4> :w\|!python3 -m doctest % <cr>
" Bind <f5> key to run doctests with verbose output 
map <f5> :w\|!python3 -m doctest -v % <cr>
" Bind <f8> key to run pycodestyle Python style checker 
map <f8> :w\|!pycodestyle % <cr>
" Bind <f9> key to run black Python auto code formatter 
map <f9> :w\|!black % <cr>

Click here to download this file. Rename as .vimrc and put it in your home directory.

[ Copyright 2018, Jeffrey Elkner ]

Comments, questions, or suggestions? Email the webmaster