Skip to content
Natalie Perret
Go back

Learning Neovim > 4: Search & Replace

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

Open Table of contents

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


Share this post on:

Previous Post
Learning Neovim > 3: Insert & Visual Modes
Next Post
DDD (Domain-Driven Design) Basics