Bracket Matching

Misplaced and unmatched brackets are one of the most common syntax errors encountered when writing code. jEdit has several features to make brackets easier to deal with.

Positioning the caret immediately after a bracket will highlight the corresponding closing or opening bracket (assuming it is visible), and draw a scope indicator in the gutter. If the highlighted bracket is not visible, the text of the matching line will be shown in the status bar. If the matching line consists of only whitespace and the bracket itself, the previous line is shown instead. This feature is very useful when your code is indented as follows, with braces on their own lines:

public void someMethod()
{
    if(isOK)
    {
        doSomething();
    }
}

Invoking Edit>Source>Go to Matching Bracket (shortcut: C+]) or clicking the scope indicator in the gutter moves the caret to the matching bracket.

Edit>Source>Select Code Block (shortcut: C+[) selects all text between the closest two brackets surrounding the caret.

Holding down Control while clicking the scope indicator in the gutter or a bracket in the text area will select all text between the two matching brackets.

Edit>Source>Go to Previous Bracket (shortcut: C+e C+[) moves the caret to the previous opening bracket.

Edit>Source>Go to Next Bracket (shortcut: C+e C+]) moves the caret to the next closing bracket.

Bracket highlighting in the text area and bracket scope display in the gutter can be customized in the Text Area and Gutter panes of the Utilities>Options dialog box; see the section called “The Global Options Dialog Box”.

Tip

jEdit's bracket matching algorithm only checks syntax tokens with the same type as the original bracket, so for example unmatched brackets inside string literals and comments will be skipped when matching brackets that are part of program syntax.