VIM PYTHON 调试

 

 
  
  1. python << EOF  
  2. import time  
  3. import vim  
  4. def SetBreakpoint():  
  5.     nLine = int( vim.eval( 'line(".")'))  
  6.     strLine = vim.current.line  
  7.     i = 0 
  8.     strWhite = ""  
  9.     while strLine[i] == ' ' or strLine[i] == "\t":  
  10.         i += 1 
  11.         strWhite += strLine[i]  
  12.     vim.current.buffer.append(  
  13.        "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %  
  14.          {'space':strWhite, 'mark''#' * 30}, nLine - 1)  
  15.     for strLine in vim.current.buffer:  
  16.         if strLine == "import pdb":  
  17.             break 
  18.         else:  
  19.             vim.current.buffer.append( 'import pdb'0)  
  20.             vim.command( 'normal j1')  
  21.             break 
  22. vim.command( 'map <C-M> :py SetBreakpoint()<cr>')  
  23.    
  24. def RemoveBreakpoints():  
  25.     nCurrentLine = int( vim.eval( 'line(".")'))  
  26.     nLines = []  
  27.     nLine = 1 
  28.     for strLine in vim.current.buffer:  
  29.         if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':  
  30.             nLines.append( nLine)  
  31.         nLine += 1 
  32.     nLines.reverse()  
  33.     for nLine in nLines:  
  34.         vim.command( 'normal %dG' % nLine)  
  35.         vim.command( 'normal dd')  
  36.         if nLine < nCurrentLine:  
  37.             nCurrentLine -= 1 
  38.     vim.command( 'normal %dG' % nCurrentLine)  
  39. vim.command( 'map <C-U> :py RemoveBreakpoints()<cr>')  
  40. vim.command( 'map <C-D> :!python %<cr>')  
  41. EOF  
  42.  

 










本文转自 ibelieveme 51CTO博客,原文链接:http://blog.51cto.com/skyson/493955,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值