Aliases

Aliases are identifiers that you can quickly type which are then expanded into snippets of text. You can use aliases for any text that you frequently type, including directory paths, function names, statements, and comment headers.

There are two types of aliases in SlickEditŪ Core:

Expanding Aliases

After typing the alias identifier, aliases can be expanded using any of these methods:

  • Pressing Ctrl+Shift+O for the expand_alias command. This command always expands the alias, regardless of available completions.

  • Pressing Ctrl+Space for the codehelp_complete command. This command will expand the alias only if there are no matching completions. Otherwise, it will show a list of completions.

  • If Syntax Expansion is enabled (Window → SlickEdit Preferences → Languages → [Language Category] → [Language] → Indent), aliases will automatically be expanded by typing a space.

  • Pause while typing and the alias will be displayed in the Auto-Complete list.

Tip

An option is available to show a tool tip of the matching alias for the word under the cursor. Click Window → SlickEdit Preferences → Languages → [Language Category] → [Language] → Auto-Complete and check the option Alias expansion. See Completions for more information.

Global Aliases

Global aliases work across all languages. One way to use global aliases is to save time in entering long directory paths. See Directory Aliases below.

Directory Aliases

Directory aliases take advantage of the fact that most users are constantly opening files from a small number of directories throughout the day. By using a directory alias when opening a file or changing directories, you do not have to type in long paths or click the mouse repeatedly in directory and file name fields within the editor.

After typing the alias identifier, directory aliases can be expanded by pressing Ctrl+Space. Global aliases are stored in the file alias.slk, located in the SlickEditŪ Core root installation directory.

Note

SlickEdit Core doesn't modify Eclipse's file management-related dialogs such as File → Open or File → Save As. Therefore, directory aliases are not available in these dialogs.

Defining a New Directory Alias

Directory aliases typically consist of a short abbreviation of the last name in a long directory path. For example, if you had a directory called c:\version20\src\project2\, a good alias name might be p2. For compiler include files, define an alias called inc (vinc in Microsoft Visual C++, binc in C++ BuilderŪ, or ginc for GCC) if you have multiple compilers.

To define a new directory alias, complete the following steps:

  1. From the main menu, click Window → SlickEdit Preferences → Editing → Global Aliases.

  2. Click New, then type the characters you wish to use for an identifier in the Alias Name text box.

  3. Click OK. The identifier you entered is now displayed in the alias list box on the options page.

  4. Make sure your new identifier is selected, then in the large text box to the right, enter the alias value by typing in the directory path that you want the identifier substituted with.

  5. Click OK.

Using Directory Aliases

After the directory aliases are defined, you can use them in any text box or buffer, including the Build view and the Open and Change Directory dialogs. For example, to use a directory alias in the Open dialog, complete the following steps:

  1. On the SlickEdit Core command line, type e (for "edit").

  2. Type the alias name (identifier) for the directory where the file resides.

  3. Press Ctrl+Space to expand the alias.

  4. Type the name of the file to open.

  5. Press Enter.

Embedding Environment Variables in Directory Aliases

If you keep source code in a version directory tree, you might want to set an environment variable and embed the environment variable in the alias value. For example, if you have a directory named c:\version20\src\project2\, define a p2 alias and give it a value such as %VERSION%\src\project2\. Type the following command on the command line to set or create the VERSION environment variable:

          set VERSION=c:\version20
        

For more information about setting environment variables, see Environment Variables.

Language-Specific Aliases

You can set up language-specific aliases for any frequently used text, such as comment headers. Each language can have one alias file, allowing aliases to be defined that do not affect other languages. Language-specific aliases are stored in files with the extension .als located in the user configuration directory.

The aliases that you create in a language are made available each time you open or create a file in that language. To manage language-specific aliases, from the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select Aliases. As an example, the Java Aliases screen is shown below.

Alias names are displayed in the list box on the left. The value for the selected alias name is displayed in the large text box to the right. Click Delete to remove a selected alias and its value.

Creating a Language-Specific Alias

To create a new alias, complete the following steps:

  1. Click New, then type the characters you wish to use for an identifier in the Alias Name text box.

  2. Click OK. The identifier you entered is now displayed in the list box in the Alias options page.

  3. Make sure your new identifier is selected, then in the large text box to the right, enter the alias value by typing in the text that you want the identifier substituted with.

  4. Click OK.

Tip

  • You can use special escape sequences in your aliases, which will be substituted upon expansion with certain values. See Alias Escape Sequences for more information.

  • You can also specify parameters in alias values. When the alias is expanded, you are prompted with a dialog to input the values. See Parameter Prompting for more information.

Alias Escape Sequences

Alias escape sequences can be used in alias values. When the aliases are expanded, the sequences are replaced with their values. The following table contains a list of the escape sequences that can be used for aliases. For examples, see Escape Sequence Examples below.

Note

If you leave a blank line in an alias, SlickEdit will automatically insert the sequence to preserve leading spaces, %\l, when you save the alias. This ensures that the blank line is preserved.

Escape Sequence

Description

%\a

Inserts the authors name.

%\c

Places the cursor. This sequence can be used multiple times in the same alias value in order to create a series of "hot spots" within the alias. After the alias is expanded, press Ctrl+[ (next_hotspot command) to jump to the next cursor stop.

%\d

Inserts the date (locale-dependent).

%\e

Inserts the date in MMDDYY format.

%\t

Inserts the time (locale-dependent).

%%

Inserts a percent character.

%\f

Inserts the current file name.

%\g

Inserts a file separator character. This is the backslash on Windows (\) platforms and slash (/) on UNIX/Mac.

%\w

Outputs the line number.

%\n

Inserts the current function name.

%\o

Inserts the current function name with signature.

%\j

Inserts the current class name.

%\j+

Inserts the current class name, fully-qualified.

%\i

Indents.

%\b

Unindents.

%\s

Preserves trailing spaces. This should be placed at the end of a line.

%\l

Preserves leading spaces.

%\x ColumnNumber

Moves the cursor to the specified column number.

%\x+ ddd

Increments column by ddd.

%\x- ddd

Decrements column by ddd.

%\m MacroName ArgumentList %

Calls the specified Slick-CŪ macro with a specified optional argument. This can be used for many purposes including surrounding text (see below) and inserting formatted dates (see Escape Sequence Examples).

%\m sur_text%

Uses the escape sequence to call a macro to surround the selected text. Indicates where the text to be surrounded is placed. See Surrounding and Unsurrounding for more information.

% EnvironmentVariable %

Inserts the value of the environment variable specified.

%( ParameterName )

Parameter Prompting replacement. See Parameter Prompting for more information.

%\p

Inserts parameters from the function that is located beneath it. See Doc Comments for more information.

%\q

Insert the type for the parameters (double, integer, string, etc.) from the function that is located beneath it. Typically used in conjunction with the %\p escape sequence. See Doc Comments for more information.

%\r

Inserts the return type from the function that is located beneath it. See Doc Comments for more information.

%\u

Includes this line in the expansion, if there are any function parameters that are expanded. If there are no function parameters expanded, this line is not included in the full expansion. See Doc Comments for more information.

%\v

Includes this line in the expansion, if there are any return types that are expanded. If there are no return types expanded, this line is not included in the full expansion. See Doc Comments for more information.

%\un

If there are any function parameters that are expanded, this line is not included in the full expansion. If there are no function parameters expanded, this line is included in the full expansion. See Doc Comments for more information.

%\vn

If there are any return types that are expanded, this line is not included in the full expansion. If there are no return types expanded, this line is included in the full expansion. See Doc Comments for more information.

%()

Used to separate identifier characters. For example, %\u%()n has the effect of the %\u option followed by a literal "n". It is recommended that %() be used to separate alias escape sequences ending with a letter from other identifier characters so that new aliases escape sequences won't break existing aliases you have. Don't write %\dx. Write %\d%()x instead.

Escape Sequence Examples

The following table contains some examples of using escape sequences in alias values:

Alias Name and Description

Value

Sample formatted dates

%\mprinttime #b. #d, #Y% ==> Apr. 07, 2008

%\mprinttime #A, #B #d, #Y% ==> Monday, April 07, 2008

%\mprinttime #m/#d/#Y% ==> 04/07/2008

comment - A header comment to have the date and time inserted.

************************************************/
/* Date: %\d Time: %\t */
/***********************************************/

if - A simple if statement, with indenting, support for surround, and a cursor position.

if(%\c){
%\i// Comment goes here
%\i%\m sur_text%
}

ifelse - An if/else statement with indenting and several cursor hot spots.

if(%\c){
%\i%\c
} else {
%\i%\c
}

wm - A WinMain function template with indenting and a cursor position.

int APIENTRY WinMain(HANDLE hInstance,
                     HANDLE hPrevInstance,
                     LPSTR lpszCmdParam, 
                     int nCmdShow)
{
%\i%\c
}

/** - A Javadoc comment.

/**
 * 
 * %\c
 * 
 * @author %\a (%\d)
 * %\u
 * @param %\p %\c
 * %\v
 * @return %\c%\v
 */

Parameter Prompting

Parameters can be set up for aliases, so that when the alias is expanded, you are prompted with a dialog to input the values. This is useful for reducing even more key strokes for repetitive tasks when using aliases that may require different values each time they are used.

To use parameter prompting, first define the parameters, then use them in your alias values by typing %(ParamName) where ParamName is the name of the parameter that you have defined (see Creating an Alias for Parameter Prompting below). When the alias is used and expanded, the Parameter Entry dialog will appear, prompting you for the parameter values, which will then be inserted into your text.

Creating an Alias for Parameter Prompting

To create an alias for parameter prompting, complete the following steps:

  1. Click New, then enter the new alias name. In the aliases list box (on the left side of the Alias page), make sure the new alias is selected.

  2. Click the Add button below the Parameters group box. The Enter Alias Parameter dialog is displayed.

  3. Enter the following values:

    • Parameter Name - Enter the name that you wish to use in the alias value.

    • Prompt - Enter the text that you wish to be prompted with. This is the label that will appear on the Parameter Entry dialog that prompts for values after the alias is expanded.

    • Initial Value - (Optional) Enter the initial value of the parameter. This text will appear in the text field of the Parameter Entry dialog that prompts for values after the alias is expanded.

  4. Click OK.

  5. If you wish to add more parameters, repeat Steps 2 through 4.

  6. On the Alias options page, the Parameters group box will now display a list of the parameters that you have added.

  7. In the large text field on the right side of the Alias options page, you can now type the alias value. In the places where you want parameter prompting to occur, type %(ParamName), where ParamName is the parameter name that you entered in Step 3.

  8. Click OK when you are finished.

Example: Instantiating a Variable in Java with Parameter Prompting

In Java, instantiating variables can be a repetitive task. The following code shows a common Java code snippet:

public class  {
    public static void main (String args[]) {
        String x = new String( arg[0] );
    }
}

You could define an alias for entering new class names with variables and arguments. That way, when you press Enter after the third line and type and expand the alias, you will be prompted for the values.

For this alias, use the Parameters section of the Alias options page to first define three parameters: class_name, var_name, and arg_list. Then, enter the following text for the alias value:

%(class_name) %(var_name) = new %(class_name)( %(arg_list) );

Creating a Language-Specific Alias from a Selection

You can create a language-specific alias from a selection by following the steps below.

  1. Select some code.

  2. Right-click and select Create Alias.

  3. Give the alias a name and click OK.

  4. The language-specific Alias options page appears, from which you can edit the code to fine-tune or add parameters.