Skip to main content
3 of 5
This question is mostly asking how to properly write a regular expression, so I added it to the tags list.
statox
  • 51.1k
  • 19
  • 158
  • 237

Find a string and add char in front (comment out string w/o loosing indent)

I use VIM to write my Python source and use the debugging library pdb.

Let's say I have this code with break points commented out:

import pdb #pdb.set_trace() def func1(): #pdb.set_trace() foo_bar 

I then want to globally un-comment all the pdb.set_trace() commands. Also, I'll want to re-comment them.

I figured out how to search for the commented string:

^\(\s*#\)\@!\s*pdb.set_trace() 

After this I don't know how to build a string of commands that would globally find the string and add a # to the beginning of the string so as not to mess up the indentation.

wbg
  • 143
  • 6