Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

Did you know... you can cut and paste a collapsed block of code? - #034

Following yesterday's tip theme of code relocation, you can cut and paste a collapsed block of code, keeping all of the code inside intact.  Of course, this is exactly what you would expect, but I never thought about trying it. 

About to cut a selected collapsed block of code

With a block of code collapsed, as indicated to the right in the above illustration, select the block and cut or just cut the line via your favorite cut the line mechanism.  Now navigate to the desired location and paste.

Pasted code block

Note the code will be automatically expanded upon pasting.  You can quickly collapsed the text again by pressing Ctrl+M, Ctrl+M, but more on toggling outlining expansions in our next tip!

Technorati tags: ,
Posted: Tuesday, September 11, 2007 3:00 AM by saraford

Comments

Guy Burstein said:

Hi

It is also important to mention Ctrl+M+O and Ctrl+M+P that expands and collapses all the code blocks in the file.

In a later post, I would recommend talking about commenting and uncommenting of a selected block code using Ctrl+K+C and Ctrl+K+U. The great thing is that it also works in XML files.

Enjoy!

Guy Burstein

# September 11, 2007 6:11 AM

Rory Becker said:

Great tip. I just really wish the code didn't expand afterwards. This happens when dragging or cut pasting.

Typically the reason for moving code whilst it is collapsed is for organisational purposes. It's very rare that someone will do only a single operation when organising their code.

To have each and every operation followed by an automatic expansion is very annoying.

# September 11, 2007 7:03 AM

Jason Haley said:

# September 11, 2007 9:59 AM

John S. said:

Speaking of Ctrl-M, O/P...I wish there was a command for expanding/contracting just regions and not everything.

# September 11, 2007 8:38 PM

Sara Ford's WebLog said:

D'oh! I had this tip set to go out at 3pm PST instead of 3am PST. Apologies for the delay! Yesterday's

# September 12, 2007 12:49 PM

Visual Studio 2008 ワンポイント said:

この記事を 3:00 AM PST に公開するつもりだったのに、3:00 PM PST に設定していました。遅くなって申し訳ありません。 昨日のワンポイント では、折りたたまれたコード ブロックを切り取る方法をご紹介しました。では、コード

# July 7, 2008 4:00 AM

Visual Studio 2008 ワンポイント said:

コードの移動に関する 昨日のワンポイント に続いて、折りたたまれているコード ブロックをカット アンド ペーストする方法をご紹介します。内部のコードは一切変更されません。これは完全に予想どおりの動作ですが、私は試そうと思ったことがありませんでした。

# July 7, 2008 4:03 AM

Секреты Visual Studio said:

В продолжение вчерашнего совета о перетаскивании кода, вы можете копировать и вставлять свернутые блоки

# September 10, 2008 3:38 AM
New Comments to this post are disabled
Page view tracker