Joe Webb

Musing and observations about SQL Server, other technogies, and sometimes just life in general
posts - 85, comments - 857, 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!
Gravatar

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

By the way, this technique works in the SQL Server Management Studio editor, too.
10/15/2010 12:49 AM | columbia jackets
Gravatar

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

By copying the block you can quickly and easily paste only the relevant text (the variable names) into the procedure like so.
10/15/2010 12:52 AM | snow boots for women
Gravatar

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

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.

furry boots | womens snow boots | columbia outlet | columbia sportswear jackets | the north face jackets | north face jacket | cheap mac makeup | discount makeup
10/19/2010 4:25 AM | fur boots
Gravatar

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

This super video converter for mac is developed by Emicsoft Studio, it is currently the best video converter running under Mac os x, comparied by isqunite, Visualhub and other Video Converter for Mac Free vide under "format" option choose the output video formats by your needs, such as to mp4 for ipod, iphone, zune, psp, creative zen, flv, app
10/26/2010 1:31 AM | hanly
Gravatar

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

Many TNX. One of my main reasons for retaining XP is so that I could use EMACs for block copy and paste. Now I have one less thing I have to keep XP around for.
6/25/2011 7:37 AM | electriac
Gravatar

# re: Delete a line

One other feature I wish I had that was present in most older text editors like NYedit was a single key command to "Delete A Line". Is there something like that in Vis2008 that I am missing?
6/25/2011 8:02 AM | electriac
Gravatar

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

Visual Studio is the program I use the most when editing the Indianapolis Jiu Jitsu website I work on. I have a fairly basic understanding of it and am learning more techniques every day. Copying and pasting these code blocks is a great time saver and is one technique I love! I also wish there was a single key command to delete an entire line of code. This would help speed up the website editing process for sure.
2/17/2012 6:47 PM | Ryan S.
Gravatar

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

Great!
Thanks for sharing this.
10/10/2012 9:05 AM | Nuno Monteiro
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET