Shortcut key to surround selected text with quotes

Shortcut key to surround selected text with quotes

1
NewbieNewbie
1

    Jun 03, 2016#1

    Is there a shortcut key to surround selected text with quotes?

    6,602548
    Grand MasterGrand Master
    6,602548

      Jun 03, 2016#2

      There is none by default, but it can be added by you with three 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 or newer or older, in ribbon mode or in toolbar/menu mode with contemporary menus or in toolbar/menu mode with traditional menus.

      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 two 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 creating 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 for UltraEdit for Windows ≥ v25.00 and UEStudio ≥ v18.00:

      Code: Select all

      InsertMode
      ColumnModeOff
      IfSel
      UltraEditReOn
      Find SelectText "^s"
      Replace "\"^s\""
      Else
      """"
      Key LEFT ARROW
      EndIf
      The same macro for UltraEdit < v25.00 and UEStudio < v18.00 without escaping with \ both " in replace string:

      Code: Select all

      InsertMode
      ColumnModeOff
      IfSel
      UltraEditReOn
      Find SelectText "^s"
      Replace ""^s""
      Else
      """"
      Key LEFT ARROW
      EndIf
      Or on using UltraEdit for Windows < v14.00 or UEStudio < 6.50 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();
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.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 UltraEdit for Windows < v24.00 and UEStudio < 17.00 only for text not containing a Unicode character. The clipboard method would be needed for Unicode text as used by the macro for these versions of UltraEdit/UEStudio.

      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 an UC/UE/UES for Windows user from Austria

      326
      Basic UserBasic User
      326

        Jul 15, 2016#3

        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 :-)

        6,602548
        Grand MasterGrand Master
        6,602548

          Jul 15, 2016#4

          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 (UltraEdit for Windows and UEStudio) respectively UltraEdit.activeDocument.columnMode (UltraEdit for Linux/Mac) 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

          var bColumnMode = false;
          if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
          else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
          
          if (bColumnMode)
          {
             UltraEdit.messageBox("Column mode is enabled on script start.");
          }
          else
          {
             UltraEdit.messageBox("Column mode is disabled on script start.");
          }
          
          Best regards from an UC/UE/UES for Windows user from Austria

          326
          Basic UserBasic User
          326

            Jul 17, 2016#5

            Even using scripts it remains at best a kludge and not 100% foolproof or without fault.

            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