[olug] quick vim question

Brett Burton brett at burtonbe.homeip.net
Thu Oct 27 03:22:10 UTC 2005


On Wed, Oct 26, 2005 at 12:32:52AM -0500, Eric P wrote:
> 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.
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug

That pasting problem was bothering me, so I investigated it.  To fix the
pasting problems from leading whitespace, try doing this command before
inserting those comment statements:

set paste

Then when you're done do:

set nopaste

That /should/ fix it. See ":help 'paste" for more info.

-- 
Brett Burton

PGP key (DSA ID 746933F4) available at: 
https://burtonbe.homeip.net/~brett/pubkey.asc



More information about the OLUG mailing list