Using Multiple Selections to Edit Python Code in Wing

Jan 12, 2017

Introduction

This is the first in a series of articles on features that are new or improved in Wing Python IDE version 6.

Wing is a family of Python IDEs with closely integrated editing, debugging, and unit testing capabilities. Wing version 6 improved and extended support for multiple selections on the editor, making it easier to select and then apply edits to a number of selections at once.

The first thing to say about multiple selections is that they are not the right tool to use if you are trying to change the name of a symbol globally across multiple files. In that case, you should use Rename Symbol refactoring instead from the Refactor menu. This will complete the operation in one step, rather than requiring editing each file

That said, multiple selections are very useful when you are trying to change a subset of occurrences of a symbol, or want to edit strings that are not symbol or that occur in comments or strings.

Making Selections

Multiple selections are created by selecting one occurrence of the string you want to edit and using the multiple selection icon in the toolbar, or the key bindings for the commands found in the Edit > Multiple Selections menu to also select other occurrences of that string:

/images/blog/multiple-selections/toolbar.png

Adding the next occurrence, or dropping the current occurrence and adding the next one, are the most common way in which multiple selections are made. You can also add all occurrences of the current selection within the file, class, function, method, or block, and there are options to select only occurrences that match in case or that are whole words.

Another way to make multiple selections is to Ctrl-Alt-click (or Option-Command-click on OS X) and select an additional non-empty range of text. This can be combined with the above to create arbitrary sets of selections that don't necessarily all contain the same text.

Managing Selections

After you've started making selections, Wing will show a popup that includes all the selections, whether or not they are on screen:

/images/blog/multiple-selections/example.png

Clicking on items in the popup will scroll the editor to show that selection. You can remove items accidentally selected by mousing over the item and pressing the red X icon.

Editing Selections

Once you have all the selections that you want made in the editor, you can move the caret or type and your edits will be applied to all the selections at once. For example, pressing left arrow, then Delete for forward-delete, and then x will replace the first letter of each selection with ``x`:

System Message: WARNING/2 (<string>, line 60); backlink

Inline literal start-string without end-string.
/images/blog/multiple-selections/result.png

For more information, please see Multiple Selections in the documentation or just Download Wing and try it with your own source code. The Quick Start will take you through the basics of setting up the IDE, and the Tutorial provides a more in-depth introduction to all of Wing's features.



Share this article: