A powerful search and replace plugin for Neovim using ripgrep.
Fast project-wide search and replace with live preview and undo support
- 🔍 Fast Search - Powered by ripgrep for blazing fast project-wide search
- 👁️ Live Preview - See changes before applying them
- 🔎 Browse Mode - Navigate through matches with
n/Nbefore replacing (NEW in v0.2.0) - 📁 File Grouping - Results grouped by file for easy navigation
- ✅ Selective Replace - Choose which files to include/exclude
- 🎯 Glob Filtering - Filter by file patterns (e.g.,
*.lua,src/,!tests/) - ⌨️ Keyboard Driven - Full keyboard navigation with Tab/Shift-Tab
- ↩️ Undo Support - Revert replacements with a single keystroke
- Neovim >= 0.8
- ripgrep
- nui.nvim
- plenary.nvim
Option 1: Load on startup (simpler)
{
"Jason-Bai/search-replace.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
},
lazy = false, -- Load on startup to register keymaps
config = function()
require("search-replace").setup()
end,
}Option 2: Lazy load on keymap (recommended)
{
"Jason-Bai/search-replace.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
},
keys = {
{ "<leader>sr", "<cmd>lua require('search-replace').open()<cr>", desc = "Search and Replace" },
{ "<leader>sr", "<cmd>lua require('search-replace').open_visual()<cr>", mode = "v", desc = "Search and Replace (visual)" },
},
config = function()
require("search-replace").setup({
keymap = false, -- Don't set default keymap, using lazy.nvim keys instead
})
end,
}use {
"Jason-Bai/search-replace.nvim",
requires = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
},
config = function()
require("search-replace").setup()
end,
}require("search-replace").setup({
-- Keymap to open search-replace dialog
-- Set to false to disable default keymap
keymap = "<leader>sr",
-- Window options
win_options = {
width = 0.8, -- 80% of editor width
height = 0.8, -- 80% of editor height
},
-- Additional ripgrep options
rg_options = {
-- "--hidden", -- Search hidden files
-- "--no-ignore", -- Don't respect .gitignore
},
})| Key | Description |
|---|---|
<leader>sr |
Open search-replace dialog |
v_<leader>sr |
Open with visual selection pre-fill |
| Key | Description |
|---|---|
Tab |
Next field (Search → Replace → Flags → Results → Preview) |
Shift-Tab |
Previous field |
Enter |
Execute search (in Search/Flags field) |
Esc / q |
Close dialog |
| Key | Description |
|---|---|
<C-t> |
Toggle search case sensitivity (Aa/aa) |
| Key | Description |
|---|---|
<C-t> |
Toggle glob case sensitivity (Aa/aa) |
| Key | Description |
|---|---|
j / k |
Navigate results |
Space |
Toggle file selection |
o |
Open Browse Mode (navigate matches) |
r |
Execute replacement on selected files |
u |
Undo last replacement |
| Key | Description |
|---|---|
n |
Jump to next match |
N |
Jump to previous match |
q |
Exit Browse Mode |
Tab |
Return to normal navigation |
- Press
<leader>srto open the search-replace dialog - Enter your search pattern in the Search field
- (Optional) Enter replacement text in the Replace field
- (Optional) Add file filters in the Flags/Filter field:
*.lua- Only Lua filessrc/- Only files in src directory!tests/- Exclude tests directory
- Press
Enterto search - Use
Spaceto select/deselect files - Press
rto apply replacements - Press
uto undo the last replacement if needed
Quick search for selected text:
- Select text in visual mode (e.g.,
viwto select word) - Press
<leader>srto open dialog with pre-filled search - Enter replacement text in the Replace field
- Press
Enterto search - Review matches and press
rto replace
Toggle search behavior:
- Case Sensitivity: Press
<C-t>in Search or Flags field to toggle between[Aa](sensitive) and[aa](insensitive) - Status indicators appear in the Search and Flags title bars
Before replacing, you can inspect each match in detail:
- After searching, navigate to any file in Results
- Press
oto enter Browse Mode - Use
n/Nto jump between matches in the file - The title bar shows your position:
Browse [3/8] - filename:42 - Press
qto exit Browse Mode and return to Results - Select files with
Spaceand pressrto replace
Why use Browse Mode?
- 👀 Review matches in their full context before replacing
- 🎯 Quickly navigate through all occurrences with
n/N - ✅ Make informed decisions about which files to replace
Run :checkhealth search-replace to verify your setup.
MIT
- ripgrep - Fast search tool
- nui.nvim - UI components
- plenary.nvim - Lua utilities
