Wing Pro implements a suite of
auto-editing operations that take care of common
low-level editing tasks, like moving Python code into a new block,
arguments, and maintaining PEP 8 compliance as you type. Some of the
operations, like auto-closing (
or [, are enabled by
default and easy to
understand. Others may be missed unless you know about them, and some
need to be enabled
in preferences before they can be used.
In this and the next two installments of Wing Tips we'll be looking at some
useful Wing Pro auto-editing operations that are not so easy to
Note: If you have Wing Personal, you don't have these
features. Please bear with
us through this and the next two installments. We'll return to features
also present in Wing Personal after that. Or try Wing Pro on a free trial.
Creating Blocks with the Colon Key
To quickly turn an existing section of Python code into a new block,
select it and then
press the colon key. Wing Pro indents the selected lines and positions
the caret so you
can type if, for, while, def
or any other keyword that starts a block.
Shown above: Select lines then type ":if
ar" followed by Tab for auto-completion; a new block is created from the
Creating a Try/Except Block
If you select lines of Python code and type :try Wing adds except automatically
and selects it so you can either replace except with finally, press the
right arrow key to enter an exception specifier, and/or use Tab to move into the
except or finally block.
above: Select lines then type ":try" followed Right Arrow, Space, "P",
Tab to auto-complete "ParseError", and then Tab to move into the except
Note: Other keys can also be applied to selections. For
example " encloses
selection in quotes, (
encloses it in parenthesis, and #
it is commented out.
Creating Blocks without Selecting
It's also possible to create new blocks without selecting any lines
first. In some
versions of Wing, this option needs to be enabled with the Editor>Auto-Editing>ManageBlocksonRepeatedColonPresses
preference. Once that is done and a new block is
entered, the colon key can be pressed a second time to move the next
line into the new
block, and a third time to also move the rest of a contiguous block of
lines into the new
Shown above: Type "if use_" followed by Tab
for completion and ``:`` three times to pull more and more code into the
Note that you can also just select a block of code
and press the Tab key
it. If multiple indentations are possible for that block, Wing toggles
each time you press Tab.
That's it for now. In the next part of this 3-part Wing Tips series
auto-editing in Wing Pro we'll be looking at auto-invocation, which
makes writing Python
code that calls functions and methods easier and less prone to errors.