Wing Tips: Selecting Logical Units of Python Code in Wing
In this issue of Wing Tips we take a look at quickly selecting Python code in logical units, which can make some editing tasks easier.
Select More and Select Less
The easiest way to select code from the keyboard, starting from the current selection or caret position, is to repeatedly press Ctrl-Up (the Control key together with the up arrow key). Wing selects more and more code, working outward in logical units, as follows:
Press Ctrl-Up repeatedly to select increasingly larger units of Python code
If you select too much, pressing Ctrl-Down instead reduces the selection size again:
Press Ctrl-Down repeatedly to return to selecting smaller units of Python code
Select Statement, Block or Scope
Wing also provides commands for selecting the current, previous, or next Statement (a single logical line of code that may span multiple physical lines), Block (a contiguous section of code at same indent level, without any blank lines), or Scope (an entire function, method, or class).
Here's an example using several of these commands:
Execute "Select Statement", then "Select Block", "Select Scope", and finally "Select Next Scope"
Adding Key Bindings
If you plan to use these commands, you will probably want to bind them to keys using the User Interface > Keyboard > Custom Key Bindings preference for the following commands:
select-statement next-statement previous-statement select-block next-block previous-block select-scope next-scope previous-scope
Since free key combinations are often in short supply, you may want to make use of a multi-key sequence in your bindings. For example, pressing Ctrl-\ followed by B results in the binding Ctrl-\ B:
Add a key binding "Ctrl-\ B" for "select-block"
This only works if Ctrl-\ is not itself already a binding. Any other free key combination (and not only Ctrl-\) can be used as the starting key in the sequence.
That's it for now! We'll be back next week with more Wing Tips for Wing Python IDE.
Share this article: