Skip to main content
added 183 characters in body
Source Link
wbg
  • 143
  • 6

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.

UPDATE:

I realized that I need to not re-comment lines with an existing # so I built upon the accepted answer:

To comment out:

:g/\s*\(#\)\@<!pdb.set_trace()/normal I# 

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.

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.

UPDATE:

I realized that I need to not re-comment lines with an existing # so I built upon the accepted answer:

To comment out:

:g/\s*\(#\)\@<!pdb.set_trace()/normal I# 
added 29 characters in body; edited title; edited tags
Source Link
muru
  • 25.4k
  • 8
  • 86
  • 146

Find a string and add char in front (comment How do I comment out string w/o loosing indent)lines without changing indentation?

I use VIMVim 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 
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.

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.

How do I comment out lines without changing indentation?

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.

This question is mostly asking how to properly write a regular expression, so I added it to the tags list.
Source Link
statox
  • 51.1k
  • 19
  • 158
  • 237

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

I use VIM to write my Python source and will 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.

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

I use VIM to write my Python source and will 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.

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.

This question is mostly asking how to properly write a regular expression, so I added it to the tags list.
Link
Loading
Source Link
wbg
  • 143
  • 6
Loading