Quantcast

set comments for C-style comment

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

set comments for C-style comment

Monnand
Hi all,

I am using a language whose comment is same as C's. So I copied some lines from c.vim so that my vim could automatically insert a comment after a newline in the middle of the comment.

More precisely, I added the two following lines:

setlocal fo-=t fo+=cronql
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://

It works but with some flaws:

When I type /* <CR>, I got this:
/*
*

It can correctly automatically generate the *, but no space in front.

However, what I want is this (notice the space in the second line):
/*
 *

It should generate <space>* after I type Enter (or "o" in command mode).

I think it should be very easy by setting comments option. But I still cannot figure it out. It would be nice if anyone could help me on this.

Regards,
-Monnand

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: set comments for C-style comment

Simon Ruderich-2
On Sun, Sep 02, 2012 at 04:49:00PM -0700, Monnand wrote:

> Hi all,
>
> I am using a language whose comment is same as C's. So I copied
> some lines from c.vim so that my vim could automatically insert
> a comment after a newline in the middle of the comment.
>
> More precisely, I added the two following lines:
>
> setlocal fo-=t fo+=cronql
> setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
>
> It works but with some flaws:
>
> When I type /* <CR>, I got this:
> /*
> *
> [snip]
Hello,

I just tested it locally by putting the commands in a file and
running Vim with:

    vim -u NONE -U NONE

    :source path/to/file

And it works fine for me. Some other settings must interfere with
your setup.

Are you sure the settings are executed? Try

    :verbose set fo? comments?

If not, something must overwrite them. :verbose lists the last
place the option was set.

Regards,
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: set comments for C-style comment

Monnand
On Monday, September 3, 2012 10:36:39 AM UTC-4, Simon Ruderich wrote:

> On Sun, Sep 02, 2012 at 04:49:00PM -0700, Monnand wrote:
>
> > Hi all,
>
> >
>
> > I am using a language whose comment is same as C's. So I copied
>
> > some lines from c.vim so that my vim could automatically insert
>
> > a comment after a newline in the middle of the comment.
>
> >
>
> > More precisely, I added the two following lines:
>
> >
>
> > setlocal fo-=t fo+=cronql
>
> > setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
>
> >
>
> > It works but with some flaws:
>
> >
>
> > When I type /* <CR>, I got this:
>
> > /*
>
> > *
>
> > [snip]
>
>
>
> Hello,
>
>
>
> I just tested it locally by putting the commands in a file and
>
> running Vim with:
>
>
>
>     vim -u NONE -U NONE
>
>
>
>     :source path/to/file
>
>
>
> And it works fine for me. Some other settings must interfere with
>
> your setup.
>
>
>
> Are you sure the settings are executed? Try
>
>
>
>     :verbose set fo? comments?
>
>
>
> If not, something must overwrite them. :verbose lists the last
>
> place the option was set.
>
<snip>

Thank you, Simon. I think they are executed. here is the output of :verbose set fo? comments?:

  formatoptions=croq
        Last set from ~/.vim/bundle/vim-golang/indent/go.vim
  comments=sO:* -,mO:*  ,exO:*/,s1:/*,mb:*,ex:*/,://
        Last set from ~/.vim/bundle/vim-golang/indent/go.vim

BTW, I am using Go programming language as you can tell from the output above.

It is true that I put my settings in  ~/.vim/bundle/vim-golang/indent/go.vim

Any other idea?

Regards,
-Monnand

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: set comments for C-style comment

Simon Ruderich-2
On Mon, Sep 03, 2012 at 02:11:59PM -0700, Monnand wrote:
> Thank you, Simon. I think they are executed. here is the output
> of :verbose set fo? comments?:
>
>   formatoptions=croq
>         Last set from ~/.vim/bundle/vim-golang/indent/go.vim
>   comments=sO:* -,mO:*  ,exO:*/,s1:/*,mb:*,ex:*/,://
>         Last set from ~/.vim/bundle/vim-golang/indent/go.vim

Looks fine.

> BTW, I am using Go programming language as you can tell from
> the output above.
>
> It is true that I put my settings in  ~/.vim/bundle/vim-golang/indent/go.vim

Normally ftplugin/go.vim is used for file-related settings.
indent/go.vim is for automatic indentation settings. Settings
like 'formatoptions' should be set in ftplugin/go.vim.

But the location of the setting shouldn't be related to your
problems and is just convention.

> Any other idea?

Is 'paste' set? It prevents automatic formatting.

    :set paste?

Regards,
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

attachment0 (853 bytes) Download Attachment
Loading...