jump to navigation

Convert Vi into a powerful Python IDE March 9, 2009

Posted by razasayed in Hacks, programming.
Tags:
trackback

Below is a simple two step recipe for converting Vi into a full fledged IDE for python . Though there are numerous powerful features which can be added to Vi, to make it more powerful as an IDE, for simplicity’s sake and also to enable newcomers to easily get started with using some of these great features, im gonna share a couple of ways in which you can use Vi as a Python IDE.

These tips would enable you to get all those cool features like code completion , syntax highlighting , automatic indentation in Vi which would definitely make you more productive as a python hacker.

Step 1) For automatic code completion, download the pydiction plugin for Vi, from http://www.vim.org/scripts/script.php?script_id=850

Then, you need to extract this file into  your .vim directory. Assuming its in your home directory e.g.) /home/raza/.vim (If .vim directory does not exist create it), you run the following command from the location where you dowloaded the plugin

tar xvzf pydiction-0.5.tar.gz -C ~/.vim

To use auto-completion, simply press Ctrl-n or Ctrl-p , while in Insert mode.

Step 2) Now, add the following piece of code to your .vimrc file. This file is located either in your home directory or in /etc/vim.
If you dont want to risk messing up your existing .vimrc, you can create a backup of it, and create a new .vimrc file and then paste the following code in it:

[Note:] Dont forget to replace /home/raza/.vim in the code below with the location of your .vim directory

set nocompatible
syntax on
set showmatch
set ignorecase
set showmode
set ts=4
set sw=4
set autoindent
set smartindent
set number
autocmd FileType python runtime! autoload/pythoncomplete.vim
imap <c-space> <c-x><c-o>
:set backspace=2
if has("autocmd")
        autocmd FileType python set complete+=k/home/raza/.vim/pydiction-0.5/pydiction isk+=.,(
        endif " has("autocmd"

filetype plugin on
filetype indent on

" Mappings
nmap <C-N> :noh <CR>

Thats all there is to it ! . If you want to directly execute your program , without having to leave vi, then switch to command mode and execute the following command:

:!python <yourfilename>.py

There are more cool features like adding support for snippets, debugging etc that can be added to Vi, but maybe ill cover them in a later post.
If readers would like to share any more tips for customizing Vi for python development, then you are welcome to post them in your comments.
Hope this makes your python programming more productive and fun.

Happy Hacking ! 🙂

Advertisements

Comments»

1. kunalbharati - March 13, 2009

Python Mode + Emacs = Most powerful IDE in the World!!

Jason - July 21, 2009

YOU ARE THE MAN!!!

a non - May 28, 2011

you dickwad!!!

2. Jake - August 5, 2009

Instead of:
!python .py

you can do:
!python %

Whenever you’re typing an external command from vim you can use % for the currently open file.

Also use it for quickly commit changes to subversion:
:!svn commit % -m “Quickly commited!”

3. Jake - August 5, 2009

Shoot, my &lt &gt got eaten

Should be:
!python &ltyourfilename&gt .py

4. Jake - August 5, 2009

last try: <yourfilename>.py

5. Mohan - August 13, 2009

duh….its nothing compared to WingIDE…this recipe is not an IDE…a good python editor is a better title for this blog

6. v1m g33k - November 16, 2009

this should allow you to run the file by pressing ‘g’ in commmand mode:

map g :!python %

less is more… q

7. v1m g33k - November 16, 2009

map g :!python %


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: