[olug] quick vim question
Brett Burton
brett at burtonbe.homeip.net
Mon Oct 24 18:39:41 UTC 2005
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.
--
Brett Burton
PGP key (DSA ID 746933F4) available at:
https://burtonbe.homeip.net/~brett/pubkey.asc
More information about the OLUG
mailing list