Skip to main content

Vim and Pdb integration

Project description

Abstract

This package provides an integration of the Python debugger pdb into the VIM editor.

Requirements

vimpdb has been used successfully under Linux, Mac OSX and Windows.

It is compatible with Python 2.6, 2.5 and 2.4. It is not known if it does work with Python 3.0 (let us know).

vimpdb requires an installation of VIM that supports both python and clientserver options.

Find out if it is the case by issuing the following command at the VIM prompt:

:version

If the options are supported, you will see +clientserver and +python in the output. In the opposite case, you will see -clientserver or -python.

On Linux and Windows, the default VIM build should already be server-enabled.

On Windows, the python option compiled in VIM depends on a specific Python version. Find out if that specific version is installed and works in VIM by issuing the following command at the VIM prompt:

:python import sys; print sys.version

On Mac OSX, you’ll want to use MacVIM. MacVIM also has the python option compiled in by default.

Installation

Just install this package using easy_install or similar:

$ easy_install vimpdb

If you look inside the package, you will see a VIM script file: vimpdb.vim. Do not move it to VIM configuration directory (like ~/.vim/plugin).

Configuration

You might need to setup the VIMPDB_VIMSCRIPT environment variable. It should hold the command used at the shell prompt to launch a VIM supporting the options mentioned above. (Default value is vimpdb).

On Windows, it should hold the path to vim.exe, not to gvim.exe. Furthermore, do not include quotes in the enviromnent variable to take care of whitespace in the path.

This script should also set the --servername option to specify a server name. You can think of this as a “window name” which is used to send remote commands to – this is how vimpdb communicates with a certain VIM instance.

Server Name

You might need to setup the VIMPDB_SERVERNAME environment variable. It should hold the name of the VIM server you will be using. (Default value is VIMPDB). You may list the currently running VIM servers using:

$ vim --serverlist
VIM

Or, on a Mac:

$ /Applications/MacVim.app/Contents/MacOS/Vim --serverlist
VIM

Note that the default servername is VIM

Starting a VIM Server for Debugging

To start a VIM server for debugging, issue following command on the shell:

$ vim --servername VIMPDB

Or, on a Mac, if you installed the mvim script:

$ mvim --servername VIMPDB

When a VIM supporting clientserver option has started, you can find its name by issuing the following command at the VIM prompt:

:echo v:servername

Using

Using vimpdb is easy – just call set_trace as usual:

import vimpdb; vimpdb.set_trace()

Now, when the python interpreter hits that line, VIM will get the focus and load the source file.

You may now use the following commands:

VimPDB Commands

Key

Command

n

Next

s

Step

a

Args

u

Up

d

Down

r

Return

c

Continue

b

Sets a breakpoint at the line on which the cursor is sitting.

w

Displays the value of the word on which the cursor is sitting.

x

Switch to debugging with standard Pdb.

v

Switch back to VimPdb from plain Pdb.

Standard Pdb hook

If you find it hard to change habits and keep on typing

import pdb; pdb.set_trace()

you can add the following line to the .pdbrc file sitting in your home folder:

import vimpdb; vimpdb.hookPdb()

This way, the command v(im) mentioned above is added to your standard Pdb and you can switch to vimpdb at any time.

Known issues

  • No convenient way to evaluate a Python expression.

Fixed issues

  • Fixed in 0.3.5 : broken on Windows.

  • Fixed in 0.3.3 : when you stop debugging, the buffers which you debugged with are left in an inconvenient state : the keys mapped to Pdb commands are still mapped. In other words, switching from debugging to fixing code is not convenient.

CREDITS

Changelog

0.3.5 (2010-03-22)

  • better documentation, especially for Windows

  • fix capture of output that was broken for Python 2.5 and 2.6

  • Windows compatibility (at least XP)

0.3.4 (2010-03-15)

  • close socket to allow debugging session to start again

0.3.3 (2010-03-04)

  • avoid leaving mappings in debugged buffers

0.3.2 (2010-03-03)

  • more documentation

0.3.1 (2010-03-02)

  • fix setup.py metadata so that it does not hold non ascii chars. This avoided actual release to PyPI

0.3 (2010-03-02)

  • fully rewritten

0.2.1 (2008-06-27)

  • added vimpdb script

  • added “exit” callback

0.2 (2008-06-17)

  • first release to PyPi

TODO

  • add option to allow other network settings (instead of hardcoded)

  • try to start Vim server if it is not started

  • try to guess Vim server name to avoid use of VIMPDB_SERVERNAME

  • check and complain if Vim does not support the right options

  • register menu

  • register mapping to call PDB_reset_original_mapping

  • switch from read-only to edit when changing buffer

  • and much more…

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vimpdb-0.3.5.tar.gz (9.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page