ultraedit

UltraEdit close matching brace


In most text editors, if you type in a { or " (you get the idea), the editor will automatically enter the opposite character, and put your cursor in between. I noticed that UltraEdit does not do this. Is there any way that I can setup UltraEdit so it will close a matching brace?


Solution

  • UltraEdit for Windows v23.20 introduced features for smart inserting of braces and quotes with Brace auto-completion and String auto-completion.

    Brace auto-completion

    • Brace pairs defined in wordfile are auto-closed when opening brace is typed
    • If no braces in wordfile, or if file is not syntax highlighted, "()", "{}", and "[]" are used as defaults
    • Pressing Enter will reposition close brace on separate line while maintaining proper indent levels
    • Pressing Backspace immediately following auto-completion will remove both opening and closing brace
    • Typing close brace skips over auto-completed close brace without inserting second brace
    • Can be disabled for non-highlighted (plain text) files
    • Can be disabled for comments and strings

    String auto-completion

    • Can be disabled for non-highlighted (plain text) files
    • Can be disabled for comments

    The settings for customization of those two features can be found in configuration at Editor - Braces / strings.

    UEStudio v16.20 introduced the same features with same configuration settings as UltraEdit for Windows v23.20.

    Former versions of UEStudio, the IDE with UltraEdit as core editing engine, have these features from the beginning which could be customized in configuration at IDE - IntelliTips - Miscellaneous by opening from menu Advanced with a click on menu item Configuration or clicking on ribbon tab Advanced on item Settings.

    But versions of UltraEdit for Windows prior v23.20 don't have those features.

    However, a non smart insert of { and } with setting caret between can be easily achieved with a macro which has the key pressed to insert { assigned to the macro as hotkey.

    How to create one or more new UltraEdit macros saved all together into a single macro file being configured for automatic load on startup of UltraEdit is explained in my answer on Search and replace with term list?

    The UltraEdit macro code for { is:

    InsertMode
    "{}"
    Key LEFT ARROW
    

    The same concept can be used for:

    a double quote

    InsertMode
    """"
    Key LEFT ARROW
    

    an opening square bracket

    InsertMode
    "[]"
    Key LEFT ARROW
    

    and an opening round bracket

    InsertMode
    "()"
    Key LEFT ARROW
    

    It is also possible to customize the macro for certain file types, for example:

    IfExtIs "c"
    InsertMode
    "{}"
    Key LEFT ARROW
    ExitMacro
    EndIf
    IfExtIs "cpp"
    InsertMode
    "{}"
    Key LEFT ARROW
    ExitMacro
    EndIf
    IfExtIs "h"
    InsertMode
    "{}"
    Key LEFT ARROW
    ExitMacro
    EndIf
    "{"
    

    This macro inserts } additionally to { on pressing key for { only when file extension of active file is c, cpp or h (in any case). For all other files just { is entered on pressing hotkey of macro in active mode (insert or overstrike mode).

    I suggest for inserting ( with ) an even more smart code for the macro:

    InsertMode
    "("
    IfCharIs 13
    ")"
    Key LEFT ARROW
    ExitMacro
    EndIf
    IfCharIs 10
    ")"
    Key LEFT ARROW
    ExitMacro
    EndIf
    IfEof
    ")"
    Key LEFT ARROW
    EndIf
    

    This macro inserts first just (. If next character is a carriage return (decimal value 13) or a line-feed (decimal value 10) or the caret is at end of file, additionally ) is inserted and caret is positioned between the parentheses. In all other cases just ( is inserted into active file.

    This enhancement makes it possible to modify a condition like

    if(iVar == 1 || iVar == 3)
    

    to

    if((iVar == 1) || (iVar == 3))
    

    without getting temporarily

    if(()iVar == 1 || iVar == 3)
    

    and

    if((iVar == 1) || ()iVar == 3)
    

    It is annoying to require in such cases to press key DEL to delete inserted, but unwanted ) after inserting ( somewhere in the middle of a line.