-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Refactoring: Extract Variable
#Refactoring
###Extract Variable Extract refactorings are performed for the various expressions and blocks of code, including strings. Currently Extract refactoring on substrings is not supported.
Complete Expressions Refactoring is limited to complete expressions and blocks of code.
###Extract All The current release will extract all occurranes (within the current scope) of the selected expression and replace with a variable.
##How to invoke the Extract Variable command? There are a two options to invoke the extract variable command, they are as follows:
###Option 1 (Command Palette)
- Select the text (expression) to be extracted into a variable
- Launch the Command Palette via the shortcut (⇧⌘P or Ctrl+Shift+P)
- Select the 'Extract Variable' command
- The selected expression(s) will be extracted into a variable with a random name prefixed 'newvariable'
- Next provide a new name for this variable
###Option 2 (Quick Fix)
- Select the text (expression) to be extracted into a variable
- Launch the Quick Fix command from the Command Palette (or use the short cut ⌘. or cmd+.)
- Select the 'Extract Variable' command from the menu
- The selected expression(s) will be extracted into a variable with a random name prefixed 'newvariable'
- Next provide a new name for this variable
Launching the Quick Fix command from the Command Palette
Launching the Quick Fix command using the keyboard shortcut
###Option 3 (Keyboard Shortcut)
- Setup a custom keyboard short cut for the command 'python.refactorExtractVariable'
- Select the text on the editor
- Invoke the above command using the designated keyboard shortcut