Skip to content

saecki/live-rename.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

Repository files navigation

live-rename.nvim

A neovim plugin to live preview lsp renames.

rename.mp4

Installation

lazy.nvim

{ "saecki/live-rename.nvim" }

vim-plug

Plug 'saecki/live-rename.nvim'

Setup (optional)

-- default config
require("live-rename").setup({
    -- Send a `textDocument/prepareRename` request to the server to
    -- determine the word to be renamed, can be slow on some servers.
    -- Otherwise fallback to using `<cword>`.
    prepare_rename = true,
    --- The timeout for the `textDocument/prepareRename` request and final
    --- `textDocument/rename` request when submitting.
    request_timeout = 1500,
    -- Make an initial `textDocument/rename` request to gather other
    -- occurences which are edited and use these ranges to preview.
    -- If disabled only the word under the cursor will have a preview.
    show_other_ocurrences = true,
    -- Try to infer patterns from the initial `textDocument/rename` request
    -- and use these to show hopefully better edit previews.
    use_patterns = true,
    -- The register which is used to temporarily record a macro into. This
    -- macro can then be executed on other symbols using the `macrorepeat`
    -- rename option.
    scratch_register = "l",
    keys = {
        submit = {
            { "n", "<cr>" },
            { "v", "<cr>" },
            { "i", "<cr>" },
        },
        cancel = {
            { "n", "<esc>" },
            { "n", "q" },
        },
    },
    hl = {
        current = "CurSearch",
        others = "Search",
    },
})

Usage

-- Start in normal mode and maintain cursor position.
require("live-rename").rename()

-- Start in normal mode and jump to the start of the word.
require("live-rename").rename({ cursorpos = 0 })

-- Start in insert mode and jump to the end of the word
require("live-rename").rename({ insert = true, cursorpos = -1 })

-- Start in insert mode with an empty word
require("live-rename").rename({ text = "", insert = true })

-- The actions that happened in the previous rename window are recorded as a macro.
-- The rename can be repeated by using `.`, or by manually calling the rename
-- funciton with the `macrorepeat` parameter.

-- The last lsp rename is repeated and commited without any further confirmation.
require("live-rename").rename({ macrorepeat = true, noconfirm = true })

-- Without `noconfirm` additional actions can be appended to the macro.
require("live-rename").rename({ macrorepeat = true })

live-rename includes a map function to make creating key mappings more ergonomic.
The options accepted are the same as for rename.

local live_rename = require("live-rename")

-- The following are equivalent
vim.keymap.set("n", "<leader>r", live_rename.rename, { desc = "LSP rename" })
vim.keymap.set("n", "<leader>r", live_rename.map(), { desc = "LSP rename" })
vim.keymap.set("n", "<leader>r", live_rename.map({}), { desc = "LSP rename" })

-- The following are equivalent
vim.keymap.set("n", "<leader>R", live_rename.map({ text = "", insert = true }), { desc = "LSP rename" })
vim.keymap.set("n", "<leader>R", function() live_rename.rename({ text = "", insert = true }) end, { desc = "LSP rename" })

Related

  • inc-rename.nvim is a similar plugin that implements the live preview using inccommand, while live-rename.nvim does so using extmarks and a floating window. The latter approach allows modal editing as if directly inside the buffer.

About

A neovim plugin to live preview lsp renames

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages