Wing Tips: Auto-Editing in Wing Pro (Part 1 of 3)

Mar 28, 2019

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, entering invocation arguments, and maintaining PEP 8 compliance as you type. Some of the simpler auto-editing 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 discover.

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 that are 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 selection.

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.


Shown above: Select lines then type ":try" followed Right Arrow, Space, "P", Tab to auto-complete "ParseError", and then Tab to move into the except block.

Note: Other keys can also be applied to selections. For example " encloses the selection in quotes, ( encloses it in parenthesis, and # toggles whether 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 > Manage Blocks on Repeated Colon Presses 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 block.


Shown above: Type "if use_" followed by Tab for completion and ``:`` three times to pull more and more code into the new block.

Note that you can also just select a block of code and press the Tab key to reindent it. If multiple indentations are possible for that block, Wing toggles between them each time you press Tab.

That's it for now. In the next part of this 3-part Wing Tips series on 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.

Share this article: