Loading ...
Sorry, an error occurred while loading the content.

Autoformat and C comments

Expand Messages
  • Coen Engelbarts
    Hi, The internal C formatting function ( :help = )seems to use different settings than the comments string indicates. The default comments string is:
    Message 1 of 5 , Feb 23 4:28 AM
    • 0 Attachment
      Hi,

      The internal C formatting function (":help =")seems to use different
      settings than the "comments" string indicates.

      The default "comments" string is:
      comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-"
      This gives comments like this:
      /*
      * Comment text
      */

      My company's coding standard uses:
      /*
      ** Comment text
      */

      So I use this command:
      autocmd FileType c,cpp set formatoptions=croql cindent
      comments=sr:/*,mb:**,ex:*/,://

      This works great for typing comments, but when I select a block of text and
      press [=] to re-format/re-indent the code, the comments are changed into
      this:

      /*
      ** Comment text
      */

      How can I correct this?
      I can't find this in any help text (cindent, autoindent, comments, fo-table,
      format-comments, smartindent, cinkeys, cinwords, cinoptions, formatoptions,
      cinoptions-values, etc.) or mailing list archive.

      Thanks for any help,

      Coen Engelbarts


      I use Vim 5.7 on VMS with the following settings and version:


      :set all
      --- Options ---
      aleph=224 nohidden previewheight=12 tagstack
      noallowrevins history=50 noreadonly
      term=builtin_gui
      noaltkeymap nohkmap remap noterse
      autoindent nohkmapp report=2 textauto
      noautowrite hlsearch norevins notextmode
      background=light icon norightleft textwidth=78
      backspace=2 iconstring= ruler notildeop
      nobackup ignorecase rulerformat= timeout
      backupext=_ incsearch scroll=24
      timeoutlen=1000
      nobinary noinfercase noscrollbind title
      browsedir=last noinsertmode scrolljump=1 titlelen=85
      nocindent isprint=@,161-255 scrolloff=4 titlestring=
      cinoptions= joinspaces nosecure nottimeout
      clipboard= key= selectmode= ttimeoutlen=-1
      cmdheight=2 keymodel= shell= ttybuiltin
      columns=80 keywordprg=help shellcmdflag=-c ttyfast
      nocompatible langmap= shellpipe=> ttymouse=dec
      noconfirm laststatus=1 shellquote= ttyscroll=999
      cpoptions=aABceFs nolazyredraw shellredir=>
      undolevels=1000
      dictionary= nolinebreak shellxquote=
      updatecount=200
      nodigraph lines=50 noshiftround
      updatetime=4000
      display= nolisp shiftwidth=8 verbose=0
      noedcompatible nolist noshortname
      viminfo='20,"50
      endofline listchars=eol:$ showbreak= visualbell
      equalalways magic showcmd warn
      equalprg= makeprg=make noshowfulltag noweirdinvert
      noerrorbells matchtime=5 showmatch whichwrap=b,s
      esckeys maxfuncdepth=100 showmode wildchar=<Tab>
      eventignore= maxmapdepth=1000 sidescroll=0 wildcharm=^@
      expandtab maxmem=512 smartcase wildignore=
      noexrc maxmemtot=2048 nosmartindent nowildmenu
      fileencoding=ansi modeline smarttab wildmode=full
      fileformat=unix modelines=5 softtabstop=4
      winaltkeys=menu
      filetype=vim nomodified nosplitbelow winheight=1
      nofkmap more startofline winminheight=1
      formatprg= mouse=a statusline= wrap
      nogdefault nomousefocus swapfile wrapmargin=0
      grepprg=grep -n mousehide swapsync=fsync nowrapscan
      guifont= mousemodel=extend switchbuf= write
      guifontset= mousetime=500 syntax=vim nowriteany
      guiheadroom=50 nonumber tabstop=8 nowritebackup
      guioptions=agimrt nopaste notagbsearch writedelay=0
      guipty pastetoggle= taglength=0
      helpheight=20 patchmode= tagrelative
      backupdir=./,sys$login:,tmp:
      breakat= ^I!@*-+_;:,./?
      cinkeys=0{,0},:,0#,!^F,o,O,e
      -- More --
      nofkmap more startofline winminheight=1
      formatprg= mouse=a statusline= wrap
      nogdefault nomousefocus swapfile wrapmargin=0
      grepprg=grep -n mousehide swapsync=fsync nowrapscan
      guifont= mousemodel=extend switchbuf= write
      guifontset= mousetime=500 syntax=vim nowriteany
      guiheadroom=50 nonumber tabstop=8 nowritebackup
      guioptions=agimrt nopaste notagbsearch writedelay=0
      guipty pastetoggle= taglength=0
      helpheight=20 patchmode= tagrelative
      backupdir=./,sys$login:,tmp:
      breakat= ^I!@*-+_;:,./?
      cinkeys=0{,0},:,0#,!^F,o,O,e
      cinwords=if,else,while,do,for,switch
      comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
      complete=.,w,b,u,t,i
      define=^#\s*define
      directory=./,sys$login:,tmp:
      errorfile=errors.err
      errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%f:%l:%m,"%f"\, line
      %l%*\D%c%
      *[^ ] %m,%D%*\a[%*\d]: Entering directory `%f',%X%*\a[%*\d]: Leaving
      directory `
      %f',%DMaking %*\a in %f
      fileformats=unix,dos
      formatoptions=tcql
      grepformat=%f:%l%m,%f %l%m

      guicursor=n-v-c:block-Cursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Curso
      r,
      r-cr:hor20-Cursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
      helpfile=USER_DISK:[USER.ENGELBARTS.BIN.VIM]doc/help.txt

      highlight=8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search
      ,m
      :MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v
      :Vis
      ual,V:VisualNOS,w:WarningMsg,W:WildMenu
      include=^#\s*include
      isfname=@,48-57,/,.,-,_,+,,,$,~
      isident=@,48-57,_,192-255
      iskeyword=@,48-57,_,192-255
      makeef=tmp:vim##.err
      matchpairs=(:),{:},[:]
      nrformats=octal,hex
      paragraphs=IPLPPPQPP LIpplpipbp
      path=.,/usr/include,,
      scrollopt=ver,jump
      sections=SHNHH HUnhsh
      selection=inclusive
      sessionoptions=buffers,winsize,options,help,blank
      shortmess=filnxtToO
      suffixes=.bak,~,.o,.h,.info,.swp,.obj
      tags=tags,TMP:tags,SYS$LOGIN:tags
      titleold=Thanks for flying Vim
      ttytype=builtin_gui
      Press RETURN or enter command to continue


      :version
      VIM - Vi IMproved 5.7 (2000 Jun 24, compiled Jun 27 2000 09:11:09)
      OpenVMS version
      Compiled by ZAY@PLUTO (pluto.essnet.se), with (+) or without (-):
      +autocmd +browse ++builtin_terms +byte_offset +cindent +cmdline_compl
      +cmdline_info +comments +cryptv -cscope +dialog_con_gui +digraphs
      +emacs_tags
      +eval +ex_extra +extra_search +farsi +file_in_path -osfiletype +find_in_path
      +GUI_Motif -hangul_input +insert_expand +langmap +linebreak +lispindent
      +menu
      +mksession +modify_fname +mouse +mouse_dec -mouse_gpm +mouse_netterm
      +mouse_xterm +multi_byte -perl -python +quickfix +rightleft +scrollbind
      +smartindent -sniff +statusline +syntax +tag_binary +tag_old_static
      -tag_any_white -tcl +tgetent +textobjects +title +user_commands +visualextra
      +viminfo +wildignore +wildmenu -writebackup +X11 +xfontset -xim -xterm_save
      system vimrc file: "$VIM/vimrc"
      user vimrc file: "sys$login:.vimrc"
      2nd user vimrc file: "sys$login:_vimrc"
      user exrc file: "sys$login:.exrc"
      2nd user exrc file: "sys$login:_exrc"
      system gvimrc file: "$VIM/gvimrc"
      user gvimrc file: "sys$login:.gvimrc"
      2nd user gvimrc file: "sys$login:_gvimrc"
      system menu file: "$VIMRUNTIME/menu.vim"
      Compilation: cc/decc /incl=[] /def=(HAVE_CONFIG_H,USE_GUI_MOTIF )
      /opt/prefix
      =all/include=[.proto]
      Compiler: DEC C V6.0-001 on OpenVMS Alpha V7.1
      Linking: link /exe=vim.exe *.obj ,OS_VMS.OPT/OPT
      Press RETURN or enter command to continue
    • Jay Glanville
      You have: comments=sr:/*,mb:**,ex:*/,:// try this: comments=sr:/*,m:**,ex:*/,:// I believe that the b stands for a blank. ... From: Coen Engelbarts
      Message 2 of 5 , Feb 23 4:34 AM
      • 0 Attachment
        You have: comments=sr:/*,mb:**,ex:*/,://
        try this: comments=sr:/*,m:**,ex:*/,://

        I believe that the b stands for a blank.

        -----Original Message-----
        From: Coen Engelbarts [mailto:Coen.Engelbarts@...]
        Sent: Friday, February 23, 2001 7:29 AM
        To: vim@...
        Subject: Autoformat and C comments


        Hi,

        The internal C formatting function (":help =")seems to use different
        settings than the "comments" string indicates.

        The default "comments" string is:
        comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-"
        This gives comments like this:
        /*
        * Comment text
        */

        My company's coding standard uses:
        /*
        ** Comment text
        */

        So I use this command:
        autocmd FileType c,cpp set formatoptions=croql cindent
        comments=sr:/*,mb:**,ex:*/,://

        This works great for typing comments, but when I select a block of text and
        press [=] to re-format/re-indent the code, the comments are changed into
        this:

        /*
        ** Comment text
        */

        How can I correct this?
        I can't find this in any help text (cindent, autoindent, comments, fo-table,
        format-comments, smartindent, cinkeys, cinwords, cinoptions, formatoptions,
        cinoptions-values, etc.) or mailing list archive.

        Thanks for any help,

        Coen Engelbarts
      • Coen Engelbarts
        Nope, this gives the same results. According to :help cormat-comments , this b indicates a blank space between the ** and the start of the comment. What I
        Message 3 of 5 , Feb 23 5:01 AM
        • 0 Attachment
          Nope, this gives the same results.
          According to ":help cormat-comments", this 'b' indicates a blank space
          between the "**" and the start of the comment.
          What I REALLY don't get, is the fact that I still get that blank space, even
          though I now have:
          comments=sr:/*,m:**,ex:*/,://

          If I use::
          comments=sl:/*,mb:**,ex:*/,://
          I still get exactly the same results.

          Coen

          > -----Original Message-----
          > From: Jay Glanville [mailto:dickon@...]
          > Sent: 23 February 2001 13:34
          > To: Vim Mailing List (Text)
          > Cc: Coen Engelbarts
          > Subject: RE: Autoformat and C comments
          >
          >
          > You have: comments=sr:/*,mb:**,ex:*/,://
          > try this: comments=sr:/*,m:**,ex:*/,://
          >
          > I believe that the b stands for a blank.
          >
          > -----Original Message-----
          > From: Coen Engelbarts [mailto:Coen.Engelbarts@...]
          > Sent: Friday, February 23, 2001 7:29 AM
          > To: vim@...
          > Subject: Autoformat and C comments
          >
          >
          > Hi,
          >
          > The internal C formatting function (":help =")seems to use different
          > settings than the "comments" string indicates.
          >
          > The default "comments" string is:
          > comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-"
          > This gives comments like this:
          > /*
          > * Comment text
          > */
          >
          > My company's coding standard uses:
          > /*
          > ** Comment text
          > */
          >
          > So I use this command:
          > autocmd FileType c,cpp set formatoptions=croql cindent
          > comments=sr:/*,mb:**,ex:*/,://
          >
          > This works great for typing comments, but when I select a
          > block of text and
          > press [=] to re-format/re-indent the code, the comments are
          > changed into
          > this:
          >
          > /*
          > ** Comment text
          > */
          >
          > How can I correct this?
          > I can't find this in any help text (cindent, autoindent,
          > comments, fo-table,
          > format-comments, smartindent, cinkeys, cinwords, cinoptions,
          > formatoptions,
          > cinoptions-values, etc.) or mailing list archive.
          >
          > Thanks for any help,
          >
          > Coen Engelbarts
          >
        • Zdenek Sekera
          ... No, this is a blank space between the ** and the following string. Even if you were correct, the fact that straight typing in and the = operator
          Message 4 of 5 , Feb 23 5:02 AM
          • 0 Attachment
            Jay Glanville wrote:
            >
            > You have: comments=sr:/*,mb:**,ex:*/,://
            > try this: comments=sr:/*,m:**,ex:*/,://
            >
            > I believe that the b stands for a blank.

            No, this is a blank space between the '**' and the following string.
            Even if you were correct, the fact that straight 'typing in' and the
            '=' operator behave differently is not correct.
            ...

            Original poster:
            >
            > The default "comments" string is:
            > comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-"
            > This gives comments like this:
            > /*
            > * Comment text
            > */
            >
            > My company's coding standard uses:
            > /*
            > ** Comment text
            > */
            >
            > So I use this command:
            > autocmd FileType c,cpp set formatoptions=croql cindent
            > comments=sr:/*,mb:**,ex:*/,://
            >
            > This works great for typing comments, but when I select a block of text and
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            > press [=] to re-format/re-indent the code, the comments are changed into
            > this:
            >
            > /*
            > ** Comment text
            > */

            ---Zdenek
          • Coen Engelbarts
            Thanks, but I can t seem to get gq to work. I do a visual select of some twisted comment lines in gvim and press and then . All I see is that the visual
            Message 5 of 5 , Mar 1, 2001
            • 0 Attachment
              Thanks, but I can't seem to get gq to work.
              I do a visual select of some twisted comment lines in gvim and press <g> and
              then <q>.
              All I see is that the visual selection is deselected. The comments stays
              out-of-whack.

              Am I doing something wrong?

              Thanks,

              Coen


              > -----Original Message-----
              > From: Marcelo E. Magallon [mailto:marcelo.magallon@...]
              > Sent: 23 February 2001 18:42
              > To: Coen Engelbarts
              > Cc: vim@...
              > Subject: Re: Autoformat and C comments
              >
              >
              > >> Coen Engelbarts <Coen.Engelbarts@...> writes:
              >
              > > So I use this command:
              > > autocmd FileType c,cpp set formatoptions=croql cindent
              > > comments=sr:/*,mb:**,ex:*/,://
              >
              > I just tried this, and it works fine if I use gq, but behaves as you
              > describe if I use =
              >
              > --
              > Marcelo
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.