Skip to main content
The default for vim is "magic", which makes the command as typed look for a physical *, rather than the author's intended meaning of "repeat the last any-character". I fixed it to the standard usage, the other option is to put a \M or \V (nomagic or Very nomagic) before the *.
Source Link

I recently inherited some legacy code and I wanted to replace all occurrences like:

print "xx"
print x,y
print 'xx'

to

logging.info("xy") 

or

logging.info(x,y)

Building on the previous answer and in hopes that someone will benefit from it I used the following scriptcommand, that will change all occurrences:

%s/print\( .\*\*\)/logging.info\(\1\)/g

If you substitute % with . and remove /g you will end up with

.s/print\( .\*\*\)/logging.info\(\1\)

that will enable you to go over each match and choose whether you change it or not.

I recently inherited some legacy code and I wanted to replace all occurrences like:

print "xx"
print x,y
print 'xx'

to

logging.info("xy") 

or

logging.info(x,y)

Building on the previous answer and in hopes that someone will benefit from it I used the following script, that will change all occurrences:

%s/print\( .\*\)/logging.info\(\1\)/g

If you substitute % with . and remove /g you will end up with

.s/print\( .\*\)/logging.info\(\1\)

that will enable you to go over each match and choose whether you change it or not.

I recently inherited some legacy code and I wanted to replace all occurrences like:

print "xx"
print x,y
print 'xx'

to

logging.info("xy") 

or

logging.info(x,y)

Building on the previous answer and in hopes that someone will benefit from it I used the following command, that will change all occurrences:

%s/print\( .*\)/logging.info\(\1\)/g

If you substitute % with . and remove /g you will end up with

.s/print\( .*\)/logging.info\(\1\)

that will enable you to go over each match and choose whether you change it or not.

I recently inherited some legacy code and I wanted to replace all occurrences like: print "xx" print x,y print 'xx' to logging.info("xy")

print "xx"
print x,y
print 'xx'

to

logging.info("xy") 

or logging.info(x,y)

logging.info(x,y)

Building on the previous answer and in hopes that someone will benefit from it iI used the following script, that will change all occurrences: %s/print( .*)/logging.info(\1)/g If

%s/print\( .\*\)/logging.info\(\1\)/g

If you substitute '%'% with '.'. and remove '/g'/g you will end up with .s/print( .*)/logging.info(\1)

.s/print\( .\*\)/logging.info\(\1\)

that you will be ableenable you to go over each match and choose whether you change it or not.

I recently inherited some legacy code and I wanted to replace all occurrences like: print "xx" print x,y print 'xx' to logging.info("xy") or logging.info(x,y) Building on the previous answer and in hopes that someone will benefit from it i used the following script, that will change all occurrences: %s/print( .*)/logging.info(\1)/g If you substitute '%' with '.' and remove '/g' you will end up with .s/print( .*)/logging.info(\1) that you will be able to go over each match and choose whether you change it or not.

I recently inherited some legacy code and I wanted to replace all occurrences like:

print "xx"
print x,y
print 'xx'

to

logging.info("xy") 

or

logging.info(x,y)

Building on the previous answer and in hopes that someone will benefit from it I used the following script, that will change all occurrences:

%s/print\( .\*\)/logging.info\(\1\)/g

If you substitute % with . and remove /g you will end up with

.s/print\( .\*\)/logging.info\(\1\)

that will enable you to go over each match and choose whether you change it or not.

Source Link
yagad
  • 41
  • 1

I recently inherited some legacy code and I wanted to replace all occurrences like: print "xx" print x,y print 'xx' to logging.info("xy") or logging.info(x,y) Building on the previous answer and in hopes that someone will benefit from it i used the following script, that will change all occurrences: %s/print( .*)/logging.info(\1)/g If you substitute '%' with '.' and remove '/g' you will end up with .s/print( .*)/logging.info(\1) that you will be able to go over each match and choose whether you change it or not.