Tutorial: Auto-Editing

Index of All Documentation » Wing Tutorial »

Let's revisit Auto-Editing, which was introduced before we tried out the debugger. So far we've seen the editor auto-enter invocation arguments and closing parentheses. There are a number of other auto-editing operations available as well:

Applying Characters to a Selection

If you select a range of text in the editor and press a quote, parenthesis, brace, bracket, or #, Wing applies that key stroke to the selection.

For example, try selecting a few lines of non-comment code and press #. Wing will comment out those lines using the comment style configured in the Editor > Block Comment Style preference. Pressing # a second time will remove the comment characters.

Also, selecting some text and pressing " (double quote) will surround it with double quotes, or pressing ( (open parenthesis) will surround it with parentheses. This also works when typing single quotes, triple quotes, back ticks, brackets, and braces.

Similarly, placing the caret next to a quote in a string and pressing either double quote or single quote will convert that string to either a double quoted or single quoted string.

These operations are on by default and may be disabled with the Apply Quotes to Selection, Apply Comment Key to Selection, and Apply [], (), and {} to Selection preferences in the Editor > Auto-Editing preference group.

Auto-Entering Spacing

Wing can also auto-enter spaces as you type code, optionally enforcing PEP8 style spacing. This auto-editing operation is off by default but can be turned on with the Editor > Auto-Editing > Auto-Enter Spaces preference. Try turning this on now and slowly typing the following into an editor:

import os
if os.environ['TEST'] == 'X' * 3:

Notice that Wing is auto-entering a space after the ], =, and other characters according to the context in the code. If you press the space anyway, it is ignored.

If you also enable the Editor > Auto-Editing > Enforce PEP8 Style Spacing preference, Wing will try to enforce PEP8 style spacing as you type. For example, typing the following disallows extra spaces around =:

x = 'test'

According to PEP8, spaces should not be used in argument lists. This is also the default behavior for Wing, whether or not PEP8 enforcement is on. To override this, enable the Editor > Auto-Editing > Spaces in Argument Lists preference.

Managing Blocks with the Colon Key

This operation saves a lot of typing but is off by default to avoid confusing new users. Enable it now with the Editor > Auto-Editing > Manage Blocks on Repeated Colon Key Presses preference then type the following into an editor:

if x == 1:

Notice that Wing will auto-insert a new line and indentation after the colon.

Now try typing the following before text = None on line 36 of example1.py, inside ReadPythonNews:

if force:

A new line and indent are added as before. Now, without moving the caret press : again. Wing will move the first following line (txt = None) under the new block so it looks like this:


Again without moving the caret press : a third time. Wing now moves the entire following block, up until the next blank line or first line indented less than the current one, so it looks like this:


Line Continuations

If you press Enter inside a comment (or string inside ()) and there is text after the caret, Wing auto-continues the line, placing the necessary comment or quote characters. For example, pressing Enter after the word code on the first line of example1.py results in the following:


This is on by default and can be disabled with the Editor > Auto-Completion > Continue Comment or String on New Line preference.

Correcting Out-of-Order Typing

Wing also tries to correct out-of-order typing. For example, type the following in an editor:

def y(:)

Wing figures out that the colon is misplaced and auto-corrects this to read:

def y():

Similarly, if you type the following:


Wing figures out that a . is probably missing and auto-corrects this to read:


By relying on this, it is possible to save key strokes for caret movement when coding.

This auto-editing operation is on by default and can be disabled with the Editor > Auto-Completion > Correct Out-of-Order Typing preference.