[olug] quick vim question
Eric P
eric.maillist at gmail.com
Wed Oct 26 05:32:52 UTC 2005
Brett Burton wrote:
> On Sun, Oct 23, 2005 at 12:00:23AM -0500, Eric P wrote:
>
>>If I have a block of code, what would be a quick and easy way to comment
>>it out in vim like the following (ColdFusion commenting):
>>
>>>From this:
>>
>>do this
>>do that
>>do this
>>do that
>>do this
>>do that
>>
>>
>>To this:
>>
>><!---
>>do this
>>do that
>>do this
>>do that
>>do this
>>do that
>>--->
>>
>>
>>Thanks.
>>Eric P
>>_______________________________________________
>>OLUG mailing list
>>OLUG at olug.org
>>http://lists.olug.org/mailman/listinfo/olug
>
>
> Here's one way to do it:
>
> Put the following line in your .vimrc
>
> vmap sc "zdi<!---<C-R>z---><ESC>
>
> Now when you are in Vim, you can select something in visual mode (using
> the v key) and then hit the s key followed by the c key. That should
> surround your selection with HTML style comments.
>
> I've found it to be pretty useful. I have these statements in my .vimrc
>
> vmap sb "zdi<b><C-R>z</b><ESC>
> vmap si "zdi<i><C-R>z</i><ESC>
> vmap se "zdi<em><C-R>z</em><ESC>
> vmap sp "zdi<p><C-R>z</p><ESC>
>
> ...which allow me to surround text with various HTML tags. Super
> convenient.
>
> A quick word of caution though, if you have leading whitespace in your
> selection, it will screw up the formatting. You can get around this most
> of the time by using visual block mode (ctrl-v) to select a block of
> text excluding the leading whitespace.
>
> PS: Sorry if you got this message twice, it didn't go through the first
> time.
>
Excellent!
I added some <CR> so the comments will be on their own line.
vmap sc "zdi<!---<CR><C-R>z---><CR><ESC>
Thanks again!
Eric P.
More information about the OLUG
mailing list