A tab is a special character that moves the caret to the next tab stop. Many programming languages rely on tabs to indent lines of source depending on how deeply they are nested in the code. jEdit has several features that make tabs and indentation easier to deal width.
Many believe that the One True Tab Size is 8, others think that all code should be indented with a tab width of 4, and the GNU Project refuses to accept code with a tab width of anything but 2.
There are three ways to change the tab size:
The tab size can be changed on a global basis in Editor pane of the the Utilities>Global Options dialog box.
The tab size can be changed in the current buffer for the duration of the editing session in the Utilities>Buffer Options dialog box.
The tab size can be changed in the current buffer for future editing sessions by setting the "tabSize" buffer-local property to the desired tab size, by placing the following in one of the first 10 lines of the buffer, where n is the desired tab size:
:tabSize=n: |
Sometimes, it is preferable to use multiple spaces instead of "real" tabs to indent code. The main advantage of doing so is that the file will look the same if viewed with a different default tab size. jEdit supports this with its "Soft Tabs" feature. If the Tab key is pressed with soft tabs enabled, the number of spaces necessary to move the caret to the next tab stop will be inserted, instead of a "real" tab.
There are three ways to use soft tabs:
You can specify if soft tabs should be used on a global basis in the Editor pane of the Utilities>Global Options dialog box.
You can specify if soft tabs should be used in the current buffer for the duration of the editing session in the Utilities>Buffer Options dialog box.
You can specify if soft tabs should be used in the current buffer for future editing sessions by placing the following in one of the first 10 lines of the buffer, where flag is either true or false:
:noTabs=flag: |
Edit>Lines>Shift Indent Left (keyboard equivalent: Alt-Left Arrow) and Edit>Lines>Shift Indent Right (keyboard equivalent: Alt-Right Arrow) will add or remove, respectively, one level of indent (a tab, or the number of spaces equivalent to a tab) to every line in the selection, or the current line if nothing is selected.
Edit>Selection>Spaces to Tabs will convert consecutive spaces to tabs in the selection. Edit>Selection>Tabs to Spaces will convert tabs to soft tabs (multiple spaces) in the selection.
Pressing Tab or Space at the start of every line to create the appropriate indent is very tedious, so jEdit has an auto indent feature.
Edit>Lines>Indent Selected Lines (keyboard equivalent: Control-I) will indent all selected lines, or the current line if there is no selection. If indent on enter is enabled, pressing Enter will create a new line with the appropriate amount of indent automatically. If indent on tab is enabled, pressing Tab on an unindented line will insert the appropriate amount of indentation. Pressing it again will insert an actual tab.
By default, indent on enter is enabled and indent on tab is disabled. There are three ways to specify when indentation should be performed:
Indent on enter and indent on tab can be set on a global basis in the Editor pane of the Utilities>Global Options dialog box.
Indent on enter and indent on tab can be set in the current buffer for the duration of the editing session in the Utilities>Buffer Options dialog box.
Indent on enter and indent on tab can be set in the current buffer for future editing sessions using buffer-local properties by placing the following in the first 10 lines of a buffer, where flag is either "true" or "false":
:indentOnEnter=flag:indentOnTab=flag: |
Auto indent rules are 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), if the previous line contains an open curly bracket ("{"), an extra tab (or soft tab) is inserted. Similarly, when you type a closing curly bracket ("}"), a level of indentation is removed. Also, "if", "else", "while" and so on create an extra level of indent on the next line.
If you want to insert a literal tab or newline without performing indentation, prefix the tab or newline with Control-E Control-V. For example, to create a new line without any indentation, type Control-E Control-V Enter.