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

Re: cindent

Expand Messages
  • vipin aravind
    Is there any way to specify in the comman mode with line no,s I meant as in a searching string the formating to be done on block of lines. I underatand the =G
    Message 1 of 15 , Mar 1 3:26 PM
    • 0 Attachment
      Is there any way to specify in the comman mode with line no,s
      I meant as in a searching string
      the formating to be done on block of lines.
      I underatand the =G in command mode and gq in visual mode.
      thanks
      vipin

      ----- Original Message -----
      From: Coen Engelbarts <Coen.Engelbarts@...>
      To: Ross A. Osborn <rosborn@...>; VIM Mailing list <vim-dev@...>;
      <vim@...>
      Sent: Friday, March 02, 2001 4:41 PM
      Subject: RE: cindent


      > > > Personally, I can't get <g><q> to work though, and <=>
      > > ignores my "comments"
      > > > settings.
      > >
      > > Do you have "equalprg" set to something?
      >
      > Nope, I checked:
      > equalprg=
      >
      > Other people seem to have the same problem with <=> ignoring the
      "comments"
      > string.
      > That might be a VIM bug.
      >
      > gq does not work on my C comments and formats C-code pretty strange:
      >
      > int test(int a, int B) { int c;
      >
      > return c; }
      >
      > Does anybody have any idea why vim behaves like this?
      > Thanks for any help
      >
      > Coen
      >
      >
      > 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
    • Oguz Akyuz
      A quick and probably an easy question: I would like to enable cindent only for files with extension .c, .cpp, and .h How can I do that? Thanks.
      Message 2 of 15 , Feb 15, 2006
      • 0 Attachment
        A quick and probably an easy question:


        I would like to enable cindent only for files
        with extension .c, .cpp, and .h

        How can I do that?

        Thanks.
      • A. J. Mechelynck
        ... Try adding this (untested) to your vimrc: autocmd FileType * call CheckCIndent() function CheckCIndent() if expand( %:e ) =~ | | set
        Message 3 of 15 , Feb 15, 2006
        • 0 Attachment
          Oguz Akyuz wrote:
          > A quick and probably an easy question:
          >
          >
          > I would like to enable cindent only for files
          > with extension .c, .cpp, and .h
          >
          > How can I do that?
          >
          > Thanks.
          >
          >
          >

          Try adding this (untested) to your vimrc:

          autocmd FileType * call CheckCIndent()
          function CheckCIndent()
          if expand('%:e') =~ '\<c\>\|\<cpp\>\|\<h\>'
          set cindent
          else
          set nocindent
          endif
          endfunction

          Best regards,
          Tony.
        • Peter Slizik
          I d suggest another simple way - use autocommand .vimrc: C/C++ autocommands augroup vimrc_c autocmd! cindent is set by expression indent autocmd
          Message 4 of 15 , Feb 15, 2006
          • 0 Attachment
            I'd suggest another simple way - use autocommand

            .vimrc:

            " C/C++ autocommands
            augroup vimrc_c
            autocmd!
            " cindent is set by expression indent
            autocmd BufNewFile,BufRead *.c,*.cpp,*.h set cindent
            " cinkeys - a list of keys, that cause reindenting
            " of the current line.
            autocmd BufNewFile,BufRead *.c,*.cpp,*.h set cinkeys=0{,0}
            0),:,0#,!^F,o,O,*e,*<CR>
            " Add some other stuff you might like
            augroup END

            For further help, :help autocommand.

            Cheers,

            -- Peter



            > Oguz Akyuz wrote:
            > > A quick and probably an easy question:
            > >
            > >
            > > I would like to enable cindent only for files
            > > with extension .c, .cpp, and .h
            > >
            > > How can I do that?
            > >
            > > Thanks.
            >
            > Try adding this (untested) to your vimrc:
            >
            > autocmd FileType * call CheckCIndent()
            > function CheckCIndent()
            > if expand('%:e') =~ '\<c\>\|\<cpp\>\|\<h\>'
            > set cindent
            > else
            > set nocindent
            > endif
            > endfunction
            >
            > Best regards,
            > Tony.

            --
            There's no trick to being a humorist when you have the whole government
            working for you. --Will Rogers
          • A. J. Mechelynck
            ... This doesn t set nocindent for _other_ filetypes whose ftplugins set cindent (currently: bib.vim [BibTeX]). Best regards, Tony.
            Message 5 of 15 , Feb 15, 2006
            • 0 Attachment
              Peter Slizik wrote:
              > I'd suggest another simple way - use autocommand
              >
              > .vimrc:
              >
              > " C/C++ autocommands
              > augroup vimrc_c
              > autocmd!
              > " cindent is set by expression indent
              > autocmd BufNewFile,BufRead *.c,*.cpp,*.h set cindent
              > " cinkeys - a list of keys, that cause reindenting
              > " of the current line.
              > autocmd BufNewFile,BufRead *.c,*.cpp,*.h set cinkeys=0{,0}
              > 0),:,0#,!^F,o,O,*e,*<CR>
              > " Add some other stuff you might like
              > augroup END
              >
              > For further help, :help autocommand.
              >
              > Cheers,
              >
              > -- Peter

              This doesn't set 'nocindent' for _other_ filetypes whose ftplugins set
              'cindent' (currently: bib.vim [BibTeX]).


              Best regards,
              Tony.
            • Benji Fisher
              ... I like the second suggestion (with BufNewFile,BufRead *.c,*.cpp,*.h) better than the first (with FileType *). Best of all IMHO is autocmd FileType c,cpp I
              Message 6 of 15 , Feb 15, 2006
              • 0 Attachment
                On Wed, Feb 15, 2006 at 02:56:15PM +0100, Peter Slizik wrote:
                >
                > > Oguz Akyuz wrote:
                > > > A quick and probably an easy question:
                > > >
                > > > I would like to enable cindent only for files
                > > > with extension .c, .cpp, and .h
                > > >
                > > > How can I do that?
                > >
                > > Try adding this (untested) to your vimrc:
                > >
                > > autocmd FileType * call CheckCIndent()
                > > function CheckCIndent()
                > > if expand('%:e') =~ '\<c\>\|\<cpp\>\|\<h\>'
                > > set cindent
                > > else
                > > set nocindent
                > > endif
                > > endfunction
                > >
                > > Best regards,
                > > Tony.
                >
                > I'd suggest another simple way - use autocommand
                >
                > .vimrc:
                >
                > " C/C++ autocommands
                > augroup vimrc_c
                > autocmd!
                > " cindent is set by expression indent
                > autocmd BufNewFile,BufRead *.c,*.cpp,*.h set cindent
                > " cinkeys - a list of keys, that cause reindenting
                > " of the current line.
                > autocmd BufNewFile,BufRead *.c,*.cpp,*.h set cinkeys=0{,0}
                > 0),:,0#,!^F,o,O,*e,*<CR>
                > " Add some other stuff you might like
                > augroup END
                >
                > For further help, :help autocommand.

                I like the second suggestion (with BufNewFile,BufRead *.c,*.cpp,*.h)
                better than the first (with FileType *). Best of all IMHO is

                autocmd FileType c,cpp

                I think this will catch all your .c, .cpp, and .h files as well as other
                variants, like .hpp and .c++ and so on. See $VIMRUNTIME/filetype.vim
                for details.

                There is another solution that I like even better than using an
                autocommand. Assuming that you have enabled filetype plugins
                (:help ftplugins) in your vimrc file, any file that is recognized as
                having 'filetype' c or cpp will use the appropriate ftplugin:
                $VIMRUNTIME/ftplugin/c.vim or $VIMRUNTIME/ftplugin/cpp.vim . The
                default ftplugin/cpp.vim just loads all ftplugins for c, including any
                of your own. So all you have to do is create your own ftplugin/c.vim
                (under ~/.vim/ on UNIX or $HOME/vimfiles/ on Windows). In this file,
                you can set 'cindent' and any other options you like.

                HTH --Benji Fisher

                P.S. Pet peeve: posts that mix top-reply and bottom-reply.
              • Peter Slizik
                ... True, indeed. It just seemed to me that Oguz (the guy who posted the original question) was unaware of autocommands. -- Peter -- There s no trick to being
                Message 7 of 15 , Feb 15, 2006
                • 0 Attachment
                  > This doesn't set 'nocindent' for _other_ filetypes whose ftplugins set
                  > 'cindent' (currently: bib.vim [BibTeX]).

                  True, indeed. It just seemed to me that Oguz (the guy who posted the original
                  question) was unaware of autocommands.

                  -- Peter


                  --
                  There's no trick to being a humorist when you have the whole government
                  working for you. --Will Rogers
                • A. J. Mechelynck
                  Benji Fisher wrote: [...] ... When the OP said _only_ for *.c, *.cpp, *.h (emphasis mine) I understood and not for any other files whose ftplugins might
                  Message 8 of 15 , Feb 15, 2006
                  • 0 Attachment
                    Benji Fisher wrote:
                    [...]
                    > I like the second suggestion (with BufNewFile,BufRead *.c,*.cpp,*.h)
                    > better than the first (with FileType *). Best of all IMHO is
                    >
                    > autocmd FileType c,cpp
                    >
                    > I think this will catch all your .c, .cpp, and .h files as well as other
                    > variants, like .hpp and .c++ and so on. See $VIMRUNTIME/filetype.vim
                    > for details.
                    >
                    > There is another solution that I like even better than using an
                    > autocommand. Assuming that you have enabled filetype plugins
                    > (:help ftplugins) in your vimrc file, any file that is recognized as
                    > having 'filetype' c or cpp will use the appropriate ftplugin:
                    > $VIMRUNTIME/ftplugin/c.vim or $VIMRUNTIME/ftplugin/cpp.vim . The
                    > default ftplugin/cpp.vim just loads all ftplugins for c, including any
                    > of your own. So all you have to do is create your own ftplugin/c.vim
                    > (under ~/.vim/ on UNIX or $HOME/vimfiles/ on Windows). In this file,
                    > you can set 'cindent' and any other options you like.
                    >
                    > HTH --Benji Fisher
                    >
                    > P.S. Pet peeve: posts that mix top-reply and bottom-reply.

                    When the OP said " _only_ for *.c, *.cpp, *.h" (emphasis mine) I
                    understood "and not for any other files whose ftplugins might set it"
                    (:vimgrep shows this is currently the case for BibTeX files
                    [ftplugin/bib.vim]; no idea what future filetypes might set it; in
                    addition, several indent scripts set it too). That's why I used
                    "FileType *" and set the option explicitly on or off.

                    If the constraints are relaxed a little (set it for C files and leave it
                    at the default for others), then your solution is best if "filetype
                    indent" is OFF. (If it's ON, then indent/c.vim includes "setlocal cindent".)


                    Best regards,
                    Tony.
                  • Oguz Akyuz
                    Hi, I m sure all the solutions would work (almost) equally well, but I only tried A. J. Mechelynck s first answer and it worked very well for my purpose.
                    Message 9 of 15 , Feb 15, 2006
                    • 0 Attachment
                      Hi,

                      I'm sure all the solutions would work (almost)
                      equally well, but I only tried A. J. Mechelynck's
                      first answer and it worked very well for my purpose.

                      Thanks for all the answers.

                      On 2/15/06, A. J. Mechelynck <antoine.mechelynck@...> wrote:
                      > Benji Fisher wrote:
                      > [...]
                      > > I like the second suggestion (with BufNewFile,BufRead *.c,*.cpp,*.h)
                      > > better than the first (with FileType *). Best of all IMHO is
                      > >
                      > > autocmd FileType c,cpp
                      > >
                      > > I think this will catch all your .c, .cpp, and .h files as well as other
                      > > variants, like .hpp and .c++ and so on. See $VIMRUNTIME/filetype.vim
                      > > for details.
                      > >
                      > > There is another solution that I like even better than using an
                      > > autocommand. Assuming that you have enabled filetype plugins
                      > > (:help ftplugins) in your vimrc file, any file that is recognized as
                      > > having 'filetype' c or cpp will use the appropriate ftplugin:
                      > > $VIMRUNTIME/ftplugin/c.vim or $VIMRUNTIME/ftplugin/cpp.vim . The
                      > > default ftplugin/cpp.vim just loads all ftplugins for c, including any
                      > > of your own. So all you have to do is create your own ftplugin/c.vim
                      > > (under ~/.vim/ on UNIX or $HOME/vimfiles/ on Windows). In this file,
                      > > you can set 'cindent' and any other options you like.
                      > >
                      > > HTH --Benji Fisher
                      > >
                      > > P.S. Pet peeve: posts that mix top-reply and bottom-reply.
                      >
                      > When the OP said " _only_ for *.c, *.cpp, *.h" (emphasis mine) I
                      > understood "and not for any other files whose ftplugins might set it"
                      > (:vimgrep shows this is currently the case for BibTeX files
                      > [ftplugin/bib.vim]; no idea what future filetypes might set it; in
                      > addition, several indent scripts set it too). That's why I used
                      > "FileType *" and set the option explicitly on or off.
                      >
                      > If the constraints are relaxed a little (set it for C files and leave it
                      > at the default for others), then your solution is best if "filetype
                      > indent" is OFF. (If it's ON, then indent/c.vim includes "setlocal cindent".)
                      >
                      >
                      > Best regards,
                      > Tony.
                      >
                      >
                    Your message has been successfully submitted and would be delivered to recipients shortly.