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

Reverse search and replace

Expand Messages
  • Ven Tadipatri
    In Vim, you can do a search and replace with :%s, with a confirm option. But if the text you want to replace is the last line in the current window, then you
    Message 1 of 4 , Apr 16, 2014
    • 0 Attachment
      In Vim, you can do a search and replace with :%s, with a confirm option. But if the text you want to replace is the last line in the current window, then you can't really see any context for it. Is there a way to do a reverse search and replace? Or when a match is found, can you have vim show a few lines below it?

      Thanks,
      Ven

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Christian Brabandt
      ... You can use Ctrl-E and CTRL-Y to scroll the window. Best, Christian -- -- You received this message from the vim_use maillist. Do not top-post! Type your
      Message 2 of 4 , Apr 16, 2014
      • 0 Attachment
        Am 2014-04-16 15:50, schrieb Ven Tadipatri:
        > In Vim, you can do a search and replace with :%s, with a confirm
        > option. But if the text you want to replace is the last line in the
        > current window, then you can't really see any context for it. Is there
        > a way to do a reverse search and replace? Or when a match is found,
        > can you have vim show a few lines below it?

        You can use Ctrl-E and CTRL-Y to scroll the window.

        Best,
        Christian

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • Tim Chase
        ... which will keep the cursor centered on the screen. Seems to keep it centered when doing :s commands. -tim -- -- You received this message from the
        Message 3 of 4 , Apr 16, 2014
        • 0 Attachment
          On 2014-04-16 16:10, Christian Brabandt wrote:
          > Am 2014-04-16 15:50, schrieb Ven Tadipatri:
          > > In Vim, you can do a search and replace with :%s, with a confirm
          > > option. But if the text you want to replace is the last line in
          > > the current window, then you can't really see any context for it.
          > > Is there a way to do a reverse search and replace? Or when a
          > > match is found, can you have vim show a few lines below it?
          >
          > You can use Ctrl-E and CTRL-Y to scroll the window.

          Or, you can set 'scrolloff' to some super-high number:

          :set scrolloff=999

          which will keep the cursor centered on the screen. Seems to keep it
          centered when doing :s commands.

          -tim



          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Gary Johnson
          ... I don t know of a way to do exactly what you want, but you could use scrolloff to keep the cursor line a few lines away from the top and bottom of the
          Message 4 of 4 , Apr 16, 2014
          • 0 Attachment
            On 2014-04-16, Ven Tadipatri wrote:
            > In Vim, you can do a search and replace with :%s, with a confirm option. But if
            > the text you want to replace is the last line in the current window, then you
            > can't really see any context for it. Is there a way to do a reverse search and
            > replace? Or when a match is found, can you have vim show a few lines below it?

            I don't know of a way to do exactly what you want, but you could use
            'scrolloff' to keep the cursor line a few lines away from the top
            and bottom of the screen, e.g.,

            :set scrolloff=2


            I don't use :%s with the confirm flag. Instead I use n to find the
            next match and . to repeat the substitution, but I experience the
            same frustration of not being able to see the context of the change
            I'm about to make. I don't like the solution I proposed above
            because it always scrolls the display to keep the cursor out of the
            top and bottom rows and when I'm editing I often want the cursor at
            the very top or bottom.

            My work-around has been to map n, N and a few other jump commands to
            include a call to a function that repositions the cursor away from
            the top and bottom of the screen. It works pretty well, but I don't
            know of any hooks to make it work for your case.

            Regards,
            Gary

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          Your message has been successfully submitted and would be delivered to recipients shortly.