[Wingtips] Using Multiple Selections to Avoid Repetitive Code Editing Tasks
In this issue of Wing Tips we
take a look at making multiple concurrent
selections on the editor, in order to apply a single edit simultaneously
to several parts
The most common way to make multiple selections is to select a range
of text and then add
other occurrences of the same text with AddSelectionforNextOccurrence
menu or by clicking on the multi-selection toolbar item,
which looks like this:
usually want to use the key binding for this, which is Ctrl-D, or Command-D
on OS X, and Ctrl->
in the emacs keyboard personality.
Once the selections are made your edits will be applied to all of
them in the same way,
as in the following example:
Shown above: Select "stocks", add four
other occurrences, and replace all the selections by typing "trades".
applied to all selections can include cursor movement, pasting, and
actions. So for example selecting a number of commas, pressing the right
arrow key and
then Space adds a
space after all the commas:
above: Select the first comma, add the other occurrences, press right
arrow, and then press Space to insert a space after all the commas at
Multi-Select with the Mouse
Multiple selections can also be made by clicking or double-clicking
the mouse while
holding Ctrl-Alt (or Option-Command on OS X).
This allows selecting ranges that
don't necessarily contain the same text:
above: Press Ctrl-Alt (or Option-Command on OS X) while
double-clicking to select several words and type "foo" to replace them
Renaming Variables and Attributes
If you have Wing Pro and are trying to change the name of a variable
or attribute globally
then multi-selection is usually not the right tool for the job. Instead,
use RenameSymbol in the Refactor menu.
As shown in the first example above, when more than one selection is
made, Wing displays a
floating window that enumerates the selections. You can remove
selections from here by
moving the mouse over an item and clicking on the red X icon that appears over
Shown above: Select all occurrences of
"foo", remove one selection, and and type "test" to replace the
remaining two instances.
This window can be disabled entirely
with ConfigureSelectionsWindow in
menu or the multi-selection toolbar item.
These menus are also the place to select whether occurrences match
only whole words or are
case sensitive, and they provide a way to quickly select all occurrences
in the file,
class, function/method, or block:
For more information on multi-selection, take a look at
Selections in the product manual.
That's it for now! We'll be back next week with more Wing Tips for
Wing Python IDE.
Wing Pro Python IDE tips and tricks