Two kinds of comment insertion by VIM

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Two kinds of comment insertion by VIM

Eric Leenman
Hi,

Is it possible to let VIM insert two kinds of insert at the next line
when I press enter?
I make my comment blocks as:
// ***************
// * Line 1
// * Line 2
// ***************

And to comment a piece of code I just use
// blabla
// and more blabla

Is it possible to let VIM insert on the next line when I press enter:
- ' // * ' [this is //<space>*<space>] when the previous line started as
'// * '?
- ' // ' [this is //<space>] when the previous line started '// '?

Kind regards,

Eric Leenman


Disclaimer; The information contained in this communication is confidential
and may be legally privileged. It is intended solely for the use of the individual
or entity to whom it is addressed and others authorized to recieve it.
Use of this information, in whatever way, by others is strictly prohibited
and may be unlawful. GREEFA does not accept legal responsibility
for this e-mail message due to the insecure nature of internet
communications.  
Reply | Threaded
Open this post in threaded view
|

Re: Two kinds of comment insertion by VIM

Gary Johnson
On 2005-09-19, Eric Leenman <[hidden email]> wrote:

> Hi,
>
> Is it possible to let VIM insert two kinds of insert at the next line
> when I press enter?
> I make my comment blocks as:
> // ***************
> // * Line 1
> // * Line 2
> // ***************
>
> And to comment a piece of code I just use
> // blabla
> // and more blabla
>
> Is it possible to let VIM insert on the next line when I press enter:
> - ' // * ' [this is //<space>*<space>] when the previous line started as
> '// * '?
> - ' // ' [this is //<space>] when the previous line started '// '?

Sure.  You can set the 'comments' option to include both like this:

    set comments=://\ *,://

You will also need to add 'r' to the list of 'formatoptions' so that
the comment leader will be inserted when you hit <Enter> in Insert
mode:

    set formatoptions+=r
See

    :help comments
    :help formatoptions
    :help fo-table

HTH,
Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA