Thursday, September 08, 2005 2:35 PM bart

Visual Studio's ALT + mouse drag functionality

I'm using it for years in Word now and just discovered Visual Studio .NET 2003 supports it to: drag-and-drop while holding the ALT-key. What it does is a so-called "columnar text selection", i.e. selecting a block of text columnwise, not line-based. An example to clarify things. I was documenting a piece of code I'm writing with the following text:

/// GRAPHICAL       DATABASE                           LIMITED
/// REPRESENTATION  STRUCTURE                          QUERY RESULT
/// ==============  ==============================     =========================
/// 
/// Tree            ID     Name        Parent  Top     ID     Name        Parent
/// --------------  -----  ----------  ------  ---     -----  ----------  ------
/// Shop 1              1  Shop 1      (null)    1 -->     1  Shop 1      (null)
/// + Shop 1.1          2  Shop 1.1         1    1 -->     2  Shop 1.1         1
///   + Shop 1.1.1      3  Shop 1.1.1       2    1   +     3  Shop 1.1.1       2
///   + Shop 1.1.2      4  Shop 1.1.2       2    1   +     4  Shop 1.1.2       2
///   + Shop 1.1.3      5  Shop 1.1.3       2    1   +     5  Shop 1.1.3       2
/// + Shop 1.2          6  Shop 1.2         1    0 -->     6  Shop 1.2         1
///   + Shop 1.2.1      7  Shop 1.2.1       6    ?   -
///   + Shop 1.2.2      8  Shop 1.2.2       6    ?   -
/// Shop 2              9  Shop 2      (null)    1 -->     9  Shop 2      (null)
/// + Shop 2.1         10  Shop 2.1         9    0 -->    10  Shop 2.1         9
///   + Shop 2.1.1     11  Shop 2.1.1      10    ?   -
///   + Shop 2.1.2     12  Shop 2.1.2      10    ?   -
///   + Shop 2.1.3     13  Shop 2.1.3      10    ?   -
///   + Shop 2.1.4     14  Shop 2.1.4      10    ?   -
/// + Shop 2.2         15  Shop 2.2         9    1 -->    15  Shop 2.2         9
///   + Shop 2.2.1     16  Shop 2.2.1      15    1   +    16  Shop 2.2.1      15
///   + Shop 2.2.2     17  Shop 2.2.2      15    1   +    17  Shop 2.2.2      15
/// Shop 3             18  Shop 3      (null)    1 -->    18  Shop 3      (null)
/// + Shop 3.1         19  Shop 3.1        18    1 -->    19  Shop 3.1        18
///   + Shop 3.1.1     20  Shop 3.1.1      19    1   +    20  Shop 3.1.1      19
///   + Shop 3.1.2     21  Shop 3.1.2      19    1   +    21  Shop 3.1.2      19
/// + Shop 3.2         22  Shop 3.2        18    0 -->    22  Shop 3.2        18
///   + Shop 3.2.1     23  Shop 3.2.1      22    ?   -
///   + Shop 3.2.2     24  Shop 3.2.2      22    ?   -
///   + Shop 3.2.3     25  Shop 3.2.3      22    ?   -

Then I needed the same comment somewhere else, except for the last column (okay, maybe I should have written the comments in inverse order, so that I could add the last column after copying the existing text). Using ALT + drag mouse, you can select the last columns (indicated in bold over here):

/// GRAPHICAL       DATABASE                           LIMITED
/// REPRESENTATION  STRUCTURE                          QUERY RESULT
/// ==============  ==============================     =========================
/// 
/// Tree            ID     Name        Parent  Top     ID     Name        Parent
/// --------------  -----  ----------  ------  ---     -----  ----------  ------
/// Shop 1              1  Shop 1      (null)    1 -->     1  Shop 1      (null)
/// + Shop 1.1          2  Shop 1.1         1    1 -->     2  Shop 1.1         1
///   + Shop 1.1.1      3  Shop 1.1.1       2    1   +     3  Shop 1.1.1       2
///   + Shop 1.1.2      4  Shop 1.1.2       2    1   +     4  Shop 1.1.2       2
///   + Shop 1.1.3      5  Shop 1.1.3       2    1   +     5  Shop 1.1.3       2
/// + Shop 1.2          6  Shop 1.2         1    0 -->     6  Shop 1.2         1
///   + Shop 1.2.1      7  Shop 1.2.1       6    ?   -
///   + Shop 1.2.2      8  Shop 1.2.2       6    ?   -
/// Shop 2              9  Shop 2      (null)    1 -->     9  Shop 2      (null)
/// + Shop 2.1         10  Shop 2.1         9    0 -->    10  Shop 2.1         9
///   + Shop 2.1.1     11  Shop 2.1.1      10    ?   -
///   + Shop 2.1.2     12  Shop 2.1.2      10    ?   -
///   + Shop 2.1.3     13  Shop 2.1.3      10    ?   -
///   + Shop 2.1.4     14  Shop 2.1.4      10    ?   -
/// + Shop 2.2         15  Shop 2.2         9    1 -->    15  Shop 2.2         9
///   + Shop 2.2.1     16  Shop 2.2.1      15    1   +    16  Shop 2.2.1      15
///   + Shop 2.2.2     17  Shop 2.2.2      15    1   +    17  Shop 2.2.2      15
/// Shop 3             18  Shop 3      (null)    1 -->    18  Shop 3      (null)
/// + Shop 3.1         19  Shop 3.1        18    1 -->    19  Shop 3.1        18
///   + Shop 3.1.1     20  Shop 3.1.1      19    1   +    20  Shop 3.1.1      19
///   + Shop 3.1.2     21  Shop 3.1.2      19    1   +    21  Shop 3.1.2      19
/// + Shop 3.2         22  Shop 3.2        18    0 -->    22  Shop 3.2        18
///   + Shop 3.2.1     23  Shop 3.2.1      22    ?   -
///   + Shop 3.2.2     24  Shop 3.2.2      22    ?   -
///   + Shop 3.2.3     25  Shop 3.2.3      22    ?   -

and press delete to get rid of it. In Word, you can do the same (works - logically - best on non-proportional text fonts) e.g. to change the formatting of a column. I'm always surprised to hear that people don't know this Word trick, but as far as I can remember I got the trick from putting the "tip of the day" on in Word 6.0 (if the discussed feature was already in that version) or so a long time ago. Today was the first time I had a need for the same functionality in Visual Studio and I was so happy to see it's in there too :-).

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

No Comments