SlickEdit Product Discussion > Did you know?

Copy surrounding statement

(1/1)

Dennis:
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: ---      if (autoUpdatePath != "") {
         _xmlcfg_add_attribute(handle, newNode, "AutoUpdateFrom", autoUpdatePath);
      }

--- End code ---

Somewhere else:


--- Code: ---      mkdirhier(autoUpdatePath);

--- End code ---

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: ---      if (autoUpdatePath != "") {
      }
      mkdirhier(autoUpdatePath);

--- End code ---

After hitting Cursor down in Dynamic Surround mode:


--- Code: ---      if (autoUpdatePath != "") {
          mkdirhier(autoUpdatePath);
      }

--- End code ---

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


--- Code: ---      if (autoUpdatePath != "") {
      }
      mkdirhier(autoUpdatePath);

--- End code ---

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: ---      if (autoUpdatePath != "") {
          mkdirhier(autoUpdatePath);
      }

--- End code ---

Navigation

[0] Message Index

Go to full version