[Wingtips] Using Multiple Selections to Avoid Repetitive Code Editing Tasks

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Wingtips] Using Multiple Selections to Avoid Repetitive Code Editing Tasks

Wingware Announce


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 of code.

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 Add Selection for Next Occurrence from the Edit > Multiple Selections menu or by clicking on the multi-selection toolbar item, which looks like this:

/images/blog/multi-selection/multi-select-icon.png

You'll 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:

/images/blog/multi-selection/multi-select-1.gif

Shown above: Select "stocks", add four other occurrences, and replace all the selections by typing "trades".

Edits applied to all selections can include cursor movement, pasting, and other editing actions. So for example selecting a number of commas, pressing the right arrow key and then Space adds a space after all the commas:

/images/blog/multi-selection/multi-select-2.gif

Shown 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 once.

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:

/images/blog/multi-selection/multi-select-3.gif

Shown above: Press Ctrl-Alt (or Option-Command on OS X) while double-clicking to select several words and type "foo" to replace them all.

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 Rename Symbol in the Refactor menu.

Configuring Multi-Selections

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 it:

/images/blog/multi-selection/multi-select-4.gif

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 Configure Selections Window in the Edit > Multiple Selections 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:

/images/blog/multi-selection/multi-select-menu.png

For more information on multi-selection, take a look at Multiple 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

To edit subscription or unsubscribe:
http://wingware.com/lists/wingtips