Saving Code Blocks as Snippets

The Code Snippets feature offers a quick way to store and re-use code blocks and content. Comment your snippets just as you would any code block.

Note To create a code snippet:
  1. Click the Snippets tab in the Resource pane.

  2. Right-click in the Snippets tab and choose Create Folder from the shortcut menu.
  3. Enter a name for the folder.
  4. Right-click in the Snippets pane and choose Add Snippet to open the Snippet dialog box.
  5. Enter a name for the snippet in the Description box. Note that snippet names cannot contain characters that are illegal in file names, such as slashes, special characters, double quotes, etc.
  6. In the Start Text window, type in or paste an opening code block. You can set a default spacing between the blocks by hitting the Enter key at the end of the start text and at the beginning of the end text.
  7. In the End Text window, enter a closing code block.
  8. Click OK. Right-click on a snippet to edit or delete it.

The default location for Snippets is the \UserData\Snippets folder below your ColdFusion Studio root directory.

Note Because snippets can be created as start and end blocks, you can use them to surround other tags and content. This is handy for inserting special formatting, navigation elements, and script blocks. Simply highlight the content you want to surround, then insert the snippet.

To insert a snippet, double-click an entry in the Snippets tab or right-click and select Insert into document from the menu.

Use the snippets shortcut menus to manage snippets and snippet folders.

Sharing snippets

You can share code snippets with other developers by giving them access to a shared folder on your machine or on another network machine.

Note To create a shared snippets folder:
  1. Open the Options > Settings dialog box (F8) and click Locations.
  2. In the Shared Snippets box, use the Browse button to navigate to the shared folder location and click OK.
  3. In the Snippets tab (in the Resources pane), right-click and choose Create Shared Folder. The folder icon changes color to show that it is shared.

Anyone with access to the shared folder can add, edit, and delete snippets.

Adding snippet shortcut keys

Open the Options > Customize dialog box and select the Snippet Shortcuts tab to enable a keyboard combination for a snippet. Select a snippet and press keys to enter the combination in the box at the bottom.

If a combination is in use, the current command appears below the shortcut box. To overwrite a combination, click Apply.