Joe Webb

Musing and observations about SQL Server, other technogies, and sometimes just life in general
posts - 85, comments - 401, trackbacks - 0

My Links

News

This blog has moved!

Click here for the new location.

Follow me on Twitter
Add to Technorati Favorites

Search this Blog
 




Archives

Post Categories

About me

Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

One of the things I really like about teaching technical classes is getting to know and talk with students, learning of the challenges they face and how they've addressed them. Frequently, I can learn from their experiences, too. So, it works out well for both student and instructor.

In a custom Visual Studio/SQL Server class last week, I made a passing comment about Visual Studio being a very good text editor, but that it lacked one feature that I really like in other editors - block copy and paste. I lamented that the Visual Studio editor doesn't allow you to select a rectangular area of code and then copy and paste it elsewhere in the document. Other editors that I've used over the years - emacs, vim, Notepad++, UltraEdit - can do that. I would have thought that Microsoft would have put that in Visual Studio.

It turns out that they did. One of my students showed me an old Microsoft Word trick. You can depress the Alt key while using the left mouse button to select rectangular areas of code. Pressing the Alt key tells the editor not to select the entire line, but to follow the mouse pointer wherever it goes. Then you can use normal techniques to copy the text and paste it wherever you'd like.

blockcopy20071106

Why is this useful? Consider declaring a bunch of variables as show above. At a later point in your coding, you need to set the value of all of these variable. By copying the block you can quickly and easily paste only the relevant text (the variable names) into the procedure like so.

blockcopyb20071106

Pretty nifty! Thanks, Ellen, for the tip!

By the way, this technique works in the SQL Server Management Studio editor, too.

blockcopyc20071106

Cheers!

Joe

kick it on DotNetKicks.com

Print | posted on Tuesday, November 06, 2007 7:45 AM | Filed Under [ C# T-SQL Other Technologies SQL Server ]

Feedback

Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

very sweet!!
wasn't there a keyboard short cut in an old visual studio that would enable/disable that kind od selection?
11/6/2007 8:44 AM | Mladen
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

From the Visual Studio Help:
============================
To select a rectangle of text
Hold down the ALT key, press down on the left-click button of your mouse, and then drag the cursor over the text to select.

—or—

Hold down the SHIFT+ALT keys and press any Arrow key.
11/6/2007 7:18 PM | Casual reader
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

Hey - thanks for the documentation reference.

You know, now that I know that VS has the capability, it doesn't really surprise me that it is documented in help. But I, along with every other student in the class, was unaware that VS had that capability. That's why I thought I'd mentioned it here.

Cheers!
11/8/2007 8:10 AM | Joe Webb
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

That just changed my life. Thank you!
11/8/2007 10:09 AM | Jesse Gavin
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

That's right, I forgot about that.

That would have come in handy the other day.

Thanks for the reminder!
11/8/2007 12:41 PM | Roger Dickey
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

In VI: Ctrl-Q :)
11/8/2007 7:52 PM | Lucio
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

In VI: Ctrl-Q :)
11/8/2007 7:52 PM | Lucio
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

For the benefit of this blog's owner, and all those who strayed here from DotNetKicks and seem to stare in awe, Sara Ford of Microsoft has all sorts of Visual Studio tricks in her weblog:

http://blogs.msdn.com/saraford/


11/11/2007 5:42 AM | tokioBelle
Gravatar

# re: Copying and pasting rectangular blocks of code in Visual Studio and Management Studio

wooo hooooooo!!!!

No more emacs for me!!!!!!!!!!!!
5/13/2009 11:14 AM | Great!

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 4 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET