EmEditor Home - EmEditor Help - EmEditor Macro Reference - Tutorial

Insert Characters

To insert characters using a macro, use the Text Property. Modify our tutorial file as follows:


    document.selection.Text = "EmEditor supports macros.";
    document.selection.Text = "\tEmEditor is a text editor.";


    document.selection.Text = "EmEditor supports macros."
    document.selection.Text = Chr(9) & "EmEditor is a text editor."

The NewLine Method added in the second line inserts a new line at the cursor position. The code in the third line inserts a tab character at the beginning of the string. A tab character is represented by "\t" in JavaScript, and Chr(9) in VBScript. You can also use the VBScript constant, vbTab, for a tab character.

The following tables list commonly used escape sequences in both scripting languages.

\b \u0008 Backspace.
\t \u0009 Horizontal Tab.
\n \u000a New line.
\f \u000c Form feed.
\r \u000d Carriage return.
\" \u0022 Double quote.
\' \u0027 Single quote.
\\ \u005c Backslash.
\xXX The Latin-1 character with the encoding specified by the two hexadecimal digits.
\uXXXX The Unicode character with the encoding specified by the four hexadecimal digits.
Reference: JScript Special Characters (Microsoft MSDN Library)
vbCr Chr(13) Carriage return.
vbCrLf Chr(13) & Chr(10) Carriage return + new line combination.
vbFormFeed Chr(12) Form feed.
vbLf Chr(10) New line.
vbNewLine Chr(13) & Chr(10) or Chr(10) Platform-specific new line character. Equivalent to vbCrLf in Windows.
vbTab Chr(9) Horizontal tab.
vbVerticalTab Chr(11) Vertical tab.
Reference: VBScript String Constants (Microsoft MSDN Library)


Line-endings are terminated with a combination of a \r (CR) and a \n (LF). Use the CR and LF in distinct manners. For example, if you write:

document.selection.Text = "\n";

only carriage return (LF) is inserted, which is not a line-ending convention in Windows. When you press the RETURN key in EmEditor, EmEditor inserts whatever line-ending (CR only, LF only, or CR+LF) is used in that line. If you want the same behavior upon pressing the RETURN key, as in EmEditor, we recommend that you use the NewLine Method or the writeln Method.

Next Topic:

Move Cursor

Copyright 2003-2015 by Emurasoft, Inc.