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

Recursive :global

Expand Messages
  • Antony Scriven
    Hi all. I have a working proof-of-concept (i.e. it s currently a mess) of recursive :globals. Some examples. To replace `bar with `baz if it s on a line
    Message 1 of 1 , Jul 25, 2007
    • 0 Attachment
      Hi all. I have a working proof-of-concept (i.e. it's
      currently a mess) of recursive :globals. Some examples.

      To replace `bar' with `baz' if it's on a line immediately
      preceding `foo' use

      :g/foo/ -g/bar/ s//baz/

      or alternatively

      :g/bar/ k m | +g/foo/ 'm s/bar/baz/

      With the following in a buffer,

      1
      2
      @
      3
      4
      @
      5
      6

      to add as many dashes after each non-`@' line as there are `@'s

      :v/@/ k m | g/@/ 'm s/$/-/

      giving

      1--
      2--
      @
      3--
      4--
      @
      5--
      6--

      For four dashes after every non-`@' line this works:

      :v/@/ k m | g/@/ g/@/ 'm s/$/-/

      So a nested :global still has a default range of %; I'm not
      sure whether that is right. And you get eight levels of
      recursion at the cost of an extra byte of storage per line.

      Would anyone be interested in this? Or is it too much of
      a departure from the vi model? --Antony

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.