Tabbing and Indentation
Prev | Chapter 6. Editing Source Code | Next

## Tabbing and Indentation

jEdit makes a distinction between the tab width, which is is used when displaying hard tab characters, and the indent width, which is used when a level of indent is to be added or removed, for example by mode-specific auto indent routines. Both can be changed in one of several ways:

- On a global or mode-specific basis in the Editing pane of the the Utilities>Global Options dialog box. See the section called “The Editing Pane”.

- In the current buffer for the duration of the editing session in the Utilities>Buffer Options dialog box. See the section called “The Buffer Options Dialog Box”.

- In the current buffer for future editing sessions by placing the following in one of the first or last 10 lines of the buffer, where `n` is the desired tab width, and `m` is the desired indent width:

      :tabSize=n:indentSize=m:

Edit>Indent>Shift Indent Left (shortcut: `S+TAB` or `A+LEFT`) removes one level of indent from each selected line, or the current line if there is no selection.

Edit>Indent>Shift Indent Right (shortcut: `A+RIGHT`) adds one level of indent to each selected line, or the current line if there is no selection. Pressing `Tab` while a multi-line selection is active has the same effect.

Edit>Indent>Remove Trailing Whitespace (shortcut: `C+e r`) removes all whitespace from the end of each selected line, or the current line if there is no selection.

### Soft Tabs

Files containing hard tab characters may look less than ideal if the default tab size is changed, so some people prefer using multiple space characters instead of hard tabs to indent code.

This feature is known as soft tabs. Soft tabs can be enabled or disabled in one of several ways:

- On a global or mode-specific basis in the Editing pane of the Utilities>Global Options dialog box. See the section called “The Editing Pane”.

- In the current buffer for the duration of the editing session in the Utilities>Buffer Options dialog box. See the section called “The Buffer Options Dialog Box”.

- In the current buffer for future editing sessions by placing the following in one of the first or last 10 lines of the buffer, where `flag` is either “true” or “false”:

      :noTabs=flag:

Changing the soft tabs setting has no effect on existing tab characters; it only affects subsequently-inserted tabs.

Edit>Indent>Spaces to Tabs converts soft tabs to hard tabs in the current selection, or the entire buffer if nothing is selected.

Edit>Indent>Tabs to Spaces converts hard tabs to soft tabs in the current selection, or the entire buffer if nothing is selected.

### Automatic Indent

The auto indent feature inserts the appropriate number of tabs or spaces at the beginning of a line by looking at program structure.

In the default configuration, pressing `ENTER` will create a new line with the appropriate amount of indent automatically, and pressing `TAB` at the beginning of, or inside the leading whitespace of a line will insert the appropriate amount of indentation. Pressing it again will insert a tab character.

The behavior of the `ENTER` and `TAB` keys can be configured in the Shortcuts pane of the Utilities>Global Options dialog. box, just as with any other key. The `ENTER` key can be bound to one of the following, or indeed any other command or macro:

- Insert Newline.

- Insert Newline and Indent, which is the default.

The `TAB` can be bound to one of the following, or again, any other command or macro:

- Insert Tab.

- Insert Tab or Indent, which is the default.

- Indent Selected Lines.

See the section called “The Shortcuts Pane” for details.

Auto indent behavior is mode-specific. In most edit modes, the indent of the previous line is simply copied over. However, in C-like languages (C, C++, Java, JavaScript), curly brackets and language statements are taken into account and indent is added and removed as necessary.

Edit>Indent>Indent Selected Lines (shortcut: `C+i`) indents all selected lines, or the current line if there is no selection.

To insert a literal tab or newline without performing indentation, prefix the tab or newline with `C+e v`. For example, to create a new line without any indentation, type `C+e v ENTER`.

Prev | Up | Next
Edit Modes | Home | Commenting Out Code