Tips and Tricks: Apply (or Don’t Apply) Cut or Copy commands to blank lines

Tips and Tricks: Apply (or Don’t Apply) Cut or Copy commands to blank lines

Rate This
  • Comments 16

As you may know, Visual Studio’s cut and copy commands are useful for more than just selected text.  If you invoke them when there is no selection, VS will cut or copy your entire line, which saves you the trouble of selecting the line before adding it to the clipboard.  Although a lot of developers find this helpful, we occasionally hear feedback that this feature becomes annoying when Visual Studio clears your clipboard if you accidentally hit Ctrl+X or Ctrl+C on a blank line with no selection.  Fortunately, there’s an option for that:

Apply Cut or Copy commands to blank lines when there is no selection

If you often find yourself copying blank lines to the clipboard and erasing the previous clipboard contents, try navigating to Tools->Options->Text Editor->[All Languages or your favorite language]->General and unchecking “Apply Cut or Copy commands to blank lines when there is no selection.”  You’ll still have the convenience of cutting or copying entire lines to the clipboard without the risk of unintentionally replacing your clipboard contents with white space.  And if you do inadvertently end up with a blank clipboard, the Clipboard Ring feature can often paste your previous text without requiring you to recopy it.

If you like the tips and tricks we sometimes post on this blog, you might also be interested in the Visual Studio Tips and Tricks blog, which is devoted to these little productivity boosters.  There’s even a Tip of the Day Start Page extension for the VS 2010 RC – check it out and let us know what you think!

Brittany Behrens
Program Manager, Visual Studio Editor Team

clip_image002I’m Brittany, a Program Manager on the Visual Studio Editor team.  Some of you may recognize me from Connect bugs or as the main voice of @VSEditor on Twitter, and I’m responsible for a variety of Editor features.  I love hearing from customers, so please let me know what you think!

Leave a Comment
  • Please add 7 and 1 and type the answer here:
  • Post
  • Is there any way to prevent Ctrl-L (line deletion) from getting put on the clipboard?

    I was hoping your option here would fix that, but it had no affect. I often cut a bunch of lines out of code to move them elsewhere, then hit Ctrl-L a few times to remove empty lines, then go to where I want to paste the cut code and it pastes in the empty line. Sometimes the clipboard ring is available to get back to my originally cut code, other times it is not. Quite annoying.

  • @Mark:

    You might try Ctrl+Shift+L (Edit.LineDelete) instead of Ctrl+L (Edit.LineCut).  It should give the behavior you want, i.e. just delete the current line instead of cutting it.

    - Brittany

  • VS 2008 doesn't scale at all to the extent of big projects. We have about 500 projects that logically can be united into about 50 solutions, but the dependencies between those solutions become tricky to manage, so we need some way to address this problem "for good". In other words, I am looking for an advise on how to use the MSBuild for extra large projects with lots and lots of legacy features, full of legacy stuff and lots of intricate dependencies, some of which are sircular. I realize that the proper solution will be re-architecting the system in such a way that there will be less problems. But it is out of scope. Anyway, I have to have your advise on what is the best way to organize a super-large scale projects.

  • Managing large sets of projects and solutions can be tricky. There is some guidance on some of the things you might try here:

    Of course, circular dependencies can be a real problem. The best solution is of course to remove them. When you can't, you may have to create artificial boundries to help manage the problem. This is a huge subject, and there are many ways that you can solve, or at least reduce this problem.

    From a developer perspective, you typically don't need 500 projects loaded at a single time. In fact, you might typically need less than ten at any given point in time. To load just the projects you need, open an empty solution and add the project you want to work with to the solution. This solution can be throw away. You don't need to save it or check it in to source control unless it is just convenient to do so. This reduces clutter, and allows you to work quickly while in the IDE.

    When it comes to build, you may want to setup a hierarchical system where the projects below a certain level can reference only projects higher in the tree. This helps enforce the dependencies visually in your directory structure. You can then use a traversal project (explained below) via MSBuild to build everything from some point in the tree down. When you build the tree, MSBuild will obey the P2P references and build things in the correct order. But, you may have to seperate out trees that need to be built separatley due to circular dependencies.

    A traversal project is basically an MSBuild file with an ItemGroup in it that describes a set of projects and/or other traversal projects at the next level down the tree. A simple target then takes these items and executes the MSBuild task on each one.

    The traversal project my look something like (let's name it dirs.proj):

    <Project DefaultTargets="Build" xmlns="">


       <ProjectFile Include="subfolder\Project1.csproj" />

       <ProjectFile Include="subfolder\dirs.proj" />


     <!--Import the targets-->

     <Import Project="Traversal.targets" />


    The target might look something like:

       <Target Name="Build">

         <MSBuild Projects="@(ProjectFile)" Targets="Build"/>


    Based on the above, you would stick this in a project file names Traversal.targets.

    Then, taking the dirs.proj file we showed, create files that reference the projects below it throughout the tree. Make sure that you have the appropriate P2P references in your project files. Them starting at the leaf nodes, walk up the tree using MSBuild from a Visual Studio Command Prompt to build each project (including the dirs.proj projects) all the way up the tree. Working in this manner will help you to determine where you have dependency errors or issues.

    Hope this helps...

    Chuck England

    Visual Studio Platform

    Program Manager - MSBuild

  • @Someone

    To Chuck's answer I'd also add that I agree that VS /should/ scale to an infinite number of projects. Internally it can do whatever is necessary to make this work, such as under the covers lazily loading and unloading. This is my vision and we will likely get part of the way there in the next version.

    BTW To save resources in a large solution you can multiselect some projects you don't need to work on, right click, choose Unload. Building projects that have project references to them should still work, but they won't take up VS resources until you reload them.

    Dan [MSFT]

  • Nice, but why is this a setting? Why isn't it enabled permanently (or at least by default)?

  • @Olaf:

    Changing defaults is a tricky decision because it almost always results in confusion or dissatisfaction from users who are accustomed to the old default.  In this case I tend to agree that changing this option to be off by default would make sense.  You could certainly argue that it should have been off all along, but given that it's not, we opted against changing a default because it's easy to uncheck the box once and never worry about it again.  Make sense?

    - Brittany

  • Yes and no. It's one more switch that needs to be flipped before you've got the optimal settings.

    It's easy when you know about it, but what if you don't?

    Increasing  the number of settings is not a good thing. ;)

  • Brittany,

    I've noticed in VS2010 that Select >  Right-click > Drag > Drop no longer brings up the "Copy Here/Move Here" menu.  I've been using that a lot in previous versions and now I miss it.  Is it hidden somewhere?


  • @Eric_S:

    You're right that right-click drag & drop does not work in VS 2010 (it's not hidden or under an option).  But there is no real loss of functionality. Each of the options on the VS 2008 context menu can be accomplished with the drag & drop feature as implemented for VS 2010 (all of these were also available in VS 2008 and earlier):

    - Move here: Select some text, then left-click and drag it to your desired location.

    - Copy here: Select some text, then hold Ctrl and left-click and drag it to your desired location.

    - Cancel: Select some text, start dragging, and then either press Escape or drag the text back to anywhere within the original selection. No text will be moved or copied.

    For VS 2010 RTM, you should still be able to use the left-click drag & drop feature to do everything you could with both left- and right-click drag & drop in VS 2008. Reinstating right-click drag & drop is already on our backlog and will be considered as we begin planning for the next version of Visual Studio.

    Thanks for using VS 2010 and posting your feedback!

    - Brittany

  • Hey Brittany.

    I use the clipboard ring a lot. But some times it gets filled with all sorts of stuff and I need to clear it. Is there a way to do so?



  • @Steffen:  The clipboard ring APIs unfortunately don't include the concept of clearing the clipboard ring.  Clipboard ring content does not persist between VS sessions, so restarting Visual Studio will clear it.  But there isn't a command for emptying or resetting the clipboard ring within a single instance of VS.

    Sorry I couldn't be more helpful,


  • The post might be 2 1/2 years o;ld, but it's still as useful as ever. This "feature" has been bugging me for a lifetime.

  • This function is not working anymore in VS2012. Even if you disable it in the options, Cut or Copy commands still applying to blank lines. Really annoying.

  • in VS 2013 why isn't there an option to disable copying/cutting the entire non blank line when nothing is selected? its extremely annoying. how is this feature even helpful? is it that hard to hit End, Shift+Home, Copy? on top of that you added the Ctrl+L shortcut which does the exact same thing for cut. why not make something like Ctrl+Shift+C copy the entire line regardless of whats selected? that makes much more sense to me.

    when you copy/cut with nothing selected in 99.9% of windows programs nothing happens. i'm not sure why you thought it was a good idea to change the default expected behavior of copy/cut without at least offering an option to change it back. i try to avoid using 3rd party programs as much as possible so i don't want to use some add-on just to disable copying/pasting empty lines. why not let the user customize as much as possible?

Page 1 of 2 (16 items) 12