Refactor module for nvim-treesitter
  • Lua 98.1%
  • Vim Script 1.5%
  • Shell 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-11-28 16:12:50 +01:00
.github ci: fix stylua action by update to v2 2023-03-21 00:30:22 +01:00
doc Add comments to help file 2023-03-21 00:41:46 +01:00
lua fix(highlight): don't apply usage highlight to definition node (#55) 2024-09-14 13:21:57 +02:00
plugin chore(refactor): add docs and highlight groups 2020-09-18 07:13:46 -05:00
scripts chore(all): initial feature commit 2020-09-15 13:02:06 -05:00
.editorconfig Initial commit 2020-09-15 12:44:19 -05:00
.luacheckrc chore(gh): add luacheckrc 2020-09-18 07:31:22 -05:00
.stylua.toml Use stylua to auto format code 2021-07-04 17:39:06 -05:00
LICENSE Initial commit 2020-09-15 12:44:19 -05:00
README.md docs(readme): announce deprecation 2025-11-28 16:12:50 +01:00

nvim-treesitter-refactor

Refactor modules for nvim-treesitter

Caution

This plugin is deprecated because it is not compatible with the maintained nvim-treesitter main branch. See https://github.com/nvim-treesitter/nvim-treesitter-locals for a replacement.

Installation

You can install nvim-treesitter-refactor with your favorite package manager, or using the default pack feature of Neovim!

Note: This plugin requires nvim-treesitter installed.

Using a package manager

If you are using vim-plug, put this in your init.vim file:

Plug 'nvim-treesitter/nvim-treesitter-refactor'

Highlight definitions

Highlights definition and usages of the current symbol under the cursor.

lua <<EOF
require'nvim-treesitter.configs'.setup {
  refactor = {
    highlight_definitions = {
      enable = true,
      -- Set to false if you have an `updatetime` of ~100.
      clear_on_cursor_move = true,
    },
  },
}
EOF

Highlight current scope

Highlights the block from the current scope where the cursor is.

lua <<EOF
require'nvim-treesitter.configs'.setup {
  refactor = {
    highlight_current_scope = { enable = true },
  },
}
EOF

Smart rename

Renames the symbol under the cursor within the current scope (and current file).

lua <<EOF
require'nvim-treesitter.configs'.setup {
  refactor = {
    smart_rename = {
      enable = true,
      -- Assign keymaps to false to disable them, e.g. `smart_rename = false`.
      keymaps = {
        smart_rename = "grr",
      },
    },
  },
}
EOF

Navigation

Provides "go to definition" for the symbol under the cursor, and lists the definitions from the current file. If you use goto_definition_lsp_fallback instead of goto_definition in the config below vim.lsp.buf.definition is used if nvim-treesitter can not resolve the variable. goto_next_usage/goto_previous_usage go to the next usage of the identifier under the cursor.

lua <<EOF
require'nvim-treesitter.configs'.setup {
  refactor = {
    navigation = {
      enable = true,
      -- Assign keymaps to false to disable them, e.g. `goto_definition = false`.
      keymaps = {
        goto_definition = "gnd",
        list_definitions = "gnD",
        list_definitions_toc = "gO",
        goto_next_usage = "<a-*>",
        goto_previous_usage = "<a-#>",
      },
    },
  },
}
EOF