# Refactoring

## About

Refactorings allow you to change or generate code based on the code you have. You will find a list of refactors below. You can invoke a refactor by invoke the Refactor command or by pressing the key binding `Ctrl+Alt+R` .&#x20;

Only valid refactors will be returned in the drop down menu.

## Convert to $\_

This refactoring converts a `$PSItem` variable to the `$_` variable.&#x20;

![Convert to $\_](/files/-MPXO04v5yHzXhiR1aTm)

## Convert to $PSItem

Converts a reference to the `$_` variable to `$PSItem`.

![Convert to $PSItem](/files/-MPXOJpL1Oup_fK-FvSh)

## Convert to Multiline Command

Converts a command invocation into a multi-line command. Each parameter and argument is broken up with backticks.&#x20;

![](/files/-MOZS9SXQsx48tayR16e)

## Convert to Splat

Converts a command invocation into a splatting expression and creates a hashtable named `$Parameters` and then passes that hashtable as a splatting expression to the command. Positional arguments are not added to the hashtable.

![Convert to Splat](/files/-MOUGowA5Q-fn30u2UTF)

## Export Module Member

Exports the selected variable or function from a module using `Export-ModuleMember`.

![Export Module Member](/files/-MOU6cJ8KcTt9uMTBq7s)

## Extract Function

You can use the Extract Function refactor to convert a section of code into a function. It will analyze the selected block and determine if there are variables that should be added as parameters. These variables will be added to the `param` block.&#x20;

![Extract Function](/files/-MOUgHXdNw7fZnFH_Z1v)

## Extract Selection to File

You can use the Extract Selection to File refactor to create a new file based on the selection in the current active editor.&#x20;

![Extract Selection to File](/files/-MOTrwRfBGcOtWZdOcM_)

## Generate Function from Usage

You can generate a function based on a command example. This refactoring will analyze the parameters, arguments and whether the command is used in a pipeline. If used in a pipeline, this refactoring will generate an advanced function.&#x20;

![Generate Function from Usage](/files/-MOnjGH6ICKfhLoAMKdW)

## Generate Proxy Function

Proxy functions allow you to extend existing functions with new parameters and functionality. You can select a command that you use within your script and select the Generate Proxy Function refactoring to have it generate the proxy function code for you.

![Generate Proxy Function](/files/-MPsICFqK3dXdKAczbda)

## Introduce Using Namespace

The introduce using namespace refactoring adds a `using namespace` statement to the top of a script and replaces the selected type expression with the namespace removed.&#x20;

![Introduce Using Namespace](/files/-MPSCRt_mo2RtJDZ8U63)

## Reorder Parameters

You can reorder parameters by using the `Ctrl+PageUp` and `Ctrl+PageDown` key bindings. Ensure that your cursor is on top of a parameter for a command. Press one of the key bindings. To move a parameter to the right, use Page Up. To move a parameter to the left, use Page Down.&#x20;

![Reorder Parameters](/files/-MOsRAZOJjGKyJVvLHSZ)

## Split Pipeline

The split pipe refactoring will split a pipe into multiple lines. Each element in the pipe is stored in a variable and passed to the next item in the pipe. This can be useful for debugging long or complex pipeline operations.

![Split pipeline](/files/-MPRuUr-DpGW2sRPuBs1)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.poshtools.com/powershell-pro-tools-documentation/visual-studio-code/refactoring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
