Feature Request - Live substitution feature (neovim inccommand option)

77 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Aug 8, 2018, 8:22:13 PM8/8/18
to vim_dev
Hi all,

The 'inccommand' option in Neovim allows a user to perform
live substitution. When you type a :substitute command, the
document is modified live. A demonstration of this feature
is available at http://vimcasts.org/episodes/neovim-eyecandy.

I think this feature will be a good addition to Vim.

There is also a multiple-cursors plugin
(https://github.com/terryma/vim-multiple-cursors)
which tries to mimic the Sublime Text Editor's multiple
section feature in Vim. I am not sure whether the features
provided by this plugin and the 'inccommand' option can be
combined together and natively supported in Vim.

Thanks,
Yegappan

h_east

unread,
Aug 8, 2018, 9:01:50 PM8/8/18
to vim_dev
Hi,

2018-8-9(Thu) 9:22:13 UTC+9 yega...@gmail.com:

I mention only about option name.

Option name 'inccommand' is not intuitive.
I think 'substituteopt' ('subopt' in short name) is better.

--
Best regards,
Hirohito Higashi (h_east)

James McCoy

unread,
Aug 8, 2018, 9:25:46 PM8/8/18
to vim_dev
It's called 'inccommand' because it's not intended to be specific to
:substitute (and related commands). That's just the first command that
implemented support.

Cheers,
--
James
GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7 2D23 DFE6 91AE 331B A3DB

h_east

unread,
Aug 8, 2018, 10:07:42 PM8/8/18
to vim_dev
Hi,

2018-8-9(Thu) 10:25:46 UTC+9 James McCoy:

I judged that I was not intuitive by reading at inccommand's help document.

> Works for :substitute, :smagic, :snomagic. hl-Substitute

There is no way to know about it, as future things are not written there.

You should write it in the document.

Yee Cheng Chin

unread,
Aug 9, 2018, 12:58:03 AM8/9/18
to vim_dev
It's named "inccommand" because of the similarities it has with "incsearch". With "incsearch" it makes the window show incremental updates to what you are searching. With "inccommand" it shows incremental updates to your Ex command. That said it's true that it only works for substitution commands, so maybe it's a slight misnomer. Maybe "incsubstitue" or something is more accurate.

For what it's worth, the plugin https://github.com/markonm/traces.vim comes very close to replicating this functionality in Vim and it provides some extra benefits as well (but I assume not as efficiently as a native implementation). The one feature that the plugin doesn't mimic is the "show all substitutes in a preview window" one.

Dominique Pellé

unread,
Aug 9, 2018, 1:14:00 AM8/9/18
to vim_dev
Yegappan Lakshmanan <yega...@gmail.com> wrote:

> Hi all,
>
> The 'inccommand' option in Neovim allows a user to perform
> live substitution. When you type a :substitute command, the
> document is modified live. A demonstration of this feature
> is available at http://vimcasts.org/episodes/neovim-eyecandy.
>
> I think this feature will be a good addition to Vim.

I watched the screencast about the 'inccommand' feature.
It looks useful. When typing :%/foo/bar it interactively highlights
the matches for "foo". It would look nicer if it also highlighted
the substituted strings "bar", with a different color.

Regards
Dominique

Christian Brabandt

unread,
Aug 9, 2018, 1:55:17 AM8/9/18
to vim_dev
I noticed that too. Besides, I think there should be a way to scroll
interactively to be able to better control, that the :s command worked
on all parts of the document as expected, even if not visible in the
current viewport.

Best,
Christian
--
Alles Ideelle, sobald es vom Realen gefordert wird, zehrt
endlich dieses und sich selbst auf. So der Kredit (Papiergeld) das
Silber und sich selbst.
-- Goethe, Maximen und Reflektionen, Nr. 452

Justin M. Keyes

unread,
Aug 9, 2018, 6:20:50 AM8/9/18
to vim...@googlegroups.com


Christian Brabandt <cbl...@256bit.org> schrieb am Do., 9. Aug. 2018, 07:55:

On Do, 09 Aug 2018, Dominique Pellé wrote:

> Yegappan Lakshmanan <yega...@gmail.com> wrote:
>
> > Hi all,
> >
> > The 'inccommand' option in Neovim allows a user to perform
> > live substitution. When you type a :substitute command, the
> > document is modified live. A demonstration of this feature
> > is available at http://vimcasts.org/episodes/neovim-eyecandy.
> >
> > I think this feature will be a good addition to Vim.
>
> I watched the screencast about the 'inccommand' feature.
> It looks useful. When typing  :%/foo/bar  it interactively highlights
> the matches for "foo". It would look nicer if it also highlighted
> the substituted strings "bar", with a different color.

I noticed that too.

That was implemented in Nvim 0.3 .

Besides, I think there should be a way to scroll
interactively to be able to better control, that the :s command worked
on all parts of the document as expected, even if not visible in the
current viewport.

If you need that sort of micromanagement, it would make more sense to use /c to confirm each match. 


---
Justin M. Keyes

Christian Brabandt

unread,
Aug 9, 2018, 6:28:18 AM8/9/18
to vim...@googlegroups.com

On Do, 09 Aug 2018, Justin M. Keyes wrote:

> That was implemented in Nvim 0.3 .

Nice.

> Besides, I think there should be a way to scroll
> interactively to be able to better control, that the :s command worked
> on all parts of the document as expected, even if not visible in the
> current viewport.
>
>
> If you need that sort of micromanagement, it would make more sense to use /c to
> confirm each match.

Agree, however something like c_CTRL-G and c_CTRL-T would be nice :)

Also it does not help, if the regexp is too strict and misses a match,
which I think is one of the key features of the 'inccommand' setting,
right?

Best,
Christian

Bram Moolenaar

unread,
Aug 9, 2018, 6:40:31 AM8/9/18
to vim...@googlegroups.com, James McCoy

I wonder why that video only shows the effect in one line. What if I
have a large screen with many matches in many lines?

I also don't like the jump when typing /g finally. Not sure how useful
it is to show the effect of the substitute anyway, what is the use of
the preview?

Anyway, showing the matches can be controlled by 'incsearch'. That
should be relatively easy to implement.
So, how would you describe the effect of the option then? Writing that
down often helps to decide what to call it.

--
A hamburger walks into a bar, and the bartender says: "I'm sorry,
but we don't serve food here."

/// 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 ///

Bram Moolenaar

unread,
Aug 9, 2018, 2:45:59 PM8/9/18
to vim...@googlegroups.com, Yegappan Lakshmanan

Yegappan wrote:

> The 'inccommand' option in Neovim allows a user to perform
> live substitution. When you type a :substitute command, the
> document is modified live. A demonstration of this feature
> is available at http://vimcasts.org/episodes/neovim-eyecandy.
>
> I think this feature will be a good addition to Vim.

It sounds like a "nice to have" feature. I wonder what happens with
syntax highlighting, folds, line wrapping etc. And how does it restore
everything when cancelling? it actually has to restore at every key
stroke, and redraw everything to be correct.

> There is also a multiple-cursors plugin
> (https://github.com/terryma/vim-multiple-cursors)
> which tries to mimic the Sublime Text Editor's multiple
> section feature in Vim. I am not sure whether the features
> provided by this plugin and the 'inccommand' option can be
> combined together and natively supported in Vim.

It might work for some simple cases, but will get really difficult if
you want to make it work properly. And although it looks fancy, there
isn't much practical value. I can't say I ever missed this feature.

--
An indication you must be a manager:
You give constructive feedback to your dog.
Reply all
Reply to author
Forward
0 new messages