sed whole file

35 views
Skip to first unread message

Jorge Almeida

unread,
Oct 6, 2019, 5:54:00 AM10/6/19
to vim...@googlegroups.com
I just noticed an obnoxious behaviour that I think is a new "feature".
Or maybe it was always like this and I forgot. Or maybe I did
something wrong, in which case I apologize in advance.

It goes like this:
I want to replace each occurrence of "foo" by "bar". In command mode I
start typing
:%s/foo

and the cursor moves to the first occurrence of foo, even if it means
moving the page down. Maybe the user would like to copy something in
the original page? Maybe that's where the string "bar" occurs and the
user didn't memorize it?

Please help me to restore a sane behaviour

Thanks

Jorge Almeida

Bram Moolenaar

unread,
Oct 6, 2019, 6:25:33 AM10/6/19
to vim...@googlegroups.com, Jorge Almeida
You can reset 'incsearch'.

Perhaps we could go back to the original view when typing the search
separator. So long as the user is typing the search pattern it is
useful to show the match, but when typing ":%s/foo/", thus starting to
type the replacement, it is useful to jump back?

I actually cannot guess if the user wants to see the original text or
the context of what is going to be replaced. If you have something
specific, you can copy it beforehand. And the jumping around can be
annoying. Thus I rather leave it like it is.

--
Save the plankton - eat a whale.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Nicolas George

unread,
Oct 6, 2019, 7:42:07 AM10/6/19
to vim...@googlegroups.com
Jorge Almeida (12019-10-06):
> I just noticed an obnoxious behaviour that I think is a new "feature".
> Or maybe it was always like this and I forgot. Or maybe I did
> something wrong, in which case I apologize in advance.
>
> It goes like this:
> I want to replace each occurrence of "foo" by "bar". In command mode I
> start typing
> :%s/foo
>
> and the cursor moves to the first occurrence of foo, even if it means
> moving the page down. Maybe the user would like to copy something in
> the original page? Maybe that's where the string "bar" occurs and the
> user didn't memorize it?

It is a new consequence of the 'incsearch' option. It used to affect
searching /, but it recently started to affect replacing during while
editing the command line. And it has the drawbacks you mention about
copy-pasting and in general perusing context.

My work-around for now is to remove the % while editing and put it back
before executing. But I also would like a way of enabling 'incsearch'
for searches and disabling for replacement.

Regards,

--
Nicolas George
signature.asc

Paul

unread,
Oct 8, 2019, 5:29:15 AM10/8/19
to vim...@googlegroups.com
On Sun, Oct 06, 2019 at 12:25:20PM +0200, Bram Moolenaar wrote:
>Perhaps we could go back to the original view when typing the search
>separator. So long as the user is typing the search pattern it is
>useful to show the match, but when typing ":%s/foo/", thus starting to
>type the replacement, it is useful to jump back?
>
>I actually cannot guess if the user wants to see the original text or
>the context of what is going to be replaced. If you have something
>specific, you can copy it beforehand. And the jumping around can be
>annoying. Thus I rather leave it like it is.

Not sure if this helps to contribute to the discussion, but personally, I like to see what is going to be replaced, and with what it will be replaced, so I can experiment and get the command right real-time, so I use the traces.vim plugin (https://github.com/markonm/traces.vim).
signature.asc

Eric Christopherson

unread,
Oct 8, 2019, 12:12:50 PM10/8/19
to vim_use
It can also be helpful to edit the command line as if it were a regular Vim buffer, by executing q: in normal mode or using C-f after you've already started entering the command line using :. I developed the habit of using q/ to edit search lines when I explicitly don't want the cursor to jump to the first occurrence of the string.

--
        Eric Christopherson
Reply all
Reply to author
Forward
0 new messages