39

Is there anyway to disable the rather annoying feature that Visual Studio (2008 in my case) has of copying the line (with text on it) the cursor is on when CTRL-C is pressed and no selection is made?

I know of the option to disable copying blank lines. But this is driving me crazy as well.

ETA: I'm not looking to customize the keyboard shortcut.

ETA-II: I am NOT looking for "Tools->Options->Text Editor->All Languages->Apply cut or copy to blank lines...".

Abin Manathoor Devasia
  • 1,945
  • 2
  • 21
  • 47
erlando
  • 6,736
  • 4
  • 24
  • 29
  • 3
    I'm voting your question up, I didn't know that feature existed, sounds quite useful to me! – Benjol Sep 30 '08 at 06:52
  • 2
    This is one of the all-time most useful editing features of Visual Studio. I not surprised the team overlooked the crazy desire to disable it. :o – Sam Harwell Mar 24 '10 at 16:58
  • 6
    "...the all-time most useful editing features of Visual Studio..." a desire for visual studio to be able to work the same way that everything else works is "crazy"? – thepaulpage Oct 04 '10 at 17:26
  • There was an option to disable this in Visual Studio 6! (and I think this was called "copy with selection" there) – darklon Mar 19 '12 at 18:08
  • 4
    One of VS's most annoying behaviors. Every other application applies cut/copy to the current selection. No selection, no cut/copy. In VS, I find myself cutting/copying a line that I meant to be pasting into when my fingers slip (and I move between keyboard layouts, so this is inevitable.) If the subsequent ctrl-z undid the overwrite of the content on my keyboard, I could deal. And while I'm at it: ctrl-l putting the deleted line onto the clipboard is inane...it's identical to ctrl-x with no selection. ctrl-l: delete line (without copying it) and ctrl-d: duplicate line below would suit me. – Carl G Dec 02 '12 at 23:16

8 Answers8

24

The real problem you probably experience is that you go to paste, with CTRL+V. And you accidentally type CTRL+C, and end up overwriting the stuff that's on your clipboard. You can't disable this as far as I know, however, the work around for this, is that you can press CTRL+SHIFT+V multiple times to go back up the stack of things you have copied in visual studio. Not only does this allow you to recover what you originally copied, but you'll also find that CTRL+SHIFT+V very useful in a lot of other situations.

Abin Manathoor Devasia
  • 1,945
  • 2
  • 21
  • 47
Kibbee
  • 65,369
  • 27
  • 142
  • 182
16

If you aren't willing to customize the keyboard settings, then Ctrl+C will always be Edit.Copy, which will copy the current line if nothing is selected. If you aren't willing to use the tools VS provides to customize the interface, then you can't do it.

However, the following works: Assign this macro to Ctrl+C:

Sub CopyOnlyIfSelection()
    Dim s As String = DTE.ActiveDocument.Selection.Text
    Dim n As Integer = Len(s)
    If n > 0 Then
        DTE.ActiveDocument.Selection.Copy()
    End If
End Sub
Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
David Walthall
  • 961
  • 6
  • 5
  • What a novel approach! I wish I'd thought of that 10 years ago when MS added this goofy 'feature'. Wish I could give you credit for answering... and in VB too! – mattmc3 Jul 10 '10 at 14:04
  • 1
    VS2012 does not support macros, so you would have to [make it an AddIn](http://stackoverflow.com/questions/12027485/alternative-to-macros-in-visual-studio-2012). And MS is not willing to honor a [request for an extra option](https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2049389-stop-processing-ctrl-c-on-empty-selections) – Yahoo Serious May 28 '13 at 11:20
  • [creating macros](https://blogs.msdn.microsoft.com/zainnab/2010/12/02/creating-and-using-a-macro/) and overriding the copy shortcut seems quite complicated... There should be an option for this – brita_ Aug 30 '17 at 15:29
2

There's an extension called CopyOnlySelection for visual studio 2019 and 2017:

https://marketplace.visualstudio.com/items?itemName=KiwiProductions.CopyOnlySelection

This won't solve it immediately, but will add another command called Edit.CopyOnlySelection, which you can bind to Ctrl+C (and remove Ctrl+C from the normal Edit.Copy).

user886079
  • 864
  • 2
  • 11
  • 18
1

I'm pretty sure the way to do it in 2008 is the same as the way in 2005... check out this tutorial on 'customizing keyboard shortcuts' (about 1/3 of the way down)

http://msdn.microsoft.com/en-us/library/bb245788(VS.80).aspx

devinmoore
  • 2,726
  • 3
  • 19
  • 14
  • Well.. I'm not looking to customize the shortcut. I'm looking to making it stop copying the line the cursor is on. This will allow me to map the shortcut to another combination of keys - but the annoyance will still be there.. – erlando Sep 20 '08 at 13:35
1

I don't believe it is possible to do this without some type of 3rd party clip board manager that would prevent you from overwriting the clipboard content with the empty string.

ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78
1

I've the free SlickEdit add-in installed, and its CommandSpy feature shows that Ctrl+C executes Edit.Copy whether you've got text highlighted or not. Therefore I guess the answer to your question is No.

However, I do remember this feature annoying the hell out of me when I first encountered it; now I rely on it and get annoyed when I try the same trick in other programs and nothing happens.

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
Charles Anderson
  • 19,321
  • 13
  • 57
  • 73
  • I agree, it's a very natural action once you expect it. It wouldn't be too difficult for other applications to adopt a similar way of working. – Jonathan Webb Oct 01 '08 at 13:23
  • So this, like ctrl+tab, is another example of how Visual Studio does things "special" (like special ed) and doesn't provide any way of reverting to the normal way... so annoying! – thepaulpage Sep 28 '10 at 21:15
  • I beseech programmers of the world not to propagate this behavior. The cost of losing my most recent cut/copy when I accidentally hit ctrl-x or ctrl-c instead of ctrl-v does not outweigh the benefit. I prefer more powerful selection keyboard shortcuts combined with the familiar cut/copy behavior (e.g., 'select line', 'copy'). Other good alternatives are alt-up/down for 'move line up/down' and 'duplicate current line below this one.' Although ctrl-shift-v helps, I am uncomfortable using it without a display of the current clipboard stack. – Carl G Dec 02 '12 at 23:16
0

I have the same problem, but I found a workaround of it. When I click one time on word in text editor, all occurrences of it are highlighted.

Then I think I will copy this word. But double-click will select text to copy only.

I copy then whole line instead wanted text.

Problem Is: Color of highlighted text parts are very similar to selected text.

I changed these colors to make it easy to distinguish between the situations.

Tools -> Options -> Environment -> Font and colors -> Selected Text

Tools -> Options -> Environment ->Font and colors -> Highlighted references

0

This is fixed in the latest preview of VS2022 (17.4.0 Preview 3.0)

It now has the option: 'Cut or Copy the current line without selection' and I can confirm that it works.

As for the original question, I don't think it will be fixed in VS2008 :-)

Nils
  • 59
  • 6