Syntax Indent and SmartPaste®

Syntax Indent and SmartPaste® are two of the many SlickEdit® Core features designed to decrease typing, improving your coding efficiency. Syntax Indent automatically indents code to the correct levels. There are two ways that code can be indented: by using the automatic Syntax Indent feature, and/or by using tabs. SmartPaste reindents pasted text to the correct level based on surrounding code.

Syntax Indent

By default, if you press Enter while you are editing a source file, Syntax Indent automatically indents the cursor to the next level if it is moved inside a structure block. For example, if you edit a C file and the cursor is on a line containing the text for (:){ and you press Enter, a new line is inserted and the cursor is indented four spaces in from the letter "f" in the word "for".

To change the Syntax Indent spacing, complete the following steps:

  1. From the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select Indent.

  2. Change the value in the Syntax indent text box.

Indenting with Tabs

By default, when you press the Tab key to indent, literal spaces are inserted. If you plan to indent your code using tab characters, or if you will be editing files that already contain tabs, you will need to specify these preferences.

To activate tab indenting, from the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then click Indent. Select the Indent with tabs option.

Setting Tab Spacing

The default value of the Tab key is eight spaces. You can change this value in the Tabs text box. In general, the Tabs setting should match the Syntax indent value. For example, by default for the C language extension, the Syntax indent value is set to 4, and the Tabs setting is set to +4. The plus sign (+) indicates that the editor will automatically expand the stops by four. By default, the Tabs setting is "+4", which indicates that the default tab setting is eight spaces.

To work properly with the Sun Java API source code, the tab stops need to be in increments of eight, but the syntax indent must be set to four. The Syntax Indent affects not only the Tab key, but also the number of spaces to indent for each code block level.

Note

  • When you change the tab stops and indent for all languages except COBOL, change the Tabs text box to +value where value is the same value used for the Syntax indent text box. The Tabs text box only affects how tab characters are expanded on the screen. This does not affect the indent when pressing Tab, or the amount of indent for statements inside a code block.

  • For COBOL files, the Tabs text box also affects the Tab key. Syntax Indent still affects the indent for each code block level.

Setting Tab to Indent Selections

For the Tab key to indent the selection when text is selected, select the option Indent selection when text selected.

Setting Tabs for the Current File

To set tabs for the current buffer only, use the Tabs dialog box (Format → Tabs or gui_tabs command). You can set tabs in increments or at specific column positions. For example, to specify an increment of three, enter +3 in the text box. To specify columns, you could enter1 8 27 44 to specify tab stops that have absolute locations.

By default, the Tab key inserts enough spaces to move the text to the next tab stop. The Shift+Tab key combination deletes enough spaces to move the text to the previous tab stop. See Redefining Common Keys for information on other Tab and Shift+Tab key bindings. Regardless of the Tab key binding, if the language-specific setting Indent with tabs is on, a physical tab character is inserted (see Indenting with Tabs).

Setting the Backspace Unindent Style

By default, pressing the Backspace key when the previous character is a tab, causes the rest of the line to be moved to the previous tab stop. If you want your Backspace key to delete through tab characters one column at a time, from the main menu, click Window → SlickEdit Preferences, expand Keyboard and select Redefine Common Keys, then set the Backspace over tab option. See Redefining Common Keys for more information.

SmartPaste®

When pasting lines of text into a source file, SmartPaste reindents the added lines according to the surrounding code. For example, if editing a C or C++ file, select some lines with a line selection (Ctrl+L), copy them to the clipboard (Ctrl+C), then paste them inside a for loop block (Ctrl+V). The added lines are correctly indented according to the for loop's indent level. SmartPaste will work for character/stream selections; however, the last line of the selection must include the end-of-line character. Use the mouse to copy and move lines and still take advantage of SmartPaste.

SmartPaste is enabled by default, and can be turned on and off from the language-specific Indent option screen. To access these options, from the main menu, click Window → SlickEdit Preferences. Expand Languages in the tree, select the language category and language, then click Indent. Select or clear the Use SmartPaste® option.

Note

SmartPaste only works with line selections. For information about creating a line selection, see Line Selections.