Compartilhar via


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: VS2005Tip, VS2008Tip

Comments

  • Anonymous
    September 10, 2007
    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

  • Anonymous
    September 10, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/09/11/did-you-know-you-can-cut-and-paste-a-collapsed-block-of-code/

  • Anonymous
    September 10, 2007
    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.

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

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

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

  • Anonymous
    July 06, 2008
    The comment has been removed

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