Turn Off Whole Line Copy in Visual Studio - visual-studio-2010

There is a setting in Visual Studio 2010 to turn off copy and cut commands when the cursor is on a blank line and there is no selection. However, when the cursor is not on a blank line and you press ctrl+C, it always copies the entire line to the clipboard. I find this very irritating because I always highlight something first, copy it, then place the cursor where I want to paste it and press ctrl+V. However, sometimes I miss the v and hit the c, which replaces the text on the clipboard with the text of the current line and I have to start all over...
Does anyone know how to turn off copying when there is no selection, regardless of whether the cursor is on a blank line or not?

There is the option in the settings:
Go to Tools - Options -> Text Editor -> ALl Languages -> Apply Cut or Copy commands to blank lines when there is no selection
Also if you accidentally copied something into clipboard you can use following shortcut:
Ctrl+Shift+V – cycle through the clipboard ring.
EDITED:
It seems there is no option to turn of it because by default Ctrl-C is assigned to Edit.Copy command, which copies the current line if nothing is selected. However you can assign following macro to Ctrl-C and it should fix the issue:
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

I know this is old question, but as Macros are no longer natively supported in newer versions of Visual Studio, I thought I'd shared my new extension (cause I couldn't find any existing extensions): https://marketplace.visualstudio.com/items?itemName=KiwiProductions.CopyOnlySelection

Related

How to prevent copying nothing to clipboard in VisualStudio2015?

This is a super annoying thing with Visual Studio 2015 where if I have a segment of code copied to my clip board and I got to paste it on an empty line but instead make the mistake of pressing Ctrl + C then it erases my copied code and attaches a blank line to the clipboard. Is there a way of preventing this? I'm assuming no but I figured I'd ask to make sure.
May be you are looking for this one-
Goto Tools > Options > Text Editor > All Languages > and uncheck 'Apply Cut or Copy Commands to blank lines when there is no selection' option like below-

Visual Studio 2015 - arbitrary cursor position on empty line

Initial note: I'm not getting any responses over on superuser to my question, so please allow me to ask this here:
I inherited a VS solution with a bunch of unorthodox settings. I'm not at liberty to wipe out all those settings and start over. So there is 1 setting I want to change back to VS default but cannot find it.
In a normal/default VS c# environment, when you click the mouse on a line of code that hasn't been written yet (empty, no spaces, no code, no tabs), the cursor automatically positions to the beginning of where the line of code should begin. If it's just inside a foreach, if, or etc, it will indent a bit from the left edge according to tab rules, etc.
But in the weird VS settings I have, wherever I click, the cursor positions at that exact spot. So if I click on col 20 of the next line, the cursor remains at col 20 rather than auto-repositioning to col 5 or wherever it should be. This is SO annoying because I can't always eyeball where the cursor should be and I end up clicking at the end of the previous line, then hitting ENTER, at which time it goes to the next line and positions the cursor at the right place.
How can I fix this?
It is controlled by the Enable virtual space option. See Visual Studio options - Text Editor - C#. By default it is off/unchecked.
I resolved this issue by applying Sergey's suggested change (Visual Studio options -> Text Editor -> C# -> Enable Virtual Space [check]), but also enabled (Options -> Text Editor -> C# -> Tabs -> Smart).

Visual Studio multiple copy and paste issue

I hold CTRL-Shift- and then press V multiple times to paste from a list of my previous few pastes. [not sure what the upper limit of this list is].
My problem is that whenever I remove a line with CTRL-Delete Visual Studio replaces my whole lists of pastes with the line which i removed with the CTRL-Delete.
Any ideas?
Another thing: how do I traverse back up the list of pastes. (pressing V each time goes down the list ... how do I get back up?)
I'm using VS 2012 if that makes a difference.
Thanks.
You can remove a line with Ctrl+Shift+L without copying it to clipboard
(I use Ctrl+L to remove a line and copy it to clipboard, so we might not have the same shortcut settings)
/Robert

Visual Studio - Is there a keyboard combination to select an entire line?

I already know about Ctrl + L to delete an entire line...is there one to just select an entire line (which I can then copy and paste somewhere else...)
You can also use Ctrl + X to cut an entire line. Similarly, you can use Ctrl + C to copy an entire line.
As long as you don't have anything selected, the command will work on the entire line.
Hit
Home
Shift + End
You can do it with Shift + DownArrow.
Yes there is. If you are in the begining of the line press Shift+ End.
If you are in the end of the line press Shift+ Home.
Hope that helps
I believe, if you don't have any selection and press Ctrl + C, it would copy the line.
Shift + End = Select between cursor and the end of the line
It's Home+Home, then Shift+Down for me.
Or you change that setting which makes Ctrl+C with no selection copy the line. But I hate that, so I always turn it off. (Thanks to Bala for providing the link to that setting!)
To cut a line, Ctrl+L works in my keyboard settings.
There's also Alt-Up and Alt-Down to move whole lines. It's two fewer keystrokes than using Ctrl-X, and unlike Ctrl-X, it also moves multiple whole lines at a time if your selection covers multiple lines even partially. It's also nice because the feedback is instantaneous, unlike Ctrl-X where you can never remember whether the pasted line will go above or below your cursor.
I saw this and thought I'd never use the feature. But once I got used to it I use it all the time. There's no easier way to move a block of code than using Shift-Up/Down to select the lines, press Alt-Up/Down a few times to move them, and then use Tab to adjust the indentation.
Of course it only works within the same file though.
Visual Studio macros are another way to do these types of operations if you can't find an existing command. A simple way to create one is:
Use the Record TemporaryMacro option (under Tools/Macros).
Select the line however you prefer (e.g., home, shift, end).
Click Stop Recording (under Tools/Macros).
Choose Save TemporaryMacro (under Tools/Macros).
Then choose Tools/Customize/Keyboard and assign a shortcut to the macro.
It's not specifically a keyboard shortcut, but a triple-click will select a whole line of code.
This works in some other areas of Windows as well. In Chrome, for example, double-click selects a word, but triple-click selects a paragraph.
(This works in Visual Studio 2013 on Windows 7. Not sure about other versions/platforms.)
I use Ctrl + Insert to copy entire line, and Shift + Insert to paste entire line.
Other answers require either using a mouse or hitting more than one combination.
So I've created a macro for those who want a VSCode-like Ctrl+L behaviour. It can select multiple lines.
To use it, install Visual Commander extension for macros: https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander
Then create a new command, select C# as a language and paste this code:
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
var ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
if (!ts.ActivePoint.AtStartOfLine)
ts.StartOfLine();
ts.LineDown(true, 1);
}
}
Now you can assign a desired shortcut in preferences:
Tested in VS 2022.
Triple-click to select the whole line. Then do what you want.
You can press Home + Shift + End to select the whole line as well.
If you want to copy the whole line then just press Ctrl + C. It will copy the whole line if nothing is selected.

Can you set Visual Studio's "smart indent" to not remove tabs in blank lines?

When Visual Studio (2005) has Options -> Text Editor -> C/C++ -> Tabs -> Indenting set to Smart it will automatically indent code blocks and line up squiggly brackets, {}, as expected. However, if you hit enter inside a code block, move the cursor to another line, and then move it back, the inserted tabs are gone and the cursor is positioned all the way to the left. Is there a way to set Visual Studio to keep these tabs?
As far as I know, the only way to do that is to enter something (anything) on that line, then delete it. Or hit space and you'll never see it there until you return to that line.
Once VS determines that you've edited a line of text, it won't automatically modify it for you (at least, not in that way that you've described).
This is an annoyance to myself as well. Anytime the code is reformatted the blank lines are de-tabbed.
You might look at this: http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7 it's not exactly a solution but a step in the right direction

Resources