.. _Extract to Variable:

Extract to Variable
===================

An expression inside a subprogram, process, or protected type can be extracted to a local variable.

**Select** the expression and press :kbd:`Ctrl+1`, select **Extract to local variable** from the list of quick assist proposals and press :kbd:`Enter`.

.. figure:: ../../images/common/vhdl_quick_assist_extract_to_variable_list.png
	:align: center




The variable is declared and initialized with the extracted expression in the correct scope.

.. figure:: ../../images/common/vhdl_quick_assist_extract_to_variable_after.png
	:align: center




.. tip::

	You may change the variable name and type. Press :kbd:`tab` to switch between the edit boxes.

.. tip::

	If the expression occurs multiple times throughout the enclosing scope, you may chose to replace all the occurrences with the newly created variable, or only the selected one.

.. tip::

	You can also **right-click** in the editor and go to **Refactor** > **Extract...**.

.. figure:: ../../images/common/vhdl_quick_assist_extract_to_variable_menu.png
	:align: center








