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

Re: Indenting blocks

Expand Messages
  • Benji Fisher
    ... Well, I would not say typical since it involves a :g command, but as long as you use :normal and not :normal!, it should work fine. I tried ... on the
    Message 1 of 5 , Jun 9, 2004
    • 0 Attachment
      On Wed, Jun 02, 2004 at 08:29:27PM +0200, Antoine J. Mechelynck wrote:
      > gumnos (Tim Chase) <gumnos@...> wrote:
      > > It's that ol' VB code again. I've got a whole bunch of "Select Case"
      > > statements of the form
      > >
      > > Select Case iFoo
      > > Case 1
      > > {code}
      > > Case 2
      > > {more code}
      > > Case Else
      > > {yet more code}
      > > End Select
      > >
      > > And I'd like to exdent the contents. In the generic form, it's an
      > > easy
      > >
      > > g/Select Case/+1,/End Select/-1<<<<
      > >
      > > (my shiftwidth is currently set to 1, so this exdents those 4 leading
      > > spaces properly)
      > >
      > > However, the rub is that these "Select Case...End Select" statements
      > > can be nested like
      > >
      > >
      > > Select Case iFoo
      > > Case 1
      > > {code}
      > > Case 2
      > > Select Case iBar
      > > Case 1
      > > {stuff}
      > > Case 2
      > > {more stuff}
      > > Case Else
      > > {yet more stuff}
      > > End Select ' <-- problematic/premature End Select found
      > > Case Else
      > > {yet more code}
      > > End Select
      > >
      > > The problem is that with my first stab (the :g statement above), the
      > > "inner block" is prematurely terminated. Is there some way to do
      > > something like
      > >
      > > g/^\(\s*\)Select Case/+1,/^\1End Select"/-1<<<<
      > >
      > > which would make sure that the "Select Case" matched the indent of the
      > > "End Select" over which it was effected? The problem is that the
      > > \(...\) and the \1 are in disjoint regexps. :( Additionally, I'm not
      > > sure that this doesn't change the marks (or the location of the "next
      > > marked line on which to operate"), so it might totally jump over the
      > > inner Select Case statement because of the positioning after the
      > > search for the End Select.
      > >
      > > Any suggestions would be greatly appreciated. Thanks,
      > >
      > > -tim
      >
      > I'm not 100% sure but this sounds like a typical job for the matchit plugin.
      > Try reading its help, starting at ":help matchit.txt", and if that doesn't
      > work, see ":help matchit-install" about how to include it.

      Well, I would not say "typical" since it involves a :g command, but
      as long as you use :normal and not :normal!, it should work fine. I
      tried

      :g/Select Case/+normal v]%k2<

      on the sample text (after :set sw=1) and it worked like a charm. I
      mention this in part to advertise the ]% motion: there is more to
      matchit than just % ! Assuming you have installed the help file, see

      :help matchit-intro

      HTH --Benji Fisher
    Your message has been successfully submitted and would be delivered to recipients shortly.