code-refactor.nvim a collection of nifty code actions that do not require a LSP.
Screen.Recording.2024-01-29.at.9.56.03.mov
Install this plugin using your favorite plugin manager, and then call
require("code-refactor").setup()
.
{
"jdrupal-dev/code-refactor.nvim",
dependencies = { "nvim-treesitter/nvim-treesitter" },
keys = {
{ "<leader>cc", "<cmd>CodeActions all<CR>", desc = "Show code-refactor.nvim (not LSP code actions)" },
},
config = function()
require("code-refactor").setup({
-- Configuration here, or leave empty to use defaults.
})
end
}
Run the :CodeActions all
command to show a select list of available actions under the cursor.
Run :CodeActions [x]
to run a specific code action.
For example: :CodeActions toggle_arrow_function_braces
.
The default configuration is found in lua/code-refactor/config.lua
.
Simply call require("code-refactor").setup
with the desired options.
To disable code actions for any given language, simply return an empty table in file_types
.
require("code-refactor").setup({
available_actions = {
javascript = {
file_types = {},
},
},
})
Name | JavaScript | PHP |
---|---|---|
General | ||
Flip ternary | yes | yes |
Negate expression | yes | yes |
Convert arrow function | yes | yes |
JavaScript | ||
Toggle arrow function braces | yes |