Reverse search and replace

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Reverse search and replace

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?

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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse search and replace

Christian Brabandt
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse search and replace

Tim Chase
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse search and replace

Gary Johnson-4
In reply to this post by Ven Tadipatri
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.