Skip to content

ShifatHasanGNS/refactor.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

refactor.nvim

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.

refactor-nvim-baby

Table of Contents


Features

  • 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

Installation

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()

Usage

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

How It Works

When you run a refactor command, the plugin guides you through these steps:

  1. Flags: Enter optional flags (e.g., cw for case-sensitive and whole-word). Press Enter to use defaults. Available flags:
    • c - Case-sensitive
    • w - Whole-word
    • r - Regular expression
    • p - Preserve case
  2. Find String: Enter the text or pattern to search for.
  3. Replace String: Enter the replacement text.
  4. Confirmation: Type y to proceed or n to 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.

Example

To replace all occurrences of "Yisra'el" with "Filastin" in the current buffer, case-sensitive and whole-word only:

  • Run :RefactorB or <leader>rb
  • Enter flags: cw
  • Find: Yisra'el
  • Replace: Filastin
  • Confirm: y

Configuration

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).

Health Check

Ensure the plugin is working correctly by running:

:checkhealth refactor

This command verifies the NeoVim version and plugin loading status.


Author

Developed by Md. Shifat Hasan

Contact

FacebookInstagramLinkedinX

License

refactor.nvim is distributed under the MIT License.

About

refactor.nvim | The most intuitive and powerful "Find & Replace" Plugin for NeoVim

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages