Neovim’s search and replace capabilities are powerful once you know the commands. This article covers basic search, incremental search settings, and running external commands.

KeyAction
/Search forward
?Search backward
nJump to next match (downward)
NJump to previous match (upward)
EnterConfirm and lock on that line after search

Type /searchterm and press Enter. Use n / N to cycle through matches.

Incremental Search Settings

These Ex commands tweak search behaviour and can be added to your init.lua/init.vim:

CommandAction
:set icIgnore case during search
:set hlsHighlight all search matches
:set no[option]Prefix any option with no to unset it (e.g. :set noic)

Replace

CommandAction
:s/old/new/gReplace all occurrences on current line
:s/old/new/gcReplace on current line with confirmation prompt
:%s/old/new/gcReplace across the whole file with confirmation

The c flag prompts you y/n for each match - useful for selective replacements.

External Commands

You can run shell commands without leaving Neovim:

CommandAction
:! cmdRun any shell command (e.g. :!ls)
Ctrl+^Go back to the previous file / buffer

Tips

  • Combine :set ic and :set hls for a friendlier search experience while learning.
  • :%s/old/new/g (no c) is the fastest way to do a global rename in a single file.
  • :! is great for quick one-off tasks like formatting a file or running tests.