[DFW.pm] Not only was Patrick right, but Vim backs him up...

Wes Malone wesdmalone at gmail.com
Sat Feb 23 09:32:35 PST 2013


If you haven't already, try out a commenting plugin like nerdcommenter or
tcomment. They both install with pathogen/vundle and work on lots of
different file types, not just Perl.

https://github.com/scrooloose/nerdcommenter
https://github.com/tomtom/tcomment_vim
I think the user is looking for shift-v.  In UNIX vim, ctrl-v is literally
block mode where a rectangular select area can be selected and worked
upon.  shift-v selects entire lines.  In Windows vim I type ctrl-q for
block selection, instead of ctrl-v, but I think this is an optional mapping
I had to add to the config.  I believe the user is referring to the shift-v
mode to select lines.  Also, just v works as well for selecting from a
point in a line to another point, regardless of square blocking or line
blocking.

During a selection, just enter : to start editing a command.  Any
operations can then be performed on the selected area using replace, but
the markers for the start and end of the selected area are '< and '> ,  So,
search and replace like the following works to put a comment at the start
of the line:

:'<,'>s/^/# /

More advance things work like '<,'>s/foo/bar/g and multiple changes can be
stitched with pipes like:

:'<,'>s/^/# / | '<,'>s/foo/bar/g

However, if a piped regex fails to match anything, the regexes in the list
after the non-matching select are not executed.

Also, as far as 'two book marks', that works too, just like line numbers:

:'a,'bs/^/# /

Where, a user wants all lines from mark a to mark b prepended with an
octothorpe and a lacuna.

All these work in normal Vim.  Vim also supports variables in regexes, like
perl.  But, instead of parens in order to block a save for reuse,
backslashes are necessary before the open parens and the close parens.
Regular VI also normally supports the mark changes, eg 'a,'b, but not
visual selections.

Or, did I lose track, and this is a syntax discussion for Perl-vim which
I've never used?

      Andy

--- On *Fri, 2/22/13, Matthew Musgrove <mr.muskrat at gmail.com>* wrote:


From: Matthew Musgrove <mr.muskrat at gmail.com>
Subject: Re: [DFW.pm] Not only was Patrick right, but Vim backs him up...
To: dfw-pm at pm.org
Date: Friday, February 22, 2013, 11:27 PM

My mistake. Ctrl-v.

Matt


On Fri, Feb 22, 2013 at 10:59 PM, Matthew Musgrove
<mr.muskrat at gmail.com<http://mc/compose?to=mr.muskrat@gmail.com>
> wrote:

Going from memory but sounds right...

Position your cursor on the first character of the first line to comment
out. Press 'v' to go into visual character mode. Position your cursor on
the first character of the last line to comment out. Press 'I' to enter
insert mode. Press '#' followed by 'ESC'. Done.

Matt


On Fri, Feb 22, 2013 at 10:29 PM, Tommy Butler <
masterbucket at internetalias.net<http://mc/compose?to=masterbucket@internetalias.net>
> wrote:

Yes, that is definitely handy.

But is there some easier way to do block commenting that doesn't consume
two bookmarks? I find myself doing it based on line numbers, but it hasn't
irritated me enough to look up a better way yet...

-- 
Tommy Butler

kevin <kbrannen at pwhome.com <http://mc/compose?to=kbrannen@pwhome.com>>
wrote:

On 02/21/2013 05:30 PM, Tommy Butler wrote:




What does your .vimrc look like?  I always like to see what goodies
there are to be found in the .vimrc files of fellow Perl hackers :-D


Something I've done for a long time in my .vimrc and find useful is:



map ,c :'a,'bs/^/#/
map ,u :'a,'bs/^#//

Then I can mark a range of lines with 'a and 'b, then hit ,c and the
range is commented out. Similarly, ,u uncomments a range of lines.



Kevin
------------------------------

Dfw-pm mailing list
Dfw-pm at pm.org <http://mc/compose?to=Dfw-pm@pm.org>
http://mail.pm.org/mailman/listinfo/dfw-pm



-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

_______________________________________________

Dfw-pm mailing list
Dfw-pm at pm.org <http://mc/compose?to=Dfw-pm@pm.org>
http://mail.pm.org/mailman/listinfo/dfw-pm




-----Inline Attachment Follows-----

_______________________________________________
Dfw-pm mailing list
Dfw-pm at pm.org <http://mc/compose?to=Dfw-pm@pm.org>
http://mail.pm.org/mailman/listinfo/dfw-pm


_______________________________________________
Dfw-pm mailing list
Dfw-pm at pm.org
http://mail.pm.org/mailman/listinfo/dfw-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/dfw-pm/attachments/20130223/6d0de93a/attachment-0001.html>


More information about the Dfw-pm mailing list