Monday, July 19, 2010

Re: Default search changed by search and replace

On 07/19/10 20:32, Mark Butler wrote:
> On Jul 19, 11:56 am, Tim Chase<v...@tim.thechases.com> wrote:
> I don't have any older versions available to test right now, I just
> don't recall ever running into this problem before, and I have used
> vim hours a day for years.

I too have used vi/vim as my primary editor for about a decade
and am nigh certain this has always been the behavior and nothing
has changed. :)

> However it used to work at some point in the past, I believe the
> behavior that I suggest would be much more sensible. If you want to
> do what vim does by default now, search for Y, :%s/Y/Z and then n/N to
> get to the next Y. But that won't keep you from searching for X, :s/Y/
> Z/ and then n/N to get to the next X. As it is now, you have to keep
> typing X in over and over again, which is not very friendly.

For your particular use-case, I'd tend to do something like

:g/X/s/Y/Z/

which will find all X's, and s/Y/Z/ on those X lines (adjust
flags as you so desire, with "g" or "c" most likely). I've never
really found it a problem.

Imagining a situation with greater gravity of repetition, I'd either

1) use the search history buffer and just hit ^P to pull up the
previous search term(s) to get to X; or

2) use a little Vim-scripting and/or mapping to make sure I'm
searching for one term (perhaps stashed in a register or
buffer-local variable) regardless of what the search register
contained if a :s tromped upon it.

Just my thoughts. I like knowing that the search register is
predictably set regardless of where the search originates -- I
tend to use the converse (grr...or is that the contrapositive?
those middle-school logic classes escape me) of searching for
something and then being able to just issue

:%s//replacement/g

(putting in no search term to default to the stuff I previously
searched for)

My $0.02 for the evening...

-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

No comments: