refactor.nvim is a NeoVim plugin written in Lua that enhances your editing experience with advanced find and replace capabilities. Whether you need to refactor text in the current buffer or across multiple files via the quickfix list, this plugin offers a flexible and user-friendly solution with support for various matching options.
- Perform find and replace operations in the current file/buffer
- Extend replacements across the quickfix list
- Toggle case-sensitive or case-insensitive searches
- Match whole words or partial text
- Optionally use regular expressions for complex patterns
- Optionally preserve case during replacements
- Cancel operations easily with ESC
- Receive clear, informative notifications
refactor.nvim requires NeoVim 0.7 or later. You can install it using your preferred package manager.
Using Lazy
Add the following to your Lazy configuration:
{
"ShifatHasanGNS/refactor.nvim",
config = function()
require("refactor").setup()
end
}Using Packer
Add the following to your Packer configuration:
use {
"ShifatHasanGNS/refactor.nvim",
config = function()
require("refactor").setup()
end
}Using Vim-Plug
Add the following to your vimrc:
Plug 'ShifatHasanGNS/refactor.nvim'Then, in your NeoVim configuration (e.g., init.lua):
require("refactor").setup()It provides two primary commands to initiate refactoring:
:RefactorB- Refactor in the current buffer:RefactorQ- Refactor across the quickfix list
Default key mappings are also available (using <leader>r as the base):
<leader>rb- Refactor in the current buffer<leader>rq- Refactor in the quickfix list
When you run a refactor command, the plugin guides you through these steps:
- Flags: Enter optional flags (e.g.,
cwfor case-sensitive and whole-word). Press Enter to use defaults. Available flags:c- Case-sensitivew- Whole-wordr- Regular expressionp- Preserve case
- Find String: Enter the text or pattern to search for.
- Replace String: Enter the replacement text.
- Confirmation: Type
yto proceed ornto cancel.
Press ESC at any prompt to cancel the operation. Notifications will keep you informed throughout the process. To cencel operations just after initiating, you have to press ESC twice.
To replace all occurrences of "Yisra'el" with "Filastin" in the current buffer, case-sensitive and whole-word only:
- Run
:RefactorBor<leader>rb - Enter flags:
cw - Find:
Yisra'el - Replace:
Filastin - Confirm:
y
Customize the plugin by passing options to the setup function. For example, to set default flags:
-- For Example
require("refactor").setup({
-- Case-sensitive and whole-word by default
default_flags = "cw"
})The default_flags option accepts any combination of c, w, r, and p. Leave it empty ("") for default behavior (case-insensitive, partial-match, literal-text, normal-case).
Ensure the plugin is working correctly by running:
:checkhealth refactor
This command verifies the NeoVim version and plugin loading status.
Developed by Md. Shifat Hasan
Contact
refactor.nvim is distributed under the MIT License.
