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

How do I see a live preview of substitutions as I type in Neovim?

Answer

:set inccommand=split

Explanation

Neovim's inccommand option provides real-time visual feedback as you type substitution commands. It highlights matches and shows replacements live, with an optional split window showing off-screen changes. This makes complex substitutions far less error-prone.

How it works

  • inccommand=nosplit — shows live preview inline only
  • inccommand=split — shows live preview inline AND in a preview window for off-screen matches
  • Works with :s, :%s, and range-based substitutions
  • The preview updates with every keystroke as you type the pattern and replacement

Example

:set inccommand=split
As you type :%s/foo/bar/g:
- All 'foo' matches are highlighted in the buffer
- Each 'foo' shows 'bar' as an inline preview
- A split window shows matches from non-visible parts of the file

Tips

  • Add set inccommand=split to your init.vim for permanent use
  • This is a Neovim-only feature (not available in Vim)
  • Works perfectly with visual range substitutions :'<,'>s/old/new/g
  • Press <Esc> to cancel without making changes if the preview looks wrong

Next

How do I return to normal mode from absolutely any mode in Vim?