sed whole file

已查看 35 次
跳至第一个未读帖子

Jorge Almeida

未读,
2019年10月6日 05:54:002019/10/6
收件人 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

未读,
2019年10月6日 06:25:332019/10/6
收件人 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

未读,
2019年10月6日 07:42:072019/10/6
收件人 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

未读,
2019年10月8日 05:29:152019/10/8
收件人 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

未读,
2019年10月8日 12:12:502019/10/8
收件人 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
回复全部
回复作者
转发
0 个新帖子