Windows下,VIM调试python的设置

做者:半瓶墨水 连接:http://www.2maomao.com/blog/win32-vim-debug-python/

vim很好用,可是python的set_trace太难用了,参考这篇文章,本身搞了一下。
如今Ctrl+M插入set_trace,Ctrl+U消除全部set_trace,Ctrl+D运行。以为快捷键不爽的本身改改。
(M=>Mark, U=>Unmark, D=>Do)php

总共四个步骤:html

1. 安装python新版,http://www.python.org,并把python安装目录加入到系统路径python

2. 安装VIM的runscript插件:其做用是在vim脚本中执行python脚本vim

3. 下载python2.4版本的python24.dll, 放到c:\windows\system32目录。(注意,若是你的vim用的不是这个版本,后面的步骤中vim会出错,提示你没有 pythonxx.dll,本身去找相应的版本下载),这个主要配合vim使用,也就是解释下面那一步的脚本的,和你调试的时候所用的python版本没 有关系。windows

4. 把下面这段加入到_vimrc文件里面(我加在最后了):app

python << EOF
import time
import vim
def SetBreakpoint () :
    
nLine = int ( vim . eval ( ' line(".") ' ))
    
strLine = vim . current . line
    
i = 0
    
strWhite = ""
    
while strLine [ i ] == ' ' or strLine [ i ] == " \t " :
        
i += 1
        
strWhite += strLine [ i ]
    
vim . current . buffer . append (
      
" %(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s " %
         {
' space ' : strWhite , ' mark ' : ' # ' * 30 }, nLine - 1 )
    
for strLine in vim . current . buffer :
        
if strLine == " import pdb " :
            
break
        
else :
            
vim . current . buffer . append ( ' import pdb ' , 0 )
            
vim . command ( ' normal j1 ' )
            
break
vim . command ( ' map <C-M> :py SetBreakpoint()<cr> ' )
 
def RemoveBreakpoints () :
    
nCurrentLine = int ( vim . eval ( ' line(".") ' ))
    
nLines = []
    
nLine = 1
    
for strLine in vim . current . buffer :
        
if strLine == ' import pdb ' or strLine . lstrip ()[ : 15 ] == ' pdb.set_trace() ' :
            
nLines . append ( nLine )
        
nLine += 1
    
nLines . reverse ()
    
for nLine in nLines :
        
vim . command ( ' normal %dG ' % nLine )
        
vim . command ( ' normal dd ' )
        
if nLine < nCurrentLine :
            
nCurrentLine -= 1
    
vim . command ( ' normal %dG ' % nCurrentLine )
vim . command ( ' map <C-U> :py RemoveBreakpoints()<cr> ' )
vim . command ( ' map <C-D> :!python %<cr> ' )
EOF

 

转自:http://www.2maomao.com/blog/win32-vim-debug-python/ide

相关文章
相关标签/搜索