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

86161Re: Simple hiding all comments by folding

Expand Messages
  • A.Politz
    Jan 1, 2008
      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
      -~----------~----~----~----~------~----~------~--~---
    • Show all 17 messages in this topic