vimtricks.wiki Concise Vim tricks, one at a time.

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

  • inccommand controls live preview behavior for :substitute commands
  • :set inccommand=nosplit enables 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 hlsearch so match scope is even clearer while editing the command
  • Add c flag (:%s/pat/repl/gc) when you want live preview plus per-match confirmation
  • Keep this option in your init.vim or init.lua defaults if you do frequent project-wide renames

Next

How do I make @ characters count as part of filenames for gf and path motions?