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

Matt Musgrove MMusgrove at efji.com
Tue Feb 26 15:11:08 PST 2013


For how I was using it, ctrl-v was the appropriate means of selecting the first character of each line so that typing I#ESC (shift-i shift-3 ESC) would comment out each line. It only comments out the first line if you select all of the lines with v or shift-v.

Matt

From: Dfw-pm [mailto:dfw-pm-bounces+mmusgrove=efji.com at pm.org] On Behalf Of Andy Robertson
Sent: Saturday, February 23, 2013 9:42 AM
To: dfw-pm at pm.org
Subject: Re: [DFW.pm] Not only was Patrick right, but Vim backs him up...

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<mailto:mr.muskrat at gmail.com>> wrote:

From: Matthew Musgrove <mr.muskrat at gmail.com<mailto: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<mailto: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</mc/compose?to=mr.muskrat at 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</mc/compose?to=masterbucket at 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</mc/compose?to=kbrannen at 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</mc/compose?to=Dfw-pm at 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</mc/compose?to=Dfw-pm at pm.org>
http://mail.pm.org/mailman/listinfo/dfw-pm



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


This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain confidential information. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, distribution, review, copy or use of any of the information contained in or attached to this message is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify us by reply e-mail, and destroy the original transmission and its attachments without reading them or saving them to disk. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/dfw-pm/attachments/20130226/949955b2/attachment.html>


More information about the Dfw-pm mailing list