views:

84

answers:

2

Hi,

I have so many println("") in my codes .. I know it is messy ... I want to put comment for each of the println("");

how to do that in VIM ? I mean I want to do that on multiple files.

Also if possible, can it detect whether the lines has // already or not ... if the lines has been commented .. I don't want to add new //

+1  A: 

To append a //comment to all uncommented println(...) calls on their own lines:

:%s/^\(\s*println(.*);\)\s*$/\1\/\/comment/gc

To comment out all the uncommented println(...) calls on their own lines

:%s/^\(\s*println(.*);\)\s*$/\/\/\1/gc
Amarghosh
A: 

You could also use the :global command:

:g|println|normal I//

:g executes the command (here :normal I//) on all the lines when the first argument (here println) matches.

Also if you want to do this on all opened buffers, use the :bufdo command:

:bufdo g|println|normal I//

And to only do this on uncommented lines Amarghosh's regexp is perfect:

:bufdo g|\s*println(.*);|normal I//
Jim