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

Re: collapsing single lines of html tag attributes via plugin??

Expand Messages
  • Tim Chase
    ... Welcome! ... Well, since they can be slightly reformatted, as HTML generally ignores whitespace, you may be able to use an external tool like tidy to
    Message 1 of 7 , Jun 1, 2007
    View Source
    • 0 Attachment
      > Been a long long time vi user but bizarrely never made the
      > jump to vim until quite recently.

      Welcome!

      > I'm editing a lot of complex html/cake-php thtml templates at
      > the moment and despite useful color highlighting I'm finding
      > it quite difficult to see the "wood for the trees" due to the
      > complex templates i have to edit. Typically for example, I've
      > got tags with just about every possible attribute populated
      > stretching over 3-4 lines sometimes. Imagine that embedded in
      > huge multi level tables with specific tags.... I'm stuck with
      > the templates to adhere to corporate style.

      Well, since they can be slightly reformatted, as HTML generally
      ignores whitespace, you may be able to use an external tool like
      "tidy" to clean up the code so it's a bit easier to read. It
      should also help with normalizing the indentation.

      You may also be interested in reading about "folding" which
      collapses multiple lines into one:

      :help folding

      You can manually create folds to hide away particularly
      nettlesome segments if there are just a handful, or you can go
      for a more automated way of folding them. Folds are only
      line-wise rather than character-wise (though there is an vim
      patch floating around to also do column-wise folding...this is
      hearsay, as I've never tried it). Folding can be done by a
      variety of methods, defaulting to "manual", but also allowing it
      to be done by syntax, by expression, or by indentation. Or even
      the manual folding can be done in a semi-automated fashion via a
      :g command such as

      :g/<[^>]*$/.,/>/fold

      which may be a good first place to start. If you used "tidy" and
      it has normalized indentation, you can just use

      :set foldmethod=indent

      and it may allow you to get a bird's-eye view of your code.

      > to abbreviate or partially hide the detail so i can see the
      > overall structure more clearly. In essence I would like to
      > collapse huge (single) lines of tags to something like <a
      > id="xyz" href="/img ....... - where "...." implies I could
      > expand if required.

      Another lazy option might just be to visually hide it with
      something like

      :match Ignore /<\_[^>]*>/

      which will just hide all the tags (making them background-color
      on background-color). This is dangerous if you start editing and
      treat them like you would treat whitespace, but it can help make
      your content pop. Or you might try

      /<\s*\w\+\s\+\zs\_[^>]*/

      which will just discolor your attribtes. If you want to see them
      but make them more subdued, you can opt for a different
      highlighting group than "Ignore", something like

      :match Comment /.../

      where, at least in my setup, Comment is dark grey on black which
      allows me to see it, but it isn't quite as intrusive. When done,
      you can un-:match them with

      :match none

      You can read all about this at

      :help :match

      > For lots of boring reasons I don't have the option of funky
      > graphical html editors or environments - i'm in a remote shell
      > using vim in text mode.

      You have Vim...what more do you need? ;-)

      Hope this gives you some ideas with which to work...

      -tim
    • Tobia
      ... There is a simple solution, maybe too simple, but... if you only have one tag per line, or if you can reformat your file in such a way, it ... Type that
      Message 2 of 7 , Jun 1, 2007
      View Source
      • 0 Attachment
        Howard Glynn wrote:
        > In essence I would like to collapse huge (single) lines of tags to
        > something like <a id="xyz" href="/img .......

        There is a simple solution, maybe too simple, but... if you only have
        one tag per line, or if you can reformat your file in such a way, it
        might be enough to disable line wrap:

        :set nowrap

        You can map a function key to toggling line wrap:

        :map <F9> :set wrap!<CR>

        Type that literally, with < > and everything, or put it into ~/.vimrc


        HTH
        Tobia
      • Charles E Campbell Jr
        ... Hello! Sounds like Vince Negri s conceal patch to vim would come in handy for this. Vim s current folding is on a line-by-line basis; Negri s patch can
        Message 3 of 7 , Jun 1, 2007
        View Source
        • 0 Attachment
          Howard Glynn wrote:

          > <snip>
          >
          > I wondered whether there was a plugin somewhere that was able to
          > abbreviate or
          > partially hide the detail so i can see the overall structure more
          > clearly. In essence I
          > would like to collapse huge (single) lines of tags to something like
          > <a id="xyz"
          > href="/img ....... - where "...." implies I could expand if required.
          > I'm sure it is probably
          > possible to craft a plugin to do this, i just have some urgent
          > deadlines right now ;)
          > <snip>


          Hello!

          Sounds like Vince Negri's conceal patch to vim would come in handy for this.
          Vim's current folding is on a line-by-line basis; Negri's patch can also
          perform
          concealing in lines.

          You can get his patch at: http://vince.negri.googlepages.com/

          Here's an example, although it may conceal more than what you've
          requested...

          if has("conceal")
          if &conc == 0
          let &conc= 3
          endif
          syn clear
          syn region htmlTag conceal start="<" end=">"
          endif

          So this will conceal anything between <...> . One neat thing; even
          though I've
          selected conceal level 3, nonetheless, when your cursor is atop a line
          that line
          will *not* be concealed. So editing may proceed, as that's what Vim's for.

          A more comprehensive (but not html-related) example of concealing is
          available
          at my website: see AnsiEsc.vim. This plugin will conceal ansi escape
          codes and
          perform proper colorizing of the text based on the concealed ansi codes.

          Vince N has a tex.vim syntax using concealment, too, somewhere...

          BTW, folks -- if more people than H Glynn would want this -- let Bram
          know! He's under
          the impression that its not wanted very much, which is why I presume its
          not in vim 7.x.

          Vince's patch also supports "ownsyntax". Read about it at his website.

          Regards,
          Chip Campbell
        • fREW
          ... I would use conceal if it were in standard vim. Definitely. -- -fREW
          Message 4 of 7 , Jun 1, 2007
          View Source
          • 0 Attachment
            On 6/1/07, Charles E Campbell Jr <drchip@...> wrote:
            > Howard Glynn wrote:
            >
            > > <snip>
            > >
            > > I wondered whether there was a plugin somewhere that was able to
            > > abbreviate or
            > > partially hide the detail so i can see the overall structure more
            > > clearly. In essence I
            > > would like to collapse huge (single) lines of tags to something like
            > > <a id="xyz"
            > > href="/img ....... - where "...." implies I could expand if required.
            > > I'm sure it is probably
            > > possible to craft a plugin to do this, i just have some urgent
            > > deadlines right now ;)
            > > <snip>
            >
            >
            > Hello!
            >
            > Sounds like Vince Negri's conceal patch to vim would come in handy for this.
            > Vim's current folding is on a line-by-line basis; Negri's patch can also
            > perform
            > concealing in lines.
            >
            > You can get his patch at: http://vince.negri.googlepages.com/
            >
            > Here's an example, although it may conceal more than what you've
            > requested...
            >
            > if has("conceal")
            > if &conc == 0
            > let &conc= 3
            > endif
            > syn clear
            > syn region htmlTag conceal start="<" end=">"
            > endif
            >
            > So this will conceal anything between <...> . One neat thing; even
            > though I've
            > selected conceal level 3, nonetheless, when your cursor is atop a line
            > that line
            > will *not* be concealed. So editing may proceed, as that's what Vim's for.
            >
            > A more comprehensive (but not html-related) example of concealing is
            > available
            > at my website: see AnsiEsc.vim. This plugin will conceal ansi escape
            > codes and
            > perform proper colorizing of the text based on the concealed ansi codes.
            >
            > Vince N has a tex.vim syntax using concealment, too, somewhere...
            >
            > BTW, folks -- if more people than H Glynn would want this -- let Bram
            > know! He's under
            > the impression that its not wanted very much, which is why I presume its
            > not in vim 7.x.
            >
            > Vince's patch also supports "ownsyntax". Read about it at his website.
            >
            > Regards,
            > Chip Campbell
            >
            >

            I would use conceal if it were in standard vim. Definitely.

            --
            -fREW
          • Matthew Winn
            ... [snip] ... So would I. It s only nervousness at using unofficial patches that puts me off. I d also be interested in a view-only mode that conceals
            Message 5 of 7 , Jun 2, 2007
            View Source
            • 0 Attachment
              On Fri, 1 Jun 2007 15:25:25 -0600, fREW <frioux@...> wrote:

              > On 6/1/07, Charles E Campbell Jr <drchip@...> wrote:
              > > Sounds like Vince Negri's conceal patch to vim would come in handy for this.
              [snip]
              > I would use conceal if it were in standard vim. Definitely.

              So would I. It's only nervousness at using unofficial patches that
              puts me off. I'd also be interested in a view-only mode that conceals
              characters in the current line as well, if that's possible. (I have
              some large report files for which I use Vim to colour the text for
              easy reading, but that means some space in the file is taken up with
              marker characters to trigger the highlighting. It'd be nice to be able
              to collapse all the markers.)

              --
              Matthew Winn
            • Howard Glynn
              Thanks to those taking the time to post some responses on this question. I found Tobia s suggestion to map a wrapping toggle onto a function key extremely
              Message 6 of 7 , Jun 4, 2007
              View Source
              • 0 Attachment
                Thanks to those taking the time to post some responses on this question.

                I found Tobia's suggestion to map a wrapping toggle onto a function key
                extremely helpful - thanks, i'm using it now. Sometimes the simple ones
                are the best :-)

                I've also investigating folding a bit more thoroughly in the vim context and
                that has helped too.

                Conceal sounds like a good patch I will look into that when my deadlines
                get a bit easier, I don't really want to start trying to break my environment
                or getting distracted recompiling at this point, maybe in a few weeks.

                Cheers, Howard
              Your message has been successfully submitted and would be delivered to recipients shortly.