Sharing Code Style Settings with an EditorConfig File

An EditorConfig file enables you to share custom editor settings and share them across different environments. Whenever an EditorConfig file is present in a project or on the file system, the settings in it override the global code style settings in your Visual Studio. New code you write is automatically formatted according to these settings. The following commands work with the settings in this file:

You can share this file across the teams in your organization so they can use it to set their default code style settings, or only apply them for specific projects. This ensures that all developers use consistent code styles.

Create an EditorConfig file from the Visual Studio options

  1. Click Tools > Options > Text Editor > Micro Focus COBOL > Code Style > Code Cleanup.
  2. Click Generate .editorconfig file from settings.
  3. Navigate to a folder on your machine that you want to save the file to, and click Save.

Create an EditorConfig file for a solution or a project

  • Right-click the solution in Solution Explorer, and click Add > New EditorConfig (COBOL).

    If you create the file at a project, or a folder level, the command is Add > New EditorConfig.

Rules for multiple EditorConfig files on your file system

There might be more than one EditorConfig files on your system. If a file contains the root = true setting, this indicates that it is the top-level file for Visual Studio to use.

Visual Studio starts searching for an .editorconfig in the folder that contains the source file opened in the editor. It then continues to search in the parent directories until it reaches the top-level folder, or if it finds an .editorconfig that has root = true.

Visual Studio then applies the settings from the .editorconfig file that contains root = true first, and then subsequently applies the settings from any .editorconfig files it finds in the child folders down the directory tree.

See the links in Related Information for more details about EditorConfig files.

Example .editorconfig file

See below an example of a .editorconfig. This shows a number of code style settings and their values as specified in Visual Studio in a particular environment.

# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# COBOL Files
[*.{cbl,ccp,cob,cobol,cpb,cpf,cpv,cpy,eco,if,ins,mf,pco,prc,sqb,v1}]

#### Core EditorConfig Options ####

indent_size = 4
indent_style = space
tab_width = 4

#### COBOL Options ####

# General preferences
mf_cobol_base_indent = 0
mf_cobol_preserve_left_margin = true
mf_cobol_wrap_column = 30
mf_cobol_right_margin_strategy = slide
mf_cobol_directive_alignment = indicator
mf_cobol_align_inline_comments = true
mf_cobol_preserve_end_of_line_comments = false

# Procedure Division preferences
mf_cobol_continuation_indent = 0
mf_cobol_nested_indent_reference = continuation_indent
mf_cobol_entry_point_column = 0
mf_cobol_full_stop_alignment = 17
mf_cobol_if_continuation_indent = unset
mf_cobol_if_condition_per_line = false
mf_cobol_if_condition_operator_alignment = false
mf_cobol_evaluate_indent = 4
mf_cobol_evaluate_when_indent = 5
mf_cobol_format_statements = true
mf_cobol_to_keyword_alignment = none
mf_cobol_align_using_parameters = false
mf_cobol_argument_alignment = by_continuation_indent

# Identification Division preferences
mf_cobol_break_after_heading = false

# Environment Division preferences
mf_cobol_ensure_new_line_after_paragraph_in_configuration_section = false

# Data Division preferences
mf_cobol_data_base_indent = 0
mf_cobol_data_indent = 12
mf_cobol_data_name_indent = 0
mf_cobol_data_name_top_indent = 0
mf_cobol_data_relation = parent_level_number
mf_cobol_data_clause_alignment = none

# Code cleanup preferences
mf_cobol_operator_style = unset
mf_cobol_qualifier_style = unset
mf_cobol_then_keyword_style = unset
mf_cobol_usage_keyword_style = unset
mf_cobol_id_keyword_style = id
mf_cobol_pic_keyword_style = unset
mf_cobol_comp_keyword_style = unset
mf_cobol_binary_keyword_style = unset