Behavior

To set indentation preferences for text files that do not have C++ or QML code (such as Python code files), select Preferences > Text Editor > Behavior.

Behavior tab in Text Editor preferences

You can set how to interpret the Tab and Backspace key presses and how to align continuation lines.

Setting tab preferences

You can set tab preferences at the following levels:

  • For all C++ files
  • For all QML files
  • For all other text files
  • For C++ files in a project
  • For QML files in a project
  • For other text files in a project

Setting tabs and indentation

You can set tab policy and tab size in the Tabs and Indentation group. In the Default Tab policy field, select whether to use only spaces or only tabs for indentation, or to use a mixture of them.

By default, the tab length in code editor is 8 spaces and the indent size is 4 spaces. You can set the tab length and indent size separately for each project and for different types of files.

You can have continuation lines aligned with the previous line. In the Align continuation lines field, select Not at all to disable automatic alignment and indent continuation lines to the logical depth. To always use spaces for alignment, select With Spaces. To follow the Tab policy, select With Regular Indent.

Setting typing preferences

When you type text or code, it is indented automatically according to the selected text editor or code style preferences. To set typing preferences, select Preferences > Text Editor > Behavior > Typing.

The following table describes the typing preferences you can set.

PreferenceDescription
Enable automatic indentationAutomatically indent new lines according to the text editor or code style preferences.
Backspace indentationset how the indentation is decreased when you select Backspace:
  • To go back one space at a time, select None.
  • To decrease indentation in leading white space by one level, select Follows Previous Indents.
  • To move back one tab length if the character to the left of the cursor is a space, select Unindents.
Tab key performs auto-indentset when the Tab key automatically indents text:
  • To always indent text, select Always.
  • To only indent text when the cursor is located within leading white space, select In Leading White Space.
  • To never indent text, select Never.
Prefer single line commentsWhen your highlight definition file has definitions for both multi and single line comments, select this option to apply the single line comment definition when commenting out a selection.
Preferred comment positionSet the position of single line comments when you comment out a selection:
  • To let the highlight definition for the file determine the position of single line comments, select Automatic. If no highlight definition is available, the comments are placed after leading whitespace.
  • To always place single line comments after leading whitespace, select After Whitespace.
  • To place single line comments at the end of the line, select At Line Start.

Cleaning up whitespace upon saving

To automatically clean up whitespace each time you save a file, select Preferences > Text Editor > Behavior, and go to Cleanups Upon Saving.

The following table describes the cleanup preferences you can set.

PreferenceDescription
Clean whitespaceRemove trailing whitespace upon saving.
In entire documentClean whitespace in the entire document instead of only in the parts that you changed. Available when Clean whitespace is selected.
Clean indentationCorrect leading whitespace according to the tab settings. Available when Clean whitespace is selected.
Skip clean whitespace for file typesList wildcard-aware file patterns, separated by commas or semicolons, for which trailing whitespace is not trimmed. By default, *.md, *.MD, Makefile are skipped. Available when Clean whitespace is selected.
Ensure newline at end of fileAlways write a newline character at the end of the file.

Setting file encoding preferences

To set the default text encoding, byte order mark (BOM), and line ending style used when creating or saving files, select Preferences > Text Editor > Behavior, and go to File Encodings.

The following table describes the file encoding preferences you can set.

PreferenceDescription
Default encodingSelect the text encoding to use for new files and for files whose encoding cannot be detected automatically.
UTF-8 BOMSet how to handle UTF-8 byte order marks:
  • Add If Encoding Is UTF-8 always adds a BOM when saving a file in UTF-8 encoding. This does not work if the encoding is System, because the text editor does not know what encoding that actually is.
  • Keep If Already Present saves the file with a BOM if it already had one when it was loaded.
  • Always Delete never writes a UTF-8 BOM, possibly deleting a pre-existing one.

UTF-8 BOMs are uncommon and are treated incorrectly by some editors, so it usually makes little sense to add one. This setting does not affect the use of UTF-16 and UTF-32 BOMs.

Default line endingsSelect Unix (LF) or Windows (CRLF) as the default line ending style for new files.

Setting mouse and keyboard preferences

To set preferences for using the mouse and keyboard in the text editor, select Preferences > Text Editor > Behavior, and go to Mouse and Keyboard.

The following table describes the mouse and keyboard preferences you can set.

PreferenceDescription
Hide mouse cursor while typingHide the mouse cursor while you type. Not available on macOS.
Enable mouse navigationUse the mouse to navigate in the editor, for example, to follow links with Ctrl+click (or Cmd+click on macOS).
Enable scroll wheel zoomingZoom the text in the editor by holding Ctrl while rotating the mouse wheel.
Enable built-in camel case navigationMove within camelCase and snake_case names one hump or word part at a time when using cursor navigation and selection.
Enable smart selection changingMake Select Block Up and Select Block Down provide smarter selections.
Show help tooltips using keyboard shortcut (Alt)Show context-sensitive help or type information as a tooltip when you press Alt.
Show help tooltips using the mouseSelect On Mouseover to show context-sensitive help or type information on mouseover, or On Shift+Mouseover to show it only when you press Shift while hovering.

See also How to: Configure editors, Find preferences, Indent text or code, Specify Qt Quick code style, Configuring editors, C++ code style, and Nim.