KnowDotNet NetRefactor

Shortcut Code Completion - CSharpCompleterPlus

Generate blocks of code with a few keystrokes

Default Code Completion is a time-saver by saving literally hundreds of keystrokes in a normal day of coding. But, Shortcode Code Completion is where the real power of CSharpCompleterPluscomes in.

Shortcut Code Completion provides a mechanism for creating and maintaining paramaterized code blocks or snippets. The real power comes not only in being able to create your own
parameterized snippets, but that you can invoke the snippets by simply one or two keystrokes, plus any optional parameters that your snippets require, if any. This type of snippet selection is much faster than the normal "right-mouse invoked searchable dialog". That traditional mechanism still has its place and is found in NetRefactor and even is used in intellisense, but the speed and ease of use of CSharpCompleterPlusShortcut code completion is hard to beat.

Numerous shortcuts have been built into the deliverable package with
CSharpCompleterPlus. A couple of these will be described below.

Example 1 - TryCatchFinally Block

If you type the following line of Shortcut code,

   tcf NullReferenceException ex


CSharpCompleterPluswill automatically replace the Shortcut with the following block of code.

   try
   {
     |
   }
   catch(NullReferenceException ex)
   {

   }
   finally
   {

   }

At the risk of mis-counting by a stroke or two, the shortcut line, including the Enter key following it, is 30 keystrokes. At best count, the amout of code generated is 63 charcters, or a saving of 33 keystrokes. A more extreme example is shown below. It is a simple Try...Finally shortcut. Typing the following two characters plus Enter,

   tf


Will generate the following block of code. This block is approximately 25 keystrokes, generated by three counting the Enter, which is a savings of 22 keystrokes. If you save 25 keystrokes, 10 times per hour, for 8 hours, that's 2,000 keystrokes. Do it for 5 days, and that's 10,000 keystrokes. This may sound like an exaggeration, but you can do the math, and the Shortcuts generate the code correctly everytime, and there are no typing errors, assuming you type the abbreviated shortcut properly.

   try
   {
     |
   {
   finally
   {

   }


One last example is the
switch block shortcut. If you type the following line of code,

   switch(s) 1 2

The following code block will be created for you.

   switch(s)
   {
   case 1:
     |
     break;
   case 2:

     break;
   default:

     break;
   }

Not only is there a great savings in keystrokes, assumming that you can always remember to put in the ":", break;, default;, etc., which the author can't always do, the cursor is placed, ready for typing the code for the first case:.

Shortcut Code Completion is limited only by the imagination of the user of
CSharpCompleterPlus, and your ability to be creative with Regular Expressions.

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing