Clipboard Tools – Smart Cut and Smart Copy
These CodeRush clipboard features allow you to take an identifier or a block of code, and put it into clipboard without selecting it in advance. Just place the editor text caret at the identifier or at the start or end of a code block and press the copy key (Ctrl+C or Ctrl+Insert) or the cut key (Ctrl+X or Shift+Delete). This makes it easy to use cut and copy operations to move, duplicate or delete contiguous blocks of code, like methods, properties, conditional statements, loops, try/catch/finally blocks, comments, etc without selecting it first.
If the text caret is at the start or end of a code block, the entire block will be copied or cut (depending on the key you pressed) into clipboard. CodeRush detects that there is no selection and it will create the most intelligent selection for you:
Before:
After:
Note that the block of code is selected including the leading and trailing white space. This is the optional behavior (see below). In case of a member or type declarations, the selection will include all support elements such as attributes, xml doc comments as well:
Before:
After:
Otherwise, if the caret is at the identifier (name or type) the only identifier is copied (or cut):
Once the identifier is on the clipboard, other CodeRush features, such as Code Templates become very useful. For example, if we copy the class name onto a clipboard, we can easily create a descendant for this class using the “c\” code template:
Note that if the selection exists and you press the cut or copy key, the default Visual Studio behavior is performed, i.e. the only selected text is being copied into clipboard as is. The same happens if the text caret is surrounded by white space – the current line will be placed on the clipboard, which is the default Visual Studio cut and copy behavior (optional, enabled by default).
You can disable or enable the Smart Cut and/or Smart Copy on the “Editor | Clipboard | Smart Cut(Copy)” option page in the Options Dialog:
There are two additional options available:
- Include surrounding white space in smart selections
If this option is turned on, a Smart Cut (Copy) selection includes the leading and trailing white space of an active block of code. Otherwise, it includes only the constructive parts of a code block.
- Include primitive literals in smart selections
This option affects the Smart Copy, Smart Cut and Paste Replace Word features when working with text strings. If the option is enabled, CodeRush copies (cuts) or replaces an entire string including quotes. Otherwise, it replaces only the word under the text caret inside of a text string expression.
—– Products: CodeRush Pro and CodeRush Xpress Versions: 10.2 and up VS IDEs: any Updated: Feb/02/2011 ID: C063