Being able to simply debug a piece of code with 'ipython' or set a breakpoint in a pytest/nose is priceless. Also to use the correct python environment for debugging automatically should be transparent.
This plugin adds some python customization to vimspector:
- Choose the correct python executable if in a VIRTUAL_ENV.
- Run pytest/nosetests for the project or test file, with breakpoints in vimspector.
- Debug the current file as a program.
- Launch ipython and attach a debugger to it to debug your code with vimspector.
- Add a strategy to vim-test to allow running a test case in a debugger.
Of course make sure vimspector is installed:
Plug 'puremourning/vimspector'
And also add this:
Plug 'sagi-z/vimspectorpy', { 'do': { -> vimspectorpy#update() } }
Install and setup:
:PlugInstall
:VimspectorpyUpdate
- Install vimspector.
- Clone this repository into your ~/.vim/plugin/ directory.
- From vim execute this command:
:VimspectorpyUpdate
Next time you are on a python source and start a debug session (F5) you'll get this option:
- debug this file - launch a debug session for the current file, using the python from your $VIRTUAL_ENV if there is one, or python3.
These commands are available to you:
" ipython started with debugpy, ready to attach to, but not attached.
" The default name is 'Pyconsole' - it is mapped to a port number you
" can attach to with :Pyattach.
:Pyconsole [name]
" start a debug session with vimspector against the port mapped to by
" 'name'. The default name is 'Pyconsole'.
:Pyattach [name]
" pytest started with debugpy, attached to immediately with vimspector.
" The default name is 'PytestD' - it is mapped to a port number you
" can attach to with :Pyattach, if you accidentally detach from it.
" 'options' are passed on to pytest.
:PytestD [name] [options]
" pytest started with debugpy for the current file, attached to immediately
" with vimspector. The default name is 'PytestD' - it is mapped to a port
" number you can attach to with :Pyattach, if you accidentally detach from it.
" 'options' are passed on to pytest. The path to the current file is appended.
:PytestDThis [name] [options]
" nosetests started with debugpy, attached to immediately with vimspector.
" The default name is 'NosetestsD' - it is mapped to a port number you
" can attach to with :Pyattach, if you accidentally detach from it.
" 'options' are passed on to nosetests.
:NosetestsD [name] [options]
" nosetests started with debugpy for the current file, attached to immediately
" with vimspector. The default name is 'NosetestsD' - it is mapped to a port
" number you can attach to with :Pyattach, if you accidentally detach from it.
" 'options' are passed on to nosetests. The path to the current file is appended.
:NosetestsDThis [name] [options]
" This installs/updates this plugin's external dependencies:
" * A virtualenv with ipython and debugpy.
" * Some default configurations for {vimspector} python filetype.
:VimspectorpyUpdate
This plugin will not override command names you defined yourself. To avoid naming conflicts you could add a prefix to its commands.
This will make all the 'Py...' commands start with 'VS' (VSPyconsole, VSPyattach, ...):
let g:vimspectorpy#cmd_prefix = "VS"
For starting another window the plugin will use tmux automatically in a console and 'xterm' in GUI.
You could choose 'rxvt' or force 'xterm' using:
let g:vimspectorpy#launcher = "rxvt"
If you are using the excellent vim-test plugin, then now you can choose a strategy to open the test in a vimspector debugger:
let test#strategy = "vimspectorpy"
For the most up to date docs use :help vimspectorpy
MIT