You Don’t Need No Stinkin’ IDE! – Configuring Vim For Python Programming
Many Linux users have been out there long enough to get used to a text editor. Sure, you can always use an IDE to do your programming, and they do have nice features for good workflow, but I wanted to go through a couple tweaks that will make Python programming easier for those who prefer the command line. I myself setup a double tab in my shell window, one for execution/compiling and one for the project I am working on. With that said let’s look at a few tweaks to vim:First thing you want to do, is turn on syntax highlighting, and the indent plugin (which will make your Python life, much easier). All the of the commands we are going though can be inserted into a file called “.vimrc” and should be placed in your home directory (~/.vimc):
sytanx on fieltype indent plugin on
A good idea is to also put in a comment that will help you insert and tweak a few lines if you wish in the future.
# vim: tabstop=8 expandtab shiftwidth=4 softabstop=4
If we were to set all the options above in a running shell session of vim. If you have trouble with this next line, separate out the lines each with a “set.” It would look like so:
:set tabstop=8 expandtab shiftwidth=4 softabstop=4
If the modeline option not turned on by default in your distribution, be sure to turn it on:
Another tip I picked up from the python site, is the option to automatically apply the commented code above for tabstops and so forth. Create/edit the ~/.vim/ftplugin/python.vim file as such:
set tabstop=8 set expandtab set shiftwidth=4 set softtabstop=4
Now, everyone needs a good template header file! Note the spaces inbetween the ” character which let you have multiline comments (vs. the # character). I like to keep it simple:
#!/usr/bin/env python """ SYNOPSIS TODO helloworld [-h,--help] [-v,--verbose] [--version] DESCRIPTION TODO This describes how to use this script. This docstring will be printed by the script if there is an error or if the user requests help (-h or --help). EXAMPLES TODO: Show some examples of how to use this script. EXIT STATUS TODO: List exit codes AUTHOR TODO: Name <email@example.com> LICENSE This script is in the public domain, free from copyrights or restrictions. VERSION $Id$ """
That’s it! Enjoy 🙂