Komodo User Guide

Code Snippets

Code snippets are selections of frequently-used code. They can be stored in the Toolbox or the Project Manager, and quickly inserted into the current document.

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 the Projects tab.

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

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

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 Project Manager or Toolbox for this code snippet. If the snippet was created by dragging a text selection from the Editor Pane, the snippet will be 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 will be displayed in the Snippet Contents field. Otherwise, you must enter the contents of the snippet manually. Add or edit snippet content as desired.
  • Snippet Shortcuts: You can interpolate shortcuts into snippets by clicking the arrow button to the right of the Snippets Contents field, and selecting a shortcut from the drop-down menu. For a complete list of shortcuts, along with options and syntax for shortcuts, see Interpolation Shortcuts.
  • Maintain selected text or cursor position after insertion: within the snippet contents field, you can select a portion of the snippet (by dragging the mouse pointer over the desired selection). Also, you can set the position of the editing cursor within the snippet. If this box is checked, when the snippet is inserted into the Editor Pane the selected text or the cursor position will be displayed in the same manner in the Editor Pane.
  • Maintain indentation context after insertion: if you insert the snippet into the Editor Pane when the editing cursor is in an indented position, check this box to use the indentation point as an indentation "prefix". The indentation structure of the snippet will be 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 a snippet on either the Toolbox tab or the Projects tab. Alternatively, right-click the snippet and select Insert Snippet. Note that, 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 right-click method.

Snippet Key Bindings

To change the key binding for a code snippet, right-click the snippet on the Projects tab or the Toolbox tab, select Properties, then click the Key Binding tab. See Configuring Custom Key Bindings for a description of the fields on the Key Binding tab.

Top