How do I preview substitute changes inline while typing without opening a split?
Answer
:set inccommand=nosplit
Explanation
When you are crafting a risky :substitute command, the expensive part is usually confidence, not typing. inccommand gives you live feedback while the command line is still open, so you can correct the pattern before committing a destructive replace. The nosplit mode shows the preview directly in the current window, which is faster and less distracting than opening a preview split.
How it works
inccommandcontrols live preview behavior for:substitutecommands:set inccommand=nosplitenables incremental preview in place, inside the current buffer view- As you type
:s, flags, and replacement text, Neovim updates matches in real time - You still need to press
<CR>to apply the substitution; until then you are previewing only
Example
Suppose you want to rename API field names but avoid touching unrelated text.
status_code=200
status_message=ok
legacy_status_code=500
With inccommand=nosplit, you type a substitution and see live impact before execution:
:%s/status_/http_/g
During typing, you can immediately spot if legacy_status_code would be changed in a way you do not want, then tighten the pattern before pressing Enter.
Tips
- Pair with
hlsearchso match scope is even clearer while editing the command - Add
cflag (:%s/pat/repl/gc) when you want live preview plus per-match confirmation - Keep this option in your
init.vimorinit.luadefaults if you do frequent project-wide renames