| Store | Cart

ActiveState Docs

Komodo 6.0 Documentation

Loading...

Snippets

Feature Showcases

Snippets are frequently used strings that can be quickly inserted into the current document. For example, repetitive sections of code or standard comments can be stored within a snippet. Snippets have advanced properties; they support the use of Tabstops and Interpolation Shortcuts, can be assigned to Key Bindings, and allow for the specification of indentation context and cursor position.

Snippets are stored in the Projects sidebar or the Toolbox.

Creating Snippets

To create a code snippet, select the desired block of text in the Editor Pane. Then drag and drop the selected section onto the Toolbox tab or into a project on the Projects tab.

Alternatively, select the desired text, then right-click and select Add as Snippet in the Toolbox.

Alternatively, right-click a folder in the Toolbox or on a project or folder name in the Projects sidebar, and select New Snippet. If you use this method, you must manually enter the contents of the snippet; text selected in the Editor Pane is not automatically added to the Snippet dialog box.

Configuring Snippets

To configure snippet properties, right-click the snippet on either the Toolbox tab or the Projects tab, and select Properties. The following configuration properties are available:

  • Snippet Name: Enter the text that should display in the Projects or Toolbox sidebars for this code snippet. If the snippet was created by dragging a text selection from the Editor Pane, the snippet is named after the text in the snippet.
  • Snippet Contents: If the snippet was created by dragging a text selection from the Editor Pane, the contents of the selected text are displayed in the Snippet Contents field. Otherwise, enter the contents of the snippet manually. Add or edit snippet content as desired.
  • Snippet Shortcuts: Add Interpolation Shortcuts or Tabstops to a snippet by clicking the arrow button to the right of the Snippets Contents field, and selecting a shortcut from the drop-down menu. Interpolation shortcuts in snippets are not executed when the snippet is inserted in the Editor Pane via dragging and dropping.
  • Maintain selected text or cursor position after insertion: Within the snippet contents field, either select a portion of the snippet (by dragging the mouse pointer over the desired selection) or position the editing cursor within the string. If this check box is selected, when the snippet is inserted into the Editor Pane, the selected text or the cursor position is displayed in the same manner.
  • Maintain indentation context after insertion: If the snippet is inserted into the Editor Pane when the editing cursor is in an indented position, select this check box to use the indentation point as an indentation "prefix". The indentation structure of the snippet is preserved at the position of insertion.

Using Snippets

To insert the contents of a snippet at the current cursor position in the Editor Pane, double-click it, or right-click the snippet and select Insert Snippet.

Although you can also drag and drop snippets onto the Editor Pane, the cursor position and indentation check box options explained above in Configuring Snippets will only take effect if the snippet is added using the double-click or Insert Snippet method.

Abbreviations

Snippets saved in a toolbox or project folder called "Abbreviations" (or a language-specific sub-directory) can be inserted by typing the snippet name in the buffer. See Abbreviations.

Snippet Options

To access options for the selected snippet, right-click a snippet in the Toolbox and select the desired option.

The following options are available:

  • Insert Snippet: Use this option to insert the snippet at the current cursor position in the editor, as described above in Using Snippets.
  • Cut/Copy/Paste: Used to duplicate or move a snippet when dragging is not convenient (e.g. to a project which is currently closed).
  • Show in File Manager: Shows the JSON file for the snippet in the system's default file manager.
  • Export as Zip File...: Exports the snippet in a standard ".zip" archive.
  • Rename: Changes the snippet name.
  • Delete: Permanently removes the selected snippet from the toolbox.

Snippet Properties

Snippet properties are used to alter or rename snippets (as described in Configuring Snippets, above). The Properties dialog box is also used to assign a custom icon to a snippet or to assign a custom key binding. To access the Properties dialog box, right-click the snippet and select Properties.

Assigning Custom Icons to Snippets

The default snippet icons can be replaced with custom icons. Komodo includes more than 600 icons; alternatively, select a custom image stored on a local or network drive (use 16x16-pixel images for best results).

To assign a custom icon to a snippet:

  1. In the Projects or Toolbox sidebar, right-click the desired snippet and select Properties. Alternatively, click the icon in the Projects or Toolbox sidebar, then select Projects|snippet_name|Properties or Toolboxsnippet_name|Properties.
  2. In the Properties dialog box, click Change Icon.
  3. In the Pick an Icon dialog box, select a new icon and click OK. Alternatively, click Choose Other, and browse to the desired image file.
  4. In the Properties dialog box for the snippet, click OK. The custom icon is displayed next to the snippet.

To revert to the default icon for a selected snippet:

  1. In the Projects or Toolbox sidebar, right-click the desired snippet and select Properties.
  2. Click Reset, then click OK. The default icon is displayed next to the snippet.

Snippet Key Bindings

To assign a key binding to a snippet, right-click the snippet on either the Toolbox, and select Properties. Select the Key Bindings tab, and configure the desired binding. See Key Bindings for Custom Components for more information.

See Abbreviations for details on inserting snippets by name.