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.
Table of contents
On this page
Search
| Key | Action |
|---|---|
/ | Search forward |
? | Search backward |
n | Jump to next match (downward) |
N | Jump to previous match (upward) |
Enter | Confirm 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:
| Command | Action |
|---|---|
:set ic | Ignore case during search |
:set hls | Highlight all search matches |
:set no[option] | Prefix any option with no to unset it (e.g. :set noic) |
Replace
| Command | Action |
|---|---|
:s/old/new/g | Replace all occurrences on current line |
:s/old/new/gc | Replace on current line with confirmation prompt |
:%s/old/new/gc | Replace across the whole file with confirmation |
The c flag prompts you y/n for each match, which is useful for selective replacements.
External Commands
You can run shell commands without leaving Neovim:
| Command | Action |
|---|---|
:! cmd | Run any shell command (e.g. :!ls) |
Ctrl+^ | Go back to the previous file / buffer |