RefactorEx

July 8, 2025 · View on GitHub

RefactorEx is a powerful editor extension that simplifies and accelerates code refactoring for Elixir projects. It introduces intuitive code actions to help you refactor Elixir code efficiently and confidently.

With RefactorEx, you can perform common refactorings like extracting functions, renaming variables, and more — all within a few clicks.

You can check all supported editors in our installation guide.

Example

Available refactorings

ScopeRefactoringTargetCommand
aliasExpand aliasesselectionrefactor (ctrl+.)
aliasExtract aliasselectionrefactor (ctrl+.)
aliasInline aliasselectionrefactor (ctrl+.)
aliasMerge aliasesselectionrefactor (ctrl+.)
aliasSort nested aliaseslinerefactor (ctrl+.)
caseConvert from withlinerefactor (ctrl+.)
caseConvert to withlinerefactor (ctrl+.)
constantExtract constantselectionrefactor (ctrl+.)
constantInline constantselectionrefactor (ctrl+.)
constantRename constantat symbolrename (F2)
functionExpand anonymous functionselectionrefactor (ctrl+.)
functionExtract anonymous functionselectionrefactor (ctrl+.)
functionExtract functionselectionrefactor (ctrl+.)
functionCollapse anonymous functionselectionrefactor (ctrl+.)
functionInline functionselectionrefactor (ctrl+.)
functionRename functionat symbolrename (F2)
functionUse keyword syntaxlinerefactor (ctrl+.)
functionUse regular syntaxlinerefactor (ctrl+.)
guardExtract guardselectionrefactor (ctrl+.)
guardInline guardselectionrefactor (ctrl+.)
guardRename guardat symbolrename (F2)
if elseUse keyword syntaxlinerefactor (ctrl+.)
if elseUse regular syntaxlinerefactor (ctrl+.)
pipelineIntroduce IO.inspectselectionrefactor (ctrl+.)
pipelineIntroduce pipelinerefactor (ctrl+.)
pipelineRemove IO.inspectlinerefactor (ctrl+.)
pipelineRemove pipelinerefactor (ctrl+.)
variableExtract variableselectionrefactor (ctrl+.)
variableInline variableselectionrefactor (ctrl+.)
variableRename variableat symbolrename (F2)
variableUnderscore not usedlinerefactor (ctrl+.)

How to use each refactoring

Alias: expand aliases

DescriptionExpand nested aliases to their full names
TargetSelection of nested alias, group of nested aliases or alias with nesting
Inverse ofMerge aliases
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Alias: extract alias

DescriptionExtract the module full name into an alias and use it
TargetSelection of module full name
Inverse ofInline alias
ExampleExample

▲ top


Alias: inline alias

DescriptionReplace the alias usage by the module full name
TargetSelection of alias usage
Inverse ofExtract alias
Notes1. alias must be declared on the same module
2. alias declaration will not be removed
ExampleExample

▲ top


Alias: merge aliases

DescriptionMerge the group of aliases into a nested alias
TargetSelection of two or more mergeable aliases
Inverse ofExpand aliases
ExampleExample

▲ top


Alias: sort nested aliases

DescriptionSort all nested aliases alphabetically
TargetLine of alias with unsorted nested aliases
ExampleExample

▲ top


Case: convert from with

DescriptionConvert with statement to case statement
TargetLine of with statement
Inverse ofConvert to with
Noteswith statement cannot have multiple clauses
ExampleExample

▲ top


Case: convert to with

DescriptionConvert case statement to with statement
TargetLine of case statement
Inverse ofConvert from with
Notescase statement cannot have an assignment in the expression
ExampleExample

▲ top


Constant: extract constant

DescriptionExtract a piece of code into a constant
TargetSelection of any code without variables
Inverse ofInline constant
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Constant: inline constant

DescriptionReplace a constant usage by its value
TargetSelection of constant
Inverse ofExtract constant
Notes1. constant must be declared on the same module
2. constant declaration will not be removed
ExampleExample

▲ top


Constant: rename constant

DescriptionReplace the name of constant in all its usages
TargetCursor at constant definition or usage
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Function: collapse anonymous function

DescriptionCollapse a fn function into a & function
TargetSelection of fn function
Inverse ofExpand anonymous function
ExampleExample

▲ top


Function: expand anonymous function

DescriptionExpand a & function into a fn function
TargetSelection of & function
Inverse ofCollapse anonymous function
ExampleExample

▲ top


Function: extract anonymous function

DescriptionExtract a & or fn function into a function
TargetSelection of & or fn function
Inverse ofInline function
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Function: extract function

DescriptionExtract a piece of code into a function
TargetSelection of any code
Inverse ofInline function
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Function: inline function

DescriptionReplace a function call by its body
TargetSelection of function call
Inverse ofExtract anonymous function, Extract function
Read moreCatalog of Elixir refactorings
Notes1. function must be defined on the same module
2. function definition will not be removed
ExampleExample

▲ top


Function: rename function

DescriptionReplace the name of function in all its calls
TargetCursor at function definition or usage
Read moreCatalog of Elixir refactorings
Notes⚠️ Renaming a public function only affects the current file
ExampleExample

▲ top


Function: use keyword syntax

DescriptionRewrite the function using keyword syntax
TargetLine of function definition using regular syntax
Inverse ofUse regular syntax
Notesfunction body must have a single statement
ExampleExample

▲ top


Function: use regular syntax

DescriptionRewrite the function using regular syntax
TargetLine of function definition using keyword syntax
Inverse ofUse keyword syntax
ExampleExample

▲ top


Guard: extract guard

DescriptionExtract a when statement into a guard
TargetSelection of when statement or part of one
Inverse ofInline guard
ExampleExample

▲ top


Guard: inline guard

DescriptionReplace a guard call by its when statement
TargetSelection of guard call
Inverse ofExtract guard
Notes1. guard must be defined on the same module
2. guard definition will not be removed
ExampleExample

▲ top


Guard: rename guard

DescriptionReplace the name of guard in all its calls
TargetCursor at guard definition or usage
Read moreCatalog of Elixir refactorings
Notes⚠️ Renaming a public guard only affects the current file
ExampleExample

▲ top


If else: use keyword syntax

DescriptionRewrite the if else using keyword syntax
TargetLine of if using regular syntax
Inverse ofUse regular syntax
NotesClauses must have a single statement
ExampleExample

▲ top


If else: use regular syntax

DescriptionRewrite the if else using regular syntax
TargetLine of if using keyword syntax
Inverse ofUse keyword syntax
ExampleExample

▲ top


Pipeline: introduce IO.inspect

DescriptionPipe a piece of code into an IO.inspect
TargetSelection of any code
Inverse ofRemove IO.inspect
ExampleExample

▲ top


Pipeline: introduce pipe

DescriptionPipe the first arg into function call or case condition
TargetLine of function call or case condition
Inverse ofRemove pipe
ExampleExample

▲ top


Pipeline: remove IO.inspect

DescriptionRemove IO.inspect call
TargetLine of IO.inspect call
Inverse ofIntroduce IO.inspect
ExampleExample

▲ top


Pipeline: remove pipe

DescriptionRemove |> from function call or case condition
TargetLine of pipe (|>)
Inverse ofIntroduce pipe
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Variable: extract variable

DescriptionExtract a piece of code into a variable
TargetSelection of any code
Inverse ofInline variable
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Variable: inline variable

DescriptionReplace all usages of variable by its value
TargetSelection of variable assignment
Inverse ofExtract variable
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Variable: rename variable

DescriptionReplace the name of variable in all its usages
TargetCursor at variable definition
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top


Variable: underscore not used

DescriptionPlace a _ in front of variables defined but not used
TargetLine of unused variable
ExampleExample

▲ top