how to comment lot of lines in python
Tim Chase
python.list at tim.thechases.com
Thu Mar 30 18:59:21 EST 2006
>>Or there is something else too ??
>
> You should use a decent editor that could automatically
> comment/uncomment code upon your request.
In Vim, you can map a key to do the following:
:s/^/#
to comment the highlighted lines, and
:s/^#
to uncomment them. To map them, you can use
:vnoremap <f4> :s/^/#<cr>
:vnoremap <f5> :s/#<cr>
(those are literal "less-than, ["eff, [4 | 5]" | "see,
are"], greater-than" characters)
Then, pressing <f4> in visual mode will comment the selected
lines, and pressing <f5> will uncomment any selected lines
that are commented.
The nice thing about vim's method of doing this, is that you
can combine it with grepping. If you want to comment out
every line containing a regexp, you can do
:g/regexp/s/^/#
Or, if you want to comment out from "regexp_1" to the
following line containing "regexp_2", you can use
:g/regexp_1/.,/regexp2/s/^/#
All sorts of handy tricks.
There are python plugins that I'm sure offer such abilities
built-in. There are likely ways to do this in other editors
too. I just happen to be a vim sorta guy.
-tkc
More information about the Python-list
mailing list