Author Topic: Copy surrounding statement  (Read 3176 times)

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
Copy surrounding statement
« on: November 09, 2021, 01:24:21 PM »
SlickEdit has the ability to copy just the outer lines of a block statement to the clipboard.  This feature is new in SlickEdit 2021.

Suppose you have an if statement like this, and you need the same logic in another spot:

Code: [Select]
      if (autoUpdatePath != "") {
         _xmlcfg_add_attribute(handle, newNode, "AutoUpdateFrom", autoUpdatePath);
      }

Somewhere else:

Code: [Select]
      mkdirhier(autoUpdatePath);

If you place your cursor on the "if" statement and hit Ctrl+C to copy (or whatever key you have for copy in your emulation),  you will get a dialog like the one attached below.  You can then select "Copy the surrounding statement" to copy just the if statement and it's closing brace to the clipboard.  When you paste it above the "mkdirheir" line, you can then use Dynamic Surround to enclose the statement in the if block.

Code: [Select]
      if (autoUpdatePath != "") {
      }
      mkdirhier(autoUpdatePath);

After hitting Cursor down in Dynamic Surround mode:

Code: [Select]
      if (autoUpdatePath != "") {
          mkdirhier(autoUpdatePath);
      }

Or, if you do not use Dynamic Surround, you can use SmartPaste to move the "mkdirheir" statement into the if block.

Code: [Select]
      if (autoUpdatePath != "") {
      }
      mkdirhier(autoUpdatePath);

Hit Ctrl+X to cut the mkdirheir statement.

Then move up within the if statement and hit Ctrl+V to paste.  SlickEdit will correct the indentation for you (SmartPaste).

Code: [Select]
      if (autoUpdatePath != "") {
          mkdirhier(autoUpdatePath);
      }
« Last Edit: November 09, 2021, 01:30:18 PM by Dennis »