Coder Social home page Coder Social logo

inc-rename.nvim's Introduction

inc-rename.nvim

A small Neovim plugin that provides a command for LSP renaming with immediate visual feedback thanks to Neovim's command preview feature.

inc_rename_demo.mp4

Installation

This plugin requires at least Neovim 0.8

Install using your favorite package manager and call the setup function.

lazy.nvim
{
  "smjonas/inc-rename.nvim",
  config = function()
    require("inc_rename").setup()
  end,
}
packer.nvim
use {
  "smjonas/inc-rename.nvim",
  config = function()
    require("inc_rename").setup()
  end,
}
vim-plug
Plug 'smjonas/inc-rename.nvim'

Somewhere in your init.lua, you will need to call the setup function:

require("inc_rename").setup()

Usage

Simply type :IncRename <new_name> while your cursor is on an LSP identifier. You could also create a keymap that types out the command name for you so you only have to enter the new name:

vim.keymap.set("n", "<leader>rn", ":IncRename ")

If you want to fill in the word under the cursor you can use the following:

vim.keymap.set("n", "<leader>rn", function()
  return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true })
๐Ÿ’ฅ noice.nvim support


If you are using noice.nvim, you can enable the inc_rename preset like this:

require("noice").setup {
  presets = { inc_rename = true }
}

Then simply type the :IncRename command (or use the keymap mentioned above).


๐ŸŒธ dressing.nvim support


If you are using dressing.nvim, set the input_buffer_type option to "dressing":

require("inc_rename").setup {
  input_buffer_type = "dressing",
}

Then simply type the :IncRename command and the new name you enter will automatically be updated in the input buffer as you type.

The result should look something like this:


๐Ÿ’ก Tip - try these dressing.nvim settings to position the input box above the cursor to not cover the word being renamed (thank you @RaafatTurki for the suggestion!):

require("dressing").setup {
  input = {
    override = function(conf)
      conf.col = -1
      conf.row = 0
      return conf
    end,
  },
}

Known issues

There have been reports of inc-rename not working with certain plugins and language servers:

Make sure to uninstall these if you are experiencing issues.

Customization

You can override the default settings by passing a Lua table to the setup function. The default options are:

require("inc_rename").setup {
 -- the name of the command
  cmd_name = "IncRename",
   -- the highlight group used for highlighting the identifier's new name
  hl_group = "Substitute",
   -- whether an empty new name should be previewed; if false the command preview will be cancelled instead
  preview_empty_name = false,
   -- whether to display a `Renamed m instances in n files` message after a rename operation
  show_message = true,
   -- whether to save the "IncRename" command in the commandline history (set to false to prevent issues with
   -- navigating to older entries that may arise due to the behavior of command preview)
  save_in_cmdline_history = true,
   -- the type of the external input buffer to use (the only supported value is currently "dressing")
  input_buffer_type = nil,
   -- callback to run after renaming, receives the result table (from LSP handler) as an argument
  post_hook = nil,
}
๐Ÿ’ก Renaming across multiple files


When renaming across multiple files, make sure to save all affected buffers with :wa. If the Nvim option inccommand is set to split (:set inccommand=split), a buffer with information about all identifiers to be renamed will be shown as you type.

Here is an example of how this could look like:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.