User to user discussion and support for UltraEdit, UEStudio, UltraCompare, and other IDM applications.

This forum is user-to-user based and not regularly monitored by IDM.
Please see technical support page on how to contact IDM.
5 posts Page 1 of 1
Is there a shortcut key to surround selected text with quotes?
There is none by default, but it can be added by you with 3 different methods.


1. Global template

Open the Modify Templates dialog. How to open this dialog depends on version of UltraEdit. But you have unfortunately not posted which version of UltraEdit you use: UltraEdit for Windows v23.xx in ribbon or in toolbar/menu mode or a former version.

Select the Template group Global which is usually already preselected when used version of UltraEdit supports more than global templates at all (UE for Windows v18.00 and later).

Add a new template for example with name Add quotes and enter as template content: "[$replace$]^"

^ specifies the caret position after inserting the two double quotes in active file around selected text. No ^ or ^ at end sets the caret after second double quote. With ^ as given in example the caret is set before second double quote making it possible to insert just the 2 double quotes and having caret set between if there is currently nothing selected in active file.

Close the Modify Templates dialog window with a click on button OK.

Now open Advanced - Settings/Configuration - Key Mapping. In the list of commands search for InsertTemplate0 and assign a hotkey of your choice to this command.


2. Automatically loaded macro

Another possibility would be create a macro with the following commands:

Code: Select all
InsertMode
ColumnModeOff
IfSel
Clipboard 9
Cut
"""
Paste
"""
ClearClipboard
Clipboard 0
Else
""""
Key LEFT ARROW
EndIf

This macro is defined with the hotkey of your choice and stored in a macro file (together with other often needed macros) which is configured to be automatically loaded on startup of UltraEdit.

Update: A perhaps better macro for this task would be:

Code: Select all
InsertMode
ColumnModeOff
IfSel
UltraEditReOn
Find SelectText "^s"
Replace ""^s""
Else
""""
Key LEFT ARROW
EndIf

Or on using an old version of UltraEdit not supporting Find parameter SelectText:

Code: Select all
InsertMode
ColumnModeOff
IfSel
UnixReOff
Find "^s"
Replace All SelectText ""^s""
Else
""""
Key LEFT ARROW
EndIf


3. Script added to Script List

And the third possibility which I would not use for this task would be using a script which is added to the Script List with a hotkey for execution by key with following content:

Code: Select all
if (UltraEdit.document.length > 0)
{
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   if (UltraEdit.activeDocument.isSel())
   {
      UltraEdit.activeDocument.write('"' + UltraEdit.activeDocument.selection + '"');
   }
   else
   {
      UltraEdit.activeDocument.write('""');
      UltraEdit.activeDocument.key("LEFT ARROW");
   }
}

The used method works in UE v23.10.0.3 and former versions only for text not containing a Unicode character. The clipboard method would be needed for Unicode text as used by the macro.

The macro and especially the script solution can be made even smarter. For example the script could check if the selected text begins or ends already with a double quote to insert just the missing double quote at end or at beginning. Or which quotes are inserted (single or double quotes) depends on length of selected text (1 or more characters) or on the selected text itself (contains ' or " already) or on file type (file extension).
Best regards from Austria
I use similar macros for " but also for < { ( [ ' to either wrap the selected text or type the closing character.

It works well. But one annoying thing is as soon as you're in column mode and start typing one of these characters you're lost - instead of inserting " or ( in all lines, it stops working (what stops working depends on how the macro is written). But there is no "IfColMode" command and if you use "IfSel" and you are in column mode you are automatically "insel". So it fails somewhere in the macro.

So each time I'm in column mode and want to insert "<{([' I must use the "insert column" function - of course you tend to forget and frustration ensues.

Another annoying thing is that this, from what I can tell this, is a built-in feature of UEStudio, I can't understand why they don't bring this into UltraEdit as well.

Of course I did suggest this to IDM and they have added the suggestion to the database. But the more people ask the higher the chance it will be implemented natively. So it will work in column mode as well.
(If they can't/won't I suggested to introduce a "IfColMode" macro command or "InsertCol CharValue" so you can check if you are in column mode or insert text.

My 2 cents and fingers crossed it will become a native feature :-)
It is right that in macro environment there is currently (UE v23.20.0.28) no condition command to execute code depending on column mode on/off.

But in scripting environment there is the boolean property UltraEdit.columnMode which can be evaluated to use different code on having value true, i.e. column mode is enabled on executing the script.

Code: Select all
if (UltraEdit.columnMode == true)
{
   UltraEdit.messageBox("Column mode is enabled on script start.");
}
else
{
   UltraEdit.messageBox("Column mode is disabled on script start.");
}
Best regards from Austria
Even using scripts it remains at best a kludge and not 100% foolproof or without fault. The list of editors that support this natively is very long so I don't understand why UltraEdit doesn't have it while UEStudio seemingly does (I only read that in the feature list so don't know if works how I'd want it to work).

Edit: I dug up some scripts, this is how far I've gotten using scripts Surround / wrap selected text with quotes, brackets and others characters.
5 posts Page 1 of 1