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

No folds for C Functions

Expand Messages
  • Manu Anand
    Hi: I noticed that VIM supports folds for some languages but not for C , C++ and java.Is there some plugin which will do this? I don t want to do this
    Message 1 of 3 , Nov 3, 2003
    • 0 Attachment
      Hi:

      I noticed that VIM supports folds for some languages but not for "C" , C++ and java.Is there some plugin which will do this?
      I don't want to do this explicitely.

      Thanks
      -Manu
    • Gary Johnson
      ... One way to do this, which is what I do, is to put this in your .vimrc: au BufNewFile,BufRead *.c,*.h setlocal foldmethod=marker au BufNewFile,BufRead
      Message 2 of 3 , Nov 3, 2003
      • 0 Attachment
        On 2003-11-03, Manu Anand <Manu.Anand@...> wrote:
        > Hi:
        >
        > I noticed that VIM supports folds for some languages but not for
        > "C" , C++ and java.Is there some plugin which will do this?
        > I don't want to do this explicitely.

        One way to do this, which is what I do, is to put this in your
        .vimrc:

        au BufNewFile,BufRead *.c,*.h setlocal foldmethod=marker
        au BufNewFile,BufRead *.c,*.h setlocal foldmarker={,}

        You could also just add those settings (without the autocommands) to
        your own .../ftplugin/c.vim file.

        How well that works for you may depend on where you place your
        braces. The style used here has opening and closing braces on lines
        by themselves. I also redefined the Folder highlighting and defined
        my own 'foldtext' function for an overall effect that I like better
        than the default.

        highlight clear Folded
        highlight Folded term=bold ctermfg=4 guifg=Blue

        set foldtext=MyFoldText()

        function! MyFoldText()
        let n = v:foldend - v:foldstart + 1
        let i = indent(v:foldstart)
        let istr = ''
        while i > 0
        let istr = istr . ' '
        let i = i - 1
        endwhile
        return istr . "+-" . v:folddashes . " " . n . " lines "
        endfunction

        HTH,
        Gary

        --
        Gary Johnson | Agilent Technologies
        garyjohn@... | Wireless Division
        | Spokane, Washington, USA
      • Manu Anand
        ... Thanks Gary It works like a charm. Makes browsing kernel code that much fun. VIM Rocks -Manu
        Message 3 of 3 , Nov 3, 2003
        • 0 Attachment
          > On 2003-11-03, Manu Anand <Manu.Anand@...> wrote:
          > > Hi:
          > >
          > > I noticed that VIM supports folds for some languages but not for
          > > "C" , C++ and java.Is there some plugin which will do this?
          > > I don't want to do this explicitely.
          >
          > One way to do this, which is what I do, is to put this in your
          > .vimrc:
          >
          > au BufNewFile,BufRead *.c,*.h setlocal foldmethod=marker
          > au BufNewFile,BufRead *.c,*.h setlocal foldmarker={,}
          >
          > You could also just add those settings (without the autocommands) to
          > your own .../ftplugin/c.vim file.
          >
          > How well that works for you may depend on where you place your
          > braces. The style used here has opening and closing braces on lines
          > by themselves. I also redefined the Folder highlighting and defined
          > my own 'foldtext' function for an overall effect that I like better
          > than the default.
          >
          > highlight clear Folded
          > highlight Folded term=bold ctermfg=4 guifg=Blue
          >
          > set foldtext=MyFoldText()
          >
          > function! MyFoldText()
          > let n = v:foldend - v:foldstart + 1
          > let i = indent(v:foldstart)
          > let istr = ''
          > while i > 0
          > let istr = istr . ' '
          > let i = i - 1
          > endwhile
          > return istr . "+-" . v:folddashes . " " . n . " lines "
          > endfunction
          >
          Thanks Gary
          It works like a charm. Makes browsing kernel code that much fun.
          VIM Rocks

          -Manu
        Your message has been successfully submitted and would be delivered to recipients shortly.