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 the section called “The Editing Pane”.
pane of the the > dialog box. SeeIn the current buffer for the duration of the editing session in the the section called “The Buffer Options Dialog Box”.
> dialog box. SeeIn 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
:
S+TAB
or
A+LEFT
) removes one level of indent from each selected
line, or the current line if there is no selection.
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.
C+e r
)
removes all whitespace from the end of each selected line, or the
current line if there is no selection.
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 the section called “The Editing Pane”.
pane of the > dialog box. SeeIn the current buffer for the duration of the editing session in the the section called “The Buffer Options Dialog Box”.
> dialog box. SeeIn 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.
> > converts soft tabs to hard tabs in the current selection, or the entire buffer if nothing is selected.
> > converts hard tabs to soft tabs in the current selection, or the entire buffer if nothing is selected.
Elastic tabstops are an alternative way to handle tabstops. Elastic tabstops differ from traditional fixed tabstops because columns in lines above and below the "cell" that is being changed are always kept aligned. As the width of text before a tab character changes, the tabstops on adjacent lines are also changed to fit the widest piece of text in that column. It provides certain explicit benefits like it saves time spent on arranging the code and works seemlessly with variable width fonts.But at the same time it can make the code look unorganized on editors that do not support elastic tabstops.
This feature is known as elastic tabstops. Elastic tabstops can be enabled or disabled in one of several ways:
On a global or mode-specific basis in the the section called “The Editing Pane”.
pane of the > dialog box. SeeIn the current buffer for the duration of the editing session in the the section called “The Buffer Options Dialog Box”.
> dialog box. SeeIn 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”:
:elasticTabstops=flag
:
Note that this feature does not work with soft tabs. where tabs are emulated as spaces
The auto indent feature inserts the appropriate number of tabs or spaces at the beginning of a line. There are three different indentation schemes to choose from: “full”, “simple”, and “none”. The scheme can be chosen on a global or per-edit mode basis using the pane of the > dialog. It can also be changed for a specific buffer using the dialog, or with a buffer-local property. (see the section called “Buffer-Local Properties”)
In this default scheme, the amount of indentation inserted 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.
The automatic indentation can be triggered by: pressing
ENTER
(this will by default only affect the
indentation of the new line), pressing TAB
at
the beginning of, or inside the leading whitespace of a line,
entering one the bracket characters defined in the edit mode,
pressing one of the electricKeys
for the
current edit mode (more details in
the section called “The PROPS Tag”), or when causing a hard wrap
(see the section called “Wrapping Long Lines”).
No matter what automatic indentation scheme is currently
active, C+i
) indents all
selected lines, or the current line if there is no selection, as
if in the “full” scheme.
Electric keys cause reapplying of the indentation rules to the current line. Thanks to the electric keys the following code fragments are indented properly on-line:
Java, C: brackets. If indenting brackets are defined for the language, they are implicitly considered electric keys. Thus a closing bracket is placed in its correct position immediately after being typed.
Java, C: labels. Labels end with a colon and the colon is included in electric keys for these languages. With pressing the colon, the line is reindented and the labels are indented a level to the left.
Basic: endif
. Here f
letter is an electric key, that makes the line indented
to the left.
In jEdit 4 electric keys worked unconditionally. As of jEdit 5 they trigger reindentation only if the indentation of the line, before pressing a key, is the same as jEdit would indent it using its rules. This allows for specifying more electric keys in mode files, because they don't cause unwanted indentation like they did before. Electric keys including all letters seem to be good solution for basic-like languages.
In this simplified automatic-indentation scheme, only two
actions trigger an indentation: pressing ENTER
,
or causing a hard wrap. Only the new line will be indented, and
the amount of indentation will be the same as the previously
line.
In this automatic indentation scheme, no actions in the text area will trigger a reindentation, and all lines start completely unindented.
The behavior of the ENTER
and
TAB
keys can be configured in the
pane of the
>
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:
.
“none”.
, which is the default. This is equivalent to when using the indentation schemeThe TAB
can be bound to one of the
following, or again, any other command or macro:
.
“full” automatic indentation scheme.
, which is the default. This is equivalent to when not using the. This binding will not respect the selected auto indentation scheme.
See the section called “The Shortcuts Pane” for details.
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
.