I use a variant of that approach for Vim.
In my .vimrc file:
"=====[ Add or subtract comments ]===============================
function ToggleComment ()
let currline = getline(".")
if currline =~ '^#'
map <silent> # :call ToggleComment()<CR>j0
Thereafter hitting #
in Normal mode either inserts a
comment marker(if the line doesn't have one) or removes it (if one was
already there). Either way, the cursor is then moved to the next line
ready to dish out more of the same treatment.
The upshot is that a series of #'s runs you down the file,
toggling the commentedness of each line.
However, for inserting/removing long blocks of comments I find Visual mode the
easiest solution. Navigate to the start of the first (or last) line on which you want to insert
comments. Then type CTRL-V to enter Visual Block mode.
Then navigate to the other end of the block of code you want to comment,
using any of the normal Vim motion commands. Then type
To subsequently remove a block of column-1 comments: CTRL-V(navigate to other
UPDATE: Added missing if line and corrected else (thanks Jack!)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||