Breakpoint Python VS Code Extension
This extension allows you to quickly add, remove, and toggle breakpoint() statements in your code with simple commands, keyboard shortcuts (F9), and visual indicators.
Features
- Add
breakpoint(): Insert a breakpoint() statement above your cursor position with proper indentation
- Remove
breakpoint(): Remove breakpoint() statements from the current line or adjacent lines
- Toggle
breakpoint(): Smart toggle that adds breakpoints when none exist, or removes them when they do (Python files only)
- Visual indicators: Shows gutter icons next to lines containing
breakpoint() statements in Python files
- Multi-selection support: Works with multiple cursors and selections
- Smart indentation: Automatically maintains proper code indentation
Usage
Command Palette
Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on Mac) and type:
- "Breakpoint Python: Add Breakpoint()" - Insert a
breakpoint() at the cursor
- "Breakpoint Python: Remove Breakpoint()" - Remove
breakpoint() from the current/adjacent lines
- "Breakpoint Python: Toggle Python Breakpoint" - Toggle breakpoints (Python files only)
Keyboard Shortcuts
- F9 - Toggle breakpoint (Python files only)
- Ctrl+Shift+B - Add breakpoint (any file)
- Ctrl+Shift+Alt+B - Remove breakpoint (any file)
Right-click in the editor to access:
- Add Breakpoint()
- Remove Breakpoint()
- Toggle Python Breakpoint (Python files only)
Visual Indicators
In Python files, you'll see gutter icons next to lines that contain breakpoint() statements.
Note: This extension does not support gutter clicking. Use keyboard shortcuts or commands instead.
How It Works
Add Breakpoint
- Inserts
breakpoint() on a new line above your cursor position
- Maintains proper indentation based on the current line
- Won't add duplicates if a breakpoint already exists on the same line
Remove Breakpoint
- Removes
breakpoint() statements from the current line
- Also checks adjacent lines (above and below) for breakpoints to remove
- Handles multiple selections efficiently
Toggle Breakpoint (Python only)
- If no breakpoint exists near the cursor, adds one
- If a breakpoint exists on the current line or adjacent lines, removes it
- Works with multiple selections to toggle breakpoints on multiple lines at once
Language Support
- Add/Remove commands: Work in any file type
- Toggle command: Restricted to Python files (
.py)
- Visual indicators: Only shown in Python files
Enhanced Debugging with ipdb
For a better debugging experience, consider using ipdb instead of the standard pdb:
What is ipdb?
ipdb is an enhanced Python debugger that provides:
- Syntax highlighting in the debugger console
- Tab completion for variables and methods
- Better error messages and stack traces
- IPython integration with magic commands
Installation
pip install ipdb
Usage with this Extension
Once ipdb is installed, Python's breakpoint() function will automatically use ipdb instead of pdb when available. The extension works exactly the same way - just insert breakpoint() statements and enjoy the enhanced debugging experience!
Alternative: Set ipdb as default
You can also set ipdb as your default debugger by setting the PYTHONBREAKPOINT environment variable:
# In your shell profile (.bashrc, .zshrc, etc.)
export PYTHONBREAKPOINT=ipdb.set_trace
# Or for a single session
PYTHONBREAKPOINT=ipdb.set_trace python your_script.py
ipdb Commands
Some useful ipdb commands once you hit a breakpoint:
l (list) - Show current code context
n (next) - Execute next line
s (step) - Step into functions
c (continue) - Continue execution
pp variable_name - Pretty print a variable
h (help) - Show all available commands
Notes
- The extension intelligently handles indentation to match your code style
- Multiple cursor/selection support allows bulk operations
- The toggle functionality is optimized for Python development workflows
- Visual gutter indicators help you quickly identify where breakpoints are placed
- Works seamlessly with both pdb and ipdb - no configuration needed!