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

Re: autocmd & folder

Expand Messages
  • Steven Woody
    ... Sorry, I may not get the point. I check the help, but what should I do? currently my folder settings are in ~/vimfiles/filetype.vim, au BufNewFile,BufRead
    Message 1 of 5 , Oct 3, 2009
    • 0 Attachment
      On Sat, Oct 3, 2009 at 5:09 PM, Andy Wokula <anwoku@...> wrote:
      >
      > Steven Woody schrieb:
      >> Hi,
      >>
      >> I set a autocmd for *.c file, that is
      >>
      >> au BufNewFile,BufRead *.c           call s:cfold()
      >> func! s:cfold()
      >>     set fdls=0
      >>     set fdm=syntax
      >> endfun
      >>
      >> Now, I am editing a foo.c file and folder set correctly and
      >> automatically.  Then I opened some folder in the buffer using 'za' or
      >> something like that.  And, then I switch to another buffer, and go
      >> back.  At this point, I hope what I've already opened folder keeps
      >> open as that when I left,  but it is not, all the folders closed just
      >> like what they are when I firstly open the file.
      >>
      >> Please give me a hint!  Thanks.
      >
      >    :h 'foldlevelstart'
      > it is a global option, not to be set when detecting a filetype.
      >
      > see also
      >    :h ft-c-syntax
      >
      > --
      > Andy

      Sorry, I may not get the point. I check the help, but what should I
      do? currently my folder settings are in ~/vimfiles/filetype.vim,

      au BufNewFile,BufRead *.c call s:cfold()
      au BufNewFile,BufRead *.cpp call s:cfold()
      au BufNewFile,BufRead *.h call s:cfold()

      func! s:cfold()
      set fdls=0
      set fdm=syntax
      endfun
      --
      Life is the only flaw in an otherwise perfect nonexistence
      -- Schopenhauer

      narke
      public key at http://subkeys.pgp.net:11371 (narkewoody@...)

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Ben Fritz
      ... What Andy was trying to point out is, foldlevelstart is a global option, meant to be set only once in your .vimrc. It looks like you want to set
      Message 2 of 5 , Oct 3, 2009
      • 0 Attachment
        On Oct 3, 10:05 am, Steven Woody <narkewo...@...> wrote:
        >
        > >    :h 'foldlevelstart'
        > > it is a global option, not to be set when detecting a filetype.
        >
        > > see also
        > >    :h ft-c-syntax
        >
        > > --
        > > Andy
        >
        > Sorry, I may not get the point. I check the help, but what should I
        > do?  currently my folder settings are in ~/vimfiles/filetype.vim,
        >
        > au BufNewFile,BufRead *.c           call s:cfold()
        > au BufNewFile,BufRead *.cpp         call s:cfold()
        > au BufNewFile,BufRead *.h           call s:cfold()
        >
        > func! s:cfold()
        >     set fdls=0
        >     set fdm=syntax
        > endfun

        What Andy was trying to point out is, 'foldlevelstart' is a global
        option, meant to be set only once in your .vimrc.

        It looks like you want to set 'foldlevel' rather than 'foldlevelstart'
        on a file-by-file basis.

        But, 'foldlevelstart' should do that anyway, I'm not sure why you even
        need this.
        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... Using :set on an option whenever a file is opened, clobbers the setting for all files already opened in parallel. You should use :setlocal instead. In
        Message 3 of 5 , Oct 31, 2009
        • 0 Attachment
          On 03/10/09 21:03, Ben Fritz wrote:
          >
          >
          >
          > On Oct 3, 10:05 am, Steven Woody<narkewo...@...> wrote:
          >>
          >>> :h 'foldlevelstart'
          >>> it is a global option, not to be set when detecting a filetype.
          >>
          >>> see also
          >>> :h ft-c-syntax
          >>
          >>> --
          >>> Andy
          >>
          >> Sorry, I may not get the point. I check the help, but what should I
          >> do? currently my folder settings are in ~/vimfiles/filetype.vim,
          >>
          >> au BufNewFile,BufRead *.c call s:cfold()
          >> au BufNewFile,BufRead *.cpp call s:cfold()
          >> au BufNewFile,BufRead *.h call s:cfold()
          >>
          >> func! s:cfold()
          >> set fdls=0
          >> set fdm=syntax
          >> endfun
          >
          > What Andy was trying to point out is, 'foldlevelstart' is a global
          > option, meant to be set only once in your .vimrc.
          >
          > It looks like you want to set 'foldlevel' rather than 'foldlevelstart'
          > on a file-by-file basis.
          >
          > But, 'foldlevelstart' should do that anyway, I'm not sure why you even
          > need this.

          Using ":set" on an option whenever a file is opened, clobbers the
          setting for all files already opened in parallel. You should use
          ":setlocal" instead.

          In addition, *.cpp, *.c, *.h are already recognised as c or cpp
          'filetype', and the standard cpp ftplugin calls all those installed for
          c, so you should remove all these autocommands and place instead:

          in your ~/_vimrc or ~/.vimrc:
          if has('folding')
          set foldlevelstart=0
          endif

          in ~/vimfiles/after/ftplugin/c.vim (Windows) or
          ~/.vim/after/ftplugin/c.vim (Unix):
          if has('folding')
          setlocal foldmethod=syntax
          endif

          - If those files and/or directories don't exist yet, create them.
          - If you don't want to apply the same 'foldlevelstart' setting to files
          of a different 'filetype', remove the 'foldlevelstart' setting from the
          vimrc altogether, and add within the if-statement in the
          after/ftplugin/c.vim:
          setlocal foldlevel=0


          Best regards,
          Tony.
          --
          "We demand rigidly defined areas of doubt and uncertainty!"
          -- Vroomfondel

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.