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

several substitutes on same visual selection

Expand Messages
  • Malte Neumann
    Hi, just a short and simple question. I didn t know where to look in the help for the solution. How can I apply several (i.e. approx 10) subsequent
    Message 1 of 4 , Sep 25, 2003
    • 0 Attachment
      Hi,

      just a short and simple question. I didn't know where to look in the help
      for the solution.

      How can I apply several (i.e. approx 10) subsequent substitutions on the
      same visual selection.

      Thanks for your advice.

      Malte


      --
      --------------------------------------------------------------------------
      Malte Neumann
      --------------------------------------------------------------------------
      Institut fuer Baustatik / Institute of Structural Mechanics
      Prof. Dr.-Ing. Ekkehard Ramm
      Universitaet Stuttgart / University of Stuttgart

      Pfaffenwaldring 7, D-70550 Stuttgart, Germany

      mailto:neumann@...-stuttgart.de phone: ++49-711-685-6121
      http://www.uni-stuttgart.de/ibs/members/neumann/ fax: ++49-711-685-6130
      --------------------------------------------------------------------------
    • Tim Chase
      ... Well, the range
      Message 2 of 4 , Sep 25, 2003
      • 0 Attachment
        > How can I apply several (i.e. approx 10) subsequent substitutions on the
        > same visual selection.

        Well, the range '<,'> is preserved even after you do a substitute (though
        things might get funky if your substitute adds or removes lines, you
        should still be pretty safe), so just modifying your previous search
        should do the trick:

        -highlight lines to :s
        -pressing colon brings up the colon/ex prompt with the range already
        specified as '<,'>

        :'<,'>s/search/replace/g

        -pressing colon brings up the colon/ex prompt again. From here, you can
        use the ^P/^N/up/down to recall your last search if you just want to
        modify it, or you can just add the range '<,'> before your "s"

        :'<,'>/search2/replace2/g

        The :s will act across the previously specified range. I'm not sure where
        I learned this (accidental discovery is most likely), but

        :he '<

        doesn't give any indicator that the '< and '> marks are preserved outside
        of a visual selection. They are. :)

        HTH,

        -tim
      • Charles E. Campbell
        ... You can use ... repeatedly; if you prefer, you can type gv in normal mode and see the selection region get highlighted again. If you use visual-block mode
        Message 3 of 4 , Sep 25, 2003
        • 0 Attachment
          On Thu, Sep 25, 2003 at 04:34:43PM +0200, Malte Neumann wrote:
          > just a short and simple question. I didn't know where to look in the help
          > for the solution.
          >
          > How can I apply several (i.e. approx 10) subsequent substitutions on the
          > same visual selection.
          ---------------------------------------------------------------------

          You can use

          :'<,'>s/.../..../

          repeatedly; if you prefer, you can type

          gv

          in normal mode and see the selection region get highlighted again.

          If you use visual-block mode (ie. use ctrl-v), check out

          "Visual Block Commands" under
          http://www.erols.com/astronaut/vim/index.html#VimFuncs

          Regards,
          Chip Campbell

          --
          Charles E Campbell, Jr, PhD _ __ __
          Goddard Space Flight Center / /_/\_\_/ /
          cec@... /_/ \/_//_/
          PGP public key: http://www.erols.com/astronaut/pgp.html
        • Keith Roberts
          ... ^ [snip] Also, I thought I d mention that you can re-highlite (thus visually checking) the visual area with gv , and then do something else with it,
          Message 4 of 4 , Sep 25, 2003
          • 0 Attachment
            >-----Original Message-----
            >From: Tim Chase [mailto:gumnos@...]
            >Sent: Thursday, September 25, 2003 6:44 AM
            >To: Malte Neumann; vim user list
            >Subject: Re: several substitutes on same visual selection
            >
            >> How can I apply several (i.e. approx 10) subsequent substitutions on the
            >> same visual selection.
            >
            >Well, the range '<,'> is preserved even after you do a substitute (though
            >things might get funky if your substitute adds or removes lines, you
            >should still be pretty safe), so just modifying your previous search
            >should do the trick:
            >
            >-highlight lines to :s
            >-pressing colon brings up the colon/ex prompt with the range already
            >specified as '<,'>
            >
            > :'<,'>s/search/replace/g
            >
            >-pressing colon brings up the colon/ex prompt again. From here, you can
            >use the ^P/^N/up/down to recall your last search if you just want to
            >modify it, or you can just add the range '<,'> before your "s"
            >
            > :'<,'>/search2/replace2/g

            I think you forgot the "s" in this last command, Tim. Maybe you meant:
            :'<,'>s/search2/replace2/g
            ^
            [snip]

            Also, I thought I'd mention that you can re-highlite (thus visually
            checking) the visual area with "gv", and then do something else with it,
            either in normal mode or in Ex mode. For example,
            Vjy -create a visual area of 2 lines; yank it
            Pgv -paste a copy in front of the original
            and re-highlite the original area
            :'<,'>s/expr1/expr2/g -as soon as you press ":" the range shows
            and you add your command (eg, substitute)
            gv... -repeat the process for a normal cmd
            :'<,'>... -repeat the process for an Ex cmd
          Your message has been successfully submitted and would be delivered to recipients shortly.