how to jump to close brackets

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

how to jump to close brackets

Postby maileid » Thu Jan 15, 2009 7:22 am

Hi,
is there any KEY I can use to jump to close brackets while I edit files?

{ // edit here, and press a hotkey, then jump to close brackets
abccvc

//jump to here}
maileid
Newbie
 
Posts: 3
Joined: Thu Jan 15, 2009 7:19 am

Re: how to jump to close brackets

Postby Mofi » Thu Jan 15, 2009 8:18 am

Search - Match Brace can be used. It selects everything between matching braces and sets the cursor to the opening brace or if the cursor is already on the opening brace, it sets the cursor on the matching closing brace.

So you need to press the hotkey for Search - Match Brace twice and key RIGHT or LEFT to unselect and continue editing.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: how to jump to close brackets

Postby maileid » Fri Jan 16, 2009 6:58 am

I found the solution. I should set the cursor before "{", then I can match whole brackets.

Thanks for your help.
maileid
Newbie
 
Posts: 3
Joined: Thu Jan 15, 2009 7:19 am

Re: how to jump to close brackets

Postby Mofi » Fri Jan 16, 2009 7:31 am

Don't know which version you use, but if I execute Match Brace while the cursor is inside { .... } the whole block is selected and the cursor is set left to the opening brace. Second Match Brace moves cursor to the closing brace.

To be more precise: First match brace with cursor anywhere in the code searches for next opening { ( [ or closing } ) } and selects the block defined by the found brace.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: how to jump to close brackets

Postby maileid » Fri Jan 16, 2009 11:43 am

I am using lastest version, 14.20.xxx and default setting/install.

| {A (B) }
if cursor before {, it match "{A (B) }"

{A |(B) }
if here, it match (B)
maileid
Newbie
 
Posts: 3
Joined: Thu Jan 15, 2009 7:19 am

Re: how to jump to close brackets

Postby Mofi » Fri Jan 16, 2009 12:05 pm

Yes, that's the behaviour I wanted to explain in my previous post. Of course you can configure which "strings" (braces, brackets) you want to be found by the match brace function.

The standard in the wordfile for most languages is:

/Open Brace Strings = "{" "(" "["
/Close Brace Strings = "}" ")" "]"

But if you change that to:

/Open Brace Strings = "{" "["
/Close Brace Strings = "}" "]"

then also with the cursor located as written in your second example whole {A (B) } will be matched, (B) is ignored now.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: how to jump to close brackets

Postby Mofi » Sun Jan 18, 2009 11:21 am

I have another idea how to always jump right to the matching } without changing the brace strings in the wordfile. This solution gives you the possibility to use the Match Brace command for {}, () and [], and additionally you can use a different hotkey to always jump to matching } independent of the current cursor position.

You have to copy following macro code lines into a new macro using the Edit Macro dialog. You can specify any name for the macro. Important is that you disable first macro property Show Cancel dialog for this macro, but enable the second macro property Continue if search string not found. And of course you should specify a hotkey for the macro to be able to fast execute it at any time later.

IfCharIs "{"
Else
Find MatchCase Up "{"
IfNotFound
Find MatchCase "{"
IfNotFound
ExitMacro
EndIf
EndIf
EndSelect
Key LEFT ARROW
EndIf
MatchBrace
IfSel
EndSelect
Key LEFT ARROW
Key RIGHT ARROW
EndIf

Please insert at top of this macro the command for the regular expression engine you prefer to use (UnixReOff or UltraEditReOn, UnixReOn, PerlReOn). The macro does not run regular expression searches, but also non regular expression searches are done with one of the 3 search engines and therefore it should be specified which one.

You should save the macro into a macro file (probably with other macros) which is specified at Macro - Set Auto Load for automatic loading on startup of UltraEdit. Then the macro file with this special macro is automatically loaded on startup of UltraEdit and you just have to press the macro hotkey to execute the macro and position the cursor right of next matching }.

Here is the macro code again with indentations for easier reading and understanding:

Code: Select all
IfCharIs "{"
Else
    Find MatchCase Up "{"
    IfNotFound
        Find MatchCase "{"
        IfNotFound
            ExitMacro
        EndIf
    EndIf
    EndSelect
    Key LEFT ARROW
EndIf
MatchBrace
IfSel
    EndSelect
    Key LEFT ARROW
    Key RIGHT ARROW
EndIf
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to UltraEdit General Discussion