To create a custom COBOL snippet

You need to use the Visual Studio Code Snippets Manager (click here) to manage code snippets and to create new custom ones. Do not edit the snippets directly in their default installation folder. Any changes you make in that location will be reverted and lost if you later install an upgrade to Visual COBOL such as a Patch Update release. Following the Microsoft procedure ensures that the snippets will be handled correctly during a Patch Update install.

The following instructions are for creating a standard COBOL snippet file:

  1. Create a code snippet file.

    See the Visual Studio Help for instructions.

  2. Edit the code of the snippet file in the editor to include the desired functionality.

    See the MSDN Code Snippet Schema Reference.

  3. Specify COBOL as the Language attribute in the <Code Language=""> tag - <Code Language="COBOL">.
  4. Save the file as type Snippet Files (*.snippet).
  5. To update Intellisense with your snippet, use Visual Studio Code Snippet Manager to add the file you just created to the available COBOL snippets.

    See How to: Manage Code Snippets in the Visual Studio Help.

When inserting a snippet, the editor automatically indents it into the code area, taking care of where the margin for the source file is according to its source format.

Snippets that use the left margin

You can use Micro Focus-specific snippet functions to define snippets which use the left margin. You add the function at the start of each line that needs offsetting.

If any of these functions are used in the snippet, the default margin auto-indent is not applied.

Function Behavior
MFOffsetLeftMargin() Inserts the following number of white spaces to pad the left margin:
  • 0 - for free source format
  • 7 - for variable or fixed source format
MFMarginComment () Inserts a comment marker in the indicator column.
MFOffsetToIndicatorCol() Inserts the following number of white spaces to pad to column before the indicator column:
  • 0 - for free source format
  • 6 - for variable or fixed source format


The following example shows the code for a typical snippet:

<Code Language="COBOL">
display "My snippet contents"

The following example demonstrates the use of Micro Focus-specific snippet functions:

        <Literal Editable="false">
        <Literal Editable="false">
<Code Language="COBOL" Delimiter="~">
~marginComment~My snippet comment
~offsetMargin~display "Hello World"