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

:g/^$/,/./-j

Expand Messages
  • Guido Van Hoecke
    In the VIM Regular Expressions page at ... - reduce multiple blank lines to a single blank I try to understand this, so let s break it up ... is the easy
    Message 1 of 2 , Nov 1, 2006
    • 0 Attachment
      In the 'VIM Regular Expressions' page at
      http://www.geocities.com/volontir/ I read following:

      :g/^$/,/./-j
      - reduce multiple blank lines to a single blank

      I try to understand this, so let's break it up

      :g/^$/
      is the easy part: it marks all blank lines

      ,/./-j is a riddle to me,
      Anybody cares to explain this to me?

      TIA,

      Guido.

      --
      http://vanhoecke.org ... and go2 places!
    • Tim Chase
      ... Easy enough. The basic pattern, as you recognize is ... In this case, the action is, as you identify ,/./-j What you have here is of the form {range}j
      Message 2 of 2 , Nov 1, 2006
      • 0 Attachment
        > http://www.geocities.com/volontir/ I read following:
        >
        > :g/^$/,/./-j
        > - reduce multiple blank lines to a single blank
        >
        > I try to understand this, so let's break it up
        >
        > :g/^$/
        > is the easy part: it marks all blank lines
        >
        > ,/./-j is a riddle to me,
        > Anybody cares to explain this to me?


        Easy enough. The basic pattern, as you recognize is

        :g/pattern/action

        In this case, the action is, as you identify

        ,/./-j

        What you have here is of the form

        {range}j

        That {range} is

        {start},{stop}

        If not specified, the current line is the default starting
        location for most ex commands and ranges. That makes your
        {start} the current line, and your {range} the same thing as

        .,/./-j

        which I prefer in my own vim-isms just to make it more readable.

        Your {stop} is

        /./-

        This is

        /./ search for the next line containing something
        - go back/up one line from that line containing something

        So what you have is

        :g/^$/,/./-j
        111111244435

        1) on empty line
        2) beginning on that empty line (the implicit ".") and continuing
        through
        3) the line preceeding
        4) the next line containing something
        5) join that range of lines together.


        Hope that makes sense...? :)

        -tim
      Your message has been successfully submitted and would be delivered to recipients shortly.