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

Simple hiding all comments by folding

Expand Messages
  • arctgx
    Is there a simple universal command which hides all comments in file by current syntax? I would like, for example hide comments in my shell scripts (syntax=sh)
    Message 1 of 17 , Dec 31, 2007
    • 0 Attachment
      Is there a simple universal command which hides all comments in file
      by current syntax? I would like, for example hide comments in my shell
      scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
      text about folding but I still can't find a good solution.

      I tried
      set foldmarker=#,$ | set foldmethod=marker

      but it is not universal solution and... hides all lines of shell
      script ;) ($ doesn't denote end of line?)
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... From :help foldmarker : The marker is a literal string (a regular explession would be too slow). So, no, $ means a literal dollar sign, not the end of
      Message 2 of 17 , Dec 31, 2007
      • 0 Attachment
        arctgx wrote:
        > Is there a simple universal command which hides all comments in file
        > by current syntax? I would like, for example hide comments in my shell
        > scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
        > text about folding but I still can't find a good solution.
        >
        > I tried
        > set foldmarker=#,$ | set foldmethod=marker
        >
        > but it is not universal solution and... hides all lines of shell
        > script ;) ($ doesn't denote end of line?)

        From ":help 'foldmarker'":

        "The marker is a literal string (a regular explession would be too slow)."

        So, no, $ means a literal dollar sign, not the end of the line.

        You could define a custom 'foldexpr' and set 'foldmethod' to "expr".

        Maybe (untested)

        :setlocal fdm=expr fde=getline(v:lnum)[0]\ ==\ '#'

        to tell Vim that a line is "in a fold" iff it starts with a #

        This is adapted from what is said at ":help fold-expr".

        A little more powerful, but slower (and also untested):

        :setlocal fdm=expr fde=getline(v:lnum)\ =~\ '^\\s\\*#'

        to recognise lines starting with zero or more whitespace plus one # character.

        To set this when the 'filetype' is "sh" or "xf86conf" you could for instance
        add one of the above ":setlocal" lines (without the initial colon) in each of
        two files named ~/.vim/after/ftplugin/sh.vim and
        ~/.vim/after/ftplugin/xf86conf.vim (create the files and/or directories if
        they don't yet exist). This way the setting will be set after running the
        standard ftplugin for the same filetypes.


        Best regards,
        Tony.
        --
        Some people are born mediocre, some people achieve mediocrity, and some
        people have mediocrity thrust upon them.
        -- Joseph Heller, "Catch-22"

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Ben Schmidt
        ... No. Foldmarker needs to include two literal strings that need to occur on different lines to define a fold. What you have above will be folding between a
        Message 3 of 17 , Dec 31, 2007
        • 0 Attachment
          arctgx wrote:
          > Is there a simple universal command which hides all comments in file
          > by current syntax? I would like, for example hide comments in my shell
          > scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
          > text about folding but I still can't find a good solution.
          >
          > I tried
          > set foldmarker=#,$ | set foldmethod=marker
          >
          > but it is not universal solution and... hides all lines of shell
          > script ;) ($ doesn't denote end of line?)

          No. Foldmarker needs to include two literal strings that need to occur on
          different lines to define a fold. What you have above will be folding between a
          line that contains # and a line that contains $ (though with multiple lines
          containing # without enough matching $s it will end up with lots of nested folds
          that don't end).

          I don't think there's currently really any way to do what you want. You could
          conceivably write or modify syntax files to do it and use foldmethod=syntax, but
          there'd be plenty of work involved, particularly since, for the most part, 'long'
          comments in shell scripts and such are actually not long comments, but lots of
          short comments one after the other. You'd have to modify the syntax highlighting
          to recognise multiple consecutive comments actually as large single comments.
          Folding single /* ... */ C comments would be relatively easy, as they don't suffer
          from that problem, but folding multiple // ... C++ or # ... shell script comments
          together in one fold would be relatively hard.

          What most people do is manually mark comments for folding if they want it. Using
          foldmarkder={{{,}}} then you write

          # {{{ comment starts here
          # and continues
          # and continues
          # and then ends:
          # }}}

          Hope this helps,

          Ben.





          Send instant messages to your online friends http://au.messenger.yahoo.com


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Charles E. Campbell, Jr.
          ... Inline comments can t be folded away; at least, not without Vince Negri s conceal patch to vim. Others have already made suggestions about folding
          Message 4 of 17 , Dec 31, 2007
          • 0 Attachment
            arctgx wrote:

            >Is there a simple universal command which hides all comments in file
            >by current syntax? I would like, for example hide comments in my shell
            >scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
            >text about folding but I still can't find a good solution.
            >
            >I tried
            >set foldmarker=#,$ | set foldmethod=marker
            >
            >but it is not universal solution and... hides all lines of shell
            >script ;) ($ doesn't denote end of line?)
            >
            >

            Inline comments can't be folded away; at least, not without Vince
            Negri's "conceal" patch to vim. Others have already made suggestions
            about folding markers, so I won't repeat that. One thing you could do
            instead is to highlight-link comments to something like Ignore and then
            back to Comment. For example, *.sh scripts' comments are shComment, so
            you could use (untested) something like:

            map <f1> if !exists("cmmnt_toggle")<bar><bar>cmmnt_toggle == 0<bar>let
            cmmnt_toggle=1<bar>hi link shComment Ignore<bar>else<bar>let
            cmmnt_toggle= 0<bar>hi link shComment Comment<bar>endif<cr>

            to toggle between normally highlighted comments and "Ignore"'d comments.

            Regards,
            Chip Campbell


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • A.Politz
            ... The following will fold commented lines,including pre- and succeeding empty ones. All it needs is a correct syntax plugin. This can be slow, as noted at
            Message 5 of 17 , Jan 1, 2008
            • 0 Attachment
              arctgx wrote:

              >Is there a simple universal command which hides all comments in file
              >by current syntax? I would like, for example hide comments in my shell
              >scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
              >text about folding but I still can't find a good solution.
              >
              >I tried
              >set foldmarker=#,$ | set foldmethod=marker
              >
              >but it is not universal solution and... hides all lines of shell
              >script ;) ($ doesn't denote end of line?)
              >>
              >
              >
              The following will fold commented lines,including pre- and succeeding
              empty ones. All it needs is a correct syntax plugin.
              This can be slow, as noted at ':h synID'. It would maybe be faster to
              use 'comment*' options, but then it wouldn't be simple anymore ;-).

              -----------------%<-----------------
              "(no linebreaks intended)
              set fdm=expr
              set
              fde=IsComment(v:lnum)?1:IsComment(prevnonblank(v:lnum))?1:IsComment(nextnonblank(v:lnum))?1:0


              func! IsComment( lnum )
              return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1, 1),
              "name") =~? 'comment'
              endfun
              -----------------%<-----------------

              -ap


              --
              Ich hab geträumt, der Krieg wär vorbei.


              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • A.Politz
              ... fde=IsComment(v:lnum)?1:IsComment(prevnonblank(v:lnum-1))?1:IsComment(nextnonblank(v:lnum+1))?1:0 ... Added [+-]1 to *nonblank , which is what I
              Message 6 of 17 , Jan 1, 2008
              • 0 Attachment
                A.Politz wrote:

                >arctgx wrote:
                >
                >
                >
                >>Is there a simple universal command which hides all comments in file
                >>by current syntax? I would like, for example hide comments in my shell
                >>scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
                >>text about folding but I still can't find a good solution.
                >>
                >>I tried
                >>set foldmarker=#,$ | set foldmethod=marker
                >>
                >>but it is not universal solution and... hides all lines of shell
                >>script ;) ($ doesn't denote end of line?)
                >>
                >>
                >>
                >>
                >>
                >>
                >The following will fold commented lines,including pre- and succeeding
                >empty ones. All it needs is a correct syntax plugin.
                >This can be slow, as noted at ':h synID'. It would maybe be faster to
                >use 'comment*' options, but then it wouldn't be simple anymore ;-).
                >
                >-----------------%<-----------------
                >"(no linebreaks intended)
                >set fdm=expr
                >set
                >
                >
                fde=IsComment(v:lnum)?1:IsComment(prevnonblank(v:lnum-1))?1:IsComment(nextnonblank(v:lnum+1))?1:0


                >func! IsComment( lnum )
                > return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1, 1),
                >"name") =~? 'comment'
                >endfun
                >-----------------%<-----------------
                >
                >-ap
                >
                >
                >
                >
                Added '[+-]1' to '*nonblank', which is what I actually wanted to
                do in the first place.

                -ap

                --
                Ich hab geträumt, der Krieg wär vorbei.


                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Martin Lange
                ... bashism ahead! Protect the innocent! You can fake a multiline comment in bash-scripts. Use a here script , which is defined as command
                Message 7 of 17 , Jan 1, 2008
                • 0 Attachment
                  At Tuesday 01 January 2008 05:00:05, Ben Schmidt wrote:

                  > You could conceivably write or modify syntax files to do it and use
                  > foldmethod=syntax, but there'd be plenty of work involved,
                  > particularly since, for the most part, 'long' comments in shell
                  > scripts and such are actually not long comments, but lots of short
                  > comments one after the other. (...)

                  bashism ahead! Protect the innocent!

                  You can fake a multiline comment in bash-scripts. Use a "here script",
                  which is defined as

                  command << token
                  content to be used as command's standard input
                  token

                  For "command" use the colon:

                  $ help :
                  :: :
                  No effect; the command does nothing. A zero exit code is returned.

                  For "token" invent something nice, which didn't have sideeffects.
                  (Unfortunally, the "standard" 3 curly brackets have.) Add that "token"
                  to the syntax file and proceed with "foldmethod=syntax".

                  The idea is stolen from the 'Net, but I didn't remember the URL. So,
                  credits to whoever it was.

                  HTH.

                  Martin "vi"
                • Ben Schmidt
                  ... LOL. What fun. Of course, the downside of most of the approaches everyone has mentioned is that they need the user to do work while writing the file. Nicer
                  Message 8 of 17 , Jan 1, 2008
                  • 0 Attachment
                    Martin Lange wrote:
                    > At Tuesday 01 January 2008 05:00:05, Ben Schmidt wrote:
                    >
                    >> You could conceivably write or modify syntax files to do it and use
                    >> foldmethod=syntax, but there'd be plenty of work involved,
                    >> particularly since, for the most part, 'long' comments in shell
                    >> scripts and such are actually not long comments, but lots of short
                    >> comments one after the other. (...)
                    >
                    > bashism ahead! Protect the innocent!
                    >
                    > You can fake a multiline comment in bash-scripts. Use a "here script",
                    > which is defined as
                    >
                    > command << token
                    > content to be used as command's standard input
                    > token
                    >
                    > For "command" use the colon:
                    >
                    > $ help :
                    > :: :
                    > No effect; the command does nothing. A zero exit code is returned.
                    >
                    > For "token" invent something nice, which didn't have sideeffects.
                    > (Unfortunally, the "standard" 3 curly brackets have.) Add that "token"
                    > to the syntax file and proceed with "foldmethod=syntax".
                    >
                    > The idea is stolen from the 'Net, but I didn't remember the URL. So,
                    > credits to whoever it was.
                    >
                    > HTH.
                    >
                    > Martin "vi"

                    LOL.

                    What fun.

                    Of course, the downside of most of the approaches everyone has mentioned is that
                    they need the user to do work while writing the file. Nicer would be if we could
                    just open anybody's file and have the functionality there. I think A. Politz'
                    approach is closest so far--a good bit of lateral thinking. Having only had a
                    quick look, I think it could probably do with refinement, and expect that would be
                    slow too, but still, with a bit of work...

                    Grins,

                    Ben.



                    Send instant messages to your online friends http://au.messenger.yahoo.com


                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • A.Politz
                    ... I just noticed, that this is wrong and the first solution is correct. I was to busy looking at the performance. -ap -- Ich hab geträumt, der Krieg wär
                    Message 9 of 17 , Jan 1, 2008
                    • 0 Attachment
                      A.Politz wrote:

                      >A.Politz wrote:
                      >
                      >
                      >
                      >>arctgx wrote:
                      >>
                      >>
                      >>
                      >>
                      >>
                      >>>Is there a simple universal command which hides all comments in file
                      >>>by current syntax? I would like, for example hide comments in my shell
                      >>>scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
                      >>>text about folding but I still can't find a good solution.
                      >>>
                      >>>I tried
                      >>>set foldmarker=#,$ | set foldmethod=marker
                      >>>
                      >>>but it is not universal solution and... hides all lines of shell
                      >>>script ;) ($ doesn't denote end of line?)
                      >>>
                      >>>
                      >>>
                      >>>
                      >>>
                      >>>
                      >>>
                      >>>
                      >>The following will fold commented lines,including pre- and succeeding
                      >>empty ones. All it needs is a correct syntax plugin.
                      >>This can be slow, as noted at ':h synID'. It would maybe be faster to
                      >>use 'comment*' options, but then it wouldn't be simple anymore ;-).
                      >>
                      >>-----------------%<-----------------
                      >>"(no linebreaks intended)
                      >>set fdm=expr
                      >>set
                      >>
                      >>
                      >>
                      >>
                      >fde=IsComment(v:lnum)?1:IsComment(prevnonblank(v:lnum-1))?1:IsComment(nextnonblank(v:lnum+1))?1:0
                      >
                      >
                      >
                      >
                      >>func! IsComment( lnum )
                      >> return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1, 1),
                      >>"name") =~? 'comment'
                      >>endfun
                      >>-----------------%<-----------------
                      >>
                      >>-ap
                      >>
                      >>
                      >>
                      >>
                      >>
                      >>
                      >Added '[+-]1' to '*nonblank', which is what I actually wanted to
                      >do in the first place.
                      >
                      >-ap
                      >
                      >
                      >
                      I just noticed, that this is wrong and the first solution is correct.
                      I was to busy looking at the performance.

                      -ap

                      --
                      Ich hab geträumt, der Krieg wär vorbei.


                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • A.Politz
                      ... Ok, here is a working and faster version. ... set fdm=expr set fde=FoldComments(v:lnum) func! FoldComments( lnum ) if getline( . ) =~ S return
                      Message 10 of 17 , Jan 1, 2008
                      • 0 Attachment
                        A.Politz wrote:

                        >A.Politz wrote:
                        >
                        >
                        >
                        >>arctgx wrote:
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>>Is there a simple universal command which hides all comments in file
                        >>>by current syntax? I would like, for example hide comments in my shell
                        >>>scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
                        >>>text about folding but I still can't find a good solution.
                        >>>
                        >>>I tried
                        >>>set foldmarker=#,$ | set foldmethod=marker
                        >>>
                        >>>but it is not universal solution and... hides all lines of shell
                        >>>script ;) ($ doesn't denote end of line?)
                        >>>
                        >>>
                        >>>
                        >>>
                        >>>
                        >>>
                        >>>
                        >>>
                        >>The following will fold commented lines,including pre- and succeeding
                        >>empty ones. All it needs is a correct syntax plugin.
                        >>This can be slow, as noted at ':h synID'. It would maybe be faster to
                        >>use 'comment*' options, but then it wouldn't be simple anymore ;-).
                        >>
                        >>...
                        >>
                        >
                        >

                        Ok, here is a working and faster version.


                        -----------%<--------------
                        set fdm=expr
                        set fde=FoldComments(v:lnum)

                        func! FoldComments( lnum )
                        if getline('.') =~ '\S'
                        return IsComment(a:lnum)
                        else
                        return IsComment(prevnonblank(a:lnum)) ||
                        IsComment(nextnonblank(a:lnum))
                        endif
                        endfun

                        func! IsComment( lnum )
                        return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1, 1),
                        "name") =~? 'comment'
                        endfun
                        -----------%<--------------

                        -ap


                        --
                        Ich hab geträumt, der Krieg wär vorbei.


                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • arctgx
                        ...after this discussion it seems that folding all comments isn t so basic operation and requires some special work. Thank you all very much for rich answer.
                        Message 11 of 17 , Jan 1, 2008
                        • 0 Attachment
                          ...after this discussion it seems that folding all comments isn't so
                          basic operation and requires some special work.

                          Thank you all very much for rich answer. I need some time to test it
                          (and much time to understand those tips in though partly detail). I
                          would like to describe effects of those tips there.

                          best regards
                          Tomasz
                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_use" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---
                        • arctgx
                          I wouldn t like to insert into file any strings ({{{, token etc.) that are deserve only to define fold range, especially as I open some files only for
                          Message 12 of 17 , Jan 6, 2008
                          • 0 Attachment
                            I wouldn't like to insert into file any strings ({{{, 'token' etc.)
                            that are deserve only to define fold range, especially as I open some
                            files only for reading.

                            Vince Negri's patch doesn't exists for 7.1 vim version. I tried to
                            patch 7.1 but patching exited with fails. Charles, does your commands
                            work only with this patch (E492: Not an editor command:
                            cmmnt_toggle=1<bar>hi link shComment Ign)?

                            A.Politz, I tested your functions on following text:

                            *************************************
                            # vim syntax=sh :
                            # c1cccccccc
                            # c2cccccccc
                            nnn1nnnnnnnn
                            nnn2nnnnnnnn
                            nnn3nnnnnnnn
                            # c3cccccccc
                            # c4cccccccc
                            # c5cccccccc
                            # c6cccccccc
                            nnn4nnnnnnnn
                            nnn5nnnnnnnn
                            nnn6nnnnnnnn
                            # c7cccccccc
                            # c8cccccccc
                            # c9cccccccc
                            nnn7nnnnnnnn
                            # c10ccccccc
                            nnn8nnnnnnnn
                            # c11ccccccc
                            nnn9nnnnnnnn
                            *****************************************************


                            Loading source with
                            ******************
                            set fdm=expr
                            set fde=IsComment(v:lnum)?1:IsComment(prevnonblank(v:lnum-1))?
                            1:IsComment(nextnonblank(v:lnum+1))?1:0
                            func! FoldComments( lnum )
                            if getline('.') =~ '\S'
                            return IsComment(a:lnum)
                            else
                            return IsComment(prevnonblank(a:lnum)) ||
                            IsComment(nextnonblank(a:lnum))
                            endif
                            endfun

                            func! IsComment( lnum )
                            return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1,
                            1),"name") =~? 'comment'
                            endfun

                            ******************
                            gives
                            ******************
                            +-- 4 lines: #
                            c1cccccccc-----------------------------------------------------------------------------------
                            nnn2nnnnnnnn
                            +-- 6 lines:
                            nnn3nnnnnnnn-----------------------------------------------------------------------------------
                            nnn5nnnnnnnn
                            +-- 9 lines:
                            nnn6nnnnnnnn-----------------------------------------------------------------------------------
                            ******************



                            Loading source with
                            ******************
                            gives
                            ******************
                            +-- 4 lines: #
                            c1cccccccc-----------------------------------------------------------------------------------
                            nnn2nnnnnnnn
                            +-- 6 lines:
                            nnn3nnnnnnnn-----------------------------------------------------------------------------------
                            nnn5nnnnnnnn
                            +-- 9 lines:
                            nnn6nnnnnnnn-----------------------------------------------------------------------------------
                            ******************

                            ******************
                            set fdm=expr
                            set fde=FoldComments(v:lnum)
                            func! FoldComments( lnum )
                            if getline('.') =~ '\S'
                            return IsComment(a:lnum)
                            else
                            return IsComment(prevnonblank(a:lnum)) ||
                            IsComment(nextnonblank(a:lnum))
                            endif
                            endfun

                            func! IsComment( lnum )
                            return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1,
                            1),"name") =~? 'comment'
                            endfun
                            ******************
                            gives
                            ******************
                            +-- 3 lines: #
                            c1cccccccc-----------------------------------------------------------------------------------
                            nnn1nnnnnnnn
                            nnn2nnnnnnnn
                            nnn3nnnnnnnn
                            +-- 4 lines: #
                            c3cccccccc-----------------------------------------------------------------------------------
                            nnn4nnnnnnnn
                            nnn5nnnnnnnn
                            nnn6nnnnnnnn
                            +-- 3 lines: #
                            c7cccccccc-----------------------------------------------------------------------------------
                            nnn7nnnnnnnn
                            # c10ccccccc
                            nnn8nnnnnnnn
                            # c11ccccccc
                            nnn9nnnnnnnn
                            ******************
                            but in practice those solutions may sometimes work fine after loading
                            them into vim :)
                            --~--~---------~--~----~------------~-------~--~----~
                            You received this message from the "vim_use" maillist.
                            For more information, visit http://www.vim.org/maillist.php
                            -~----------~----~----~----~------~----~------~--~---
                          • arctgx
                            Warning: there isn t any new line char in source between e.g. +-- 4 lines: # and c3cccccccc----------------------------------... . They became in output
                            Message 13 of 17 , Jan 6, 2008
                            • 0 Attachment
                              Warning: there isn't any new line char in source between e.g. "+-- 4
                              lines: # " and "c3cccccccc----------------------------------...".
                              They became in output text after sending.
                              --~--~---------~--~----~------------~-------~--~----~
                              You received this message from the "vim_use" maillist.
                              For more information, visit http://www.vim.org/maillist.php
                              -~----------~----~----~----~------~----~------~--~---
                            • A.Politz
                              ... The 1st and 3rd versions work, the 2nd doesn t, as I said. Your 1st version is my 2nd, which don t work and your 2nd, which is my 3rd does work, but maybe
                              Message 14 of 17 , Jan 6, 2008
                              • 0 Attachment
                                arctgx wrote:

                                > I wouldn't like to insert into file any strings ({{{, 'token' etc.)
                                >that are deserve only to define fold range, especially as I open some
                                >files only for reading.
                                >
                                >Vince Negri's patch doesn't exists for 7.1 vim version. I tried to
                                >patch 7.1 but patching exited with fails. Charles, does your commands
                                >work only with this patch (E492: Not an editor command:
                                >cmmnt_toggle=1<bar>hi link shComment Ign)?
                                >
                                >A.Politz, I tested your functions on following text:
                                >
                                >...
                                >
                                >******************
                                > set fdm=expr
                                > set fde=FoldComments(v:lnum)
                                > func! FoldComments( lnum )
                                > if getline('.') =~ '\S'
                                > return IsComment(a:lnum)
                                > else
                                > return IsComment(prevnonblank(a:lnum)) ||
                                >IsComment(nextnonblank(a:lnum))
                                > endif
                                > endfun
                                >
                                > func! IsComment( lnum )
                                > return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1,
                                >1),"name") =~? 'comment'
                                > endfun
                                >******************
                                >gives
                                >******************
                                >+-- 3 lines: #
                                >c1cccccccc-----------------------------------------------------------------------------------
                                >nnn1nnnnnnnn
                                >nnn2nnnnnnnn
                                >nnn3nnnnnnnn
                                >+-- 4 lines: #
                                >c3cccccccc-----------------------------------------------------------------------------------
                                >nnn4nnnnnnnn
                                >nnn5nnnnnnnn
                                >nnn6nnnnnnnn
                                >+-- 3 lines: #
                                >c7cccccccc-----------------------------------------------------------------------------------
                                >nnn7nnnnnnnn
                                ># c10ccccccc
                                >nnn8nnnnnnnn
                                ># c11ccccccc
                                >nnn9nnnnnnnn
                                >******************
                                >but in practice those solutions may sometimes work fine after loading
                                >them into vim :)
                                >
                                >
                                The 1st and 3rd versions work, the 2nd doesn't, as I said.
                                Your 1st version is my 2nd, which don't work and your 2nd,
                                which is my 3rd does work, but maybe I should haved added
                                set foldminlines=0
                                for the nonbeliever.Heh.

                                -ap

                                --
                                Ich hab geträumt, der Krieg wär vorbei.


                                --~--~---------~--~----~------------~-------~--~----~
                                You received this message from the "vim_use" maillist.
                                For more information, visit http://www.vim.org/maillist.php
                                -~----------~----~----~----~------~----~------~--~---
                              • arctgx
                                +-- 3 wierszy: # vim syntax=sh :------------------------------------------------------------------------------- nnn1nnnnnnnn nnn2nnnnnnnn nnn3nnnnnnnn +-- 4
                                Message 15 of 17 , Jan 6, 2008
                                • 0 Attachment
                                  +-- 3 wierszy: # vim
                                  syntax=sh :-------------------------------------------------------------------------------
                                  nnn1nnnnnnnn
                                  nnn2nnnnnnnn
                                  nnn3nnnnnnnn
                                  +-- 4 wierszy: #
                                  c3cccccccc------------------------------------------------------------------------------------
                                  nnn4nnnnnnnn
                                  nnn5nnnnnnnn
                                  nnn6nnnnnnnn
                                  +-- 3 wierszy: #
                                  c7cccccccc------------------------------------------------------------------------------------
                                  nnn7nnnnnnnn
                                  +-- 1 wierszy: #
                                  c10ccccccc------------------------------------------------------------------------------------
                                  nnn8nnnnnnnn
                                  +-- 1 wierszy: #
                                  c11ccccccc------------------------------------------------------------------------------------
                                  nnn9nnnnnnnn

                                  Indeed, your third version with foldminlines=0 works :) The script
                                  seems to work fine on other files also - not only on shell scripts. I
                                  shall put in spare time your version on my Polish website (
                                  http://www-users.mat.uni.torun.pl/~arctgx/lin/vim.html ) with several
                                  tips about Vim, and not forgot to add mention about your autorship, of
                                  course, and link to this thread as source.

                                  Thx once again
                                  Tomasz
                                  --~--~---------~--~----~------------~-------~--~----~
                                  You received this message from the "vim_use" maillist.
                                  For more information, visit http://www.vim.org/maillist.php
                                  -~----------~----~----~----~------~----~------~--~---
                                • Ben Schmidt
                                  ... If you have time, I suspect the community would appreciate it if you added it to the official Vim Tips wiki: http://vim.wikia.com/wiki/Main_Page Ben. Send
                                  Message 16 of 17 , Jan 6, 2008
                                  • 0 Attachment
                                    > Indeed, your third version with foldminlines=0 works :) The script
                                    > seems to work fine on other files also - not only on shell scripts. I
                                    > shall put in spare time your version on my Polish website (
                                    > http://www-users.mat.uni.torun.pl/~arctgx/lin/vim.html ) with several
                                    > tips about Vim, and not forgot to add mention about your autorship, of
                                    > course, and link to this thread as source.

                                    If you have time, I suspect the community would appreciate it if you added it to
                                    the official Vim Tips wiki:

                                    http://vim.wikia.com/wiki/Main_Page

                                    Ben.




                                    Send instant messages to your online friends http://au.messenger.yahoo.com


                                    --~--~---------~--~----~------------~-------~--~----~
                                    You received this message from the "vim_use" maillist.
                                    For more information, visit http://www.vim.org/maillist.php
                                    -~----------~----~----~----~------~----~------~--~---
                                  • Charles E. Campbell, Jr.
                                    ... I did say that the mapping was untested! Which means some debugging may be involved. OK, I ve gone and done it: map :if
                                    Message 17 of 17 , Jan 6, 2008
                                    • 0 Attachment
                                      arctgx wrote:

                                      > I wouldn't like to insert into file any strings ({{{, 'token' etc.)
                                      >that are deserve only to define fold range, especially as I open some
                                      >files only for reading.
                                      >
                                      >Vince Negri's patch doesn't exists for 7.1 vim version. I tried to
                                      >patch 7.1 but patching exited with fails. Charles, does your commands
                                      >work only with this patch (E492: Not an editor command:
                                      >cmmnt_toggle=1<bar>hi link shComment Ign)?
                                      >
                                      >
                                      >
                                      I did say that the mapping was untested! Which means some debugging may
                                      be involved. OK, I've gone and done it:

                                      map <silent> <f1> :if !exists("g:cmmnt_toggle")<bar><bar>g:cmmnt_toggle
                                      == 0<cr>:let g:cmmnt_toggle= 1<cr>hi link shComment
                                      Ignore<cr>else<bar>let g:cmmnt_toggle= 0<bar>hi link shComment
                                      Comment<cr>endif<cr>

                                      (all one line) This mapping toggles shComment between linking to
                                      Comment and Ignore highlighting. It doesn't fold the lines; instead, it
                                      "Ignore"s them. Of course, if your colorscheme is obnoxious and makes
                                      Ignore visible, it won't help, but I don't think that's common.

                                      Regards,
                                      Chip Campbell



                                      --~--~---------~--~----~------------~-------~--~----~
                                      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.