I have somehow misconfigured fingers. This leads to a very annoying situation.
I select a block of text to copy;
I move the cursor the place where I want to paste the code;
I accidentally press Ctrl+C again instead of Ctrl+V;
My block of copied text is replaced by an empty block;
I have to go back and do it all over again. Grrrrr.
Is there any way to disable this behavior, that is to disable copy of empty blocks of text in Visual Studio 2005+?
It's not copying an empty block, it's copying the blank line. You can change this setting in Tools > Options > Text Editor > All Languages > 'Apply Cut or Copy Commands to blank lines when there is no selection'
Press CTRL+SHIFT+V twice.
I'm using Visual Studio 2008 (but I believe this answer applies to Visual Studio 2005).
Select Tools -> Options.
Navigate to the "Text Editor" node and expand it.
Expand "All Languages" (or whatever language you want to apply this to) and check the "Apply Cut or Copy commands to blank lines when there is no selection".
The option that saved my sanity is found in Tools - Options - Text Editor - All Languages - General. There's a checkbox Apply Cut or Copy commands to blank lines when there is no selection. Unchecking this allowed me to hit Ctrl+C all i want on a blank line without losing the content on my clipboard.
Source
Go to Tools > Options > Text Editor > All Languages > General
The option on that page is "Apply Cut or Copy commands to blank lines when there is no selection"
For some reason that option didn't work for me (VS2010)
The answer mentioned here where you assign Ctrl+C to the macro worked however Disabling single line copy in Visual Studio
Related
I usually use comma , to set the same variable type like the gif above.
But a problem is when I hit Enter after write second variable, the VS breaks the line automatically.
As a formal Atom user, it's a bit tedious because in Atom it doesn't break the line whatever the indent number is. (My current indent number is 2.)
I changed and tested it all of the options inTools > Options > Text Editor > Basic > Tabs, but none of these turn off the breaking line. Even disabling pretty listening won't work.
How do I turn off this feature?
Judging by the glimpse of Intellisense and the fact that Enter auto-formats, it looks like you're editing a JavaScript file.
To disable auto-formatting after hitting Enter, go to Tools > Options > Text Editor > JavaScript/TypeScript > Formatting > General and toggle Format completed line on Enter to unchecked:
The accepted answer doesn't work in Visual Studio 2019 with Visual Basic. These options on the image aren't even shown in the Options for Basic.
However, when the Pretty listing option is turned off, this behavior ceases.
Seriously, I don't know what to google. Here's the thing, I like this Java-like code writing:
if (condition == true) {
doSomeStuff();
}
But VisualStudio "helps" me with its own "style", which I don't like and I am unable to change (after rather big time of desperate checking all settings :/)
if (condition == true)
{
DoStuff();
}
I obviously want the "{" char to be in same line where condition is ...
I am using MS Visual Studio 2010 professional.
Go to Tools > Options > Text Editor > [Language, i.e.: C#] > Code Style > Formatting > New Lines
This is where you can set your new line options for braces.
See the image below for more clarification.
Tools -> Options ...
alt text http://img6.imageshack.us/img6/158/capturejo.png
Text Editor > C# > Formatting > New Lines > New line options for braces
Uncheck Place open brace on new line for control blocks.
Probably want to uncheck put else on newline as well.
This is for Visual Stuio 2008, so I'm not sure that it's exactly the same in VS 2010:
Go to the Tools menu and open Options. Make sure that the Show all settings checkbox is checked. Open the Text Editor node and then the node for the language you want to change the setting for. Open the Formatting node and select the New Lines node. Here you can change when new lines are added to the code.
After installing Visual Studio I go in there and uncheck every option in the New Lines section.
Worth knowing is that Steve Horn's (and others) answer works even for other languages as they seem to appear to not have the same settings-layout. I did the changes as described in his post and it worked for my C++ projects as well.
As I am copying something from within a method, and pasting it into a word document, the code I am copying is already indented. When I paste it I therefore end up with a load of white space next to each line.
I need to copy without this. In C# I can just unindent my code, hit copy, and then indent it back again using the buttons in the IDE. But Visual Basic automatically forces indentation so any attempts to change it don't work.
Visual Studio supports block selection. Press the alt key and drag the cursor to start block selection.
Visual Studio Select Block Text
This is a very useful feature, specially when pasting code here on SO. Visual Studio 2010 will even support multi-line editing using the box selection.
Unfortunately, it seems VB doesn't support the Edit.Advanced.Tabify/Untabify or Increase / Decrease Indent commands.
Here is what you can do:
Go to Tools -> Options -> Text Editor and uncheck "pretty listing (reformatting) of code"
Select the text block you wish to copy without indentation
Go to Edit -> Advanced and click "Delete Horizontal White Space" (or: Ctrl K, Ctrl )
Copy and paste your code in Word.
Turn the "pretty listing" option back on.
the "Delete Horizontal White Space" command will unindent the entire selected text so that there is no tab/whitespace to the left of any line (unlike Block Selection, as prorposed by João Angelo, which will unindent the selected block but keep any indentation within the block).
You may use the Visual Studio extension Copy for review. Besides some formatting, it removes unnecessary whitespace. It works for Visual Basic, among other languages.
Disclosure: I am the author of that extension. Please notify me, if I can improve it to your needs.
Is there any way to force Visual Studio to copy selected code to the clipboard as unformatted text?
When I am copy-pasting code into Word or more often Outlook I have to do it via Notepad to get rid of the formatting...there has to be an easier way!
This feature can be turned off by editor.copyWithSyntaxHighlighting.
Visual Studio does put unformatted text on the clipboard, but it also puts formatted text. (The clipboard supports multiple simultaneous formats, and the OS assumes that they're simply different representations of the same data, although there's no technical enforcement of that point.)
The application you're using to paste then chooses its preferred format. In Word, and maybe Outlook as well, there is a "Paste Special" command that allows you to choose which format you want to use.
My department uses PureText. Sits in the system tray; copy text, click-it - strips all formatting leaving the plain-vanilla text. I'm sure it's much like PlainTextClipboard.
"PureText is basically equivalent to
opening Notepad, doing a PASTE,
followed by a SELECT-ALL, and then a
COPY. The benefit of PureText is
performing all these actions with a
single Hot-Key and having the result
pasted into the current window
automatically."
The goad for this was flaky Lotus Notes; likes to crash when pasting HTML-marked-up-text that I innocently copied from a web-page....
If you press CTRL+Z after pasting, it will reverse to the non-formatting one, because the formatting actually counts as one step after the regular paste.
When I do it choosing the little pop-up menu option attached to the wee clipboard item "Match Destination Formatting" does the trick for me.
From this blog post I got these instructions for getting rid of the black background when copying & pasting out of VS with the 'Dark Theme' activated, but the html in it can be tweaked to alter the rest of the formatting as required (e.g. set all text to black).
If required, install Productivity Power Tools
Open Tools → Extensions and Updates
Select Online (Visual Studio Gallery) and search for Productivity Power Tools 2012/2013
Download and restart Visual Studio when prompted
Productivity Power Tools Settings
Open Tools → Options → Expand Productivity Power Tools
select HTML Copy
Change the BeforeCodeSnippet option to:
<style type="text/css">.identifier {color:black !important;}</style>
<pre style="{font-family}{font-size}{font-weight}{font-style}">
Change EmitSpanClass to: True
Check EmitSpanStyle is: True
You might find http://www.extrabit.com/plaintextclipboard/ to be a useful tool. Some applications have a paste option which strips formatting, but what you really need is a copy operation that strips formatting, which VS does not offer.
In Outlook 2007, I've changed my default paste to do text only.
Go to Editor Options | Advanced
Under the "Cut, copy, paste" heading choose Pasting from other programs: [Keep Text Only]
And if you still want to paste formatted (less often in my case), use paste special...
Search editor.copyWithSyntaxHighlighting in Settings and disable it. Whoever enabled it by default must be flogged.
This Microsoft Office site offers a workaround that involves writing a macro to replace ctrl+v functionality to paste plain text all the time, but that may not be what you want. You can alternatively remap an unused shortcut (ctrl+?) to provide you with this functionality so you don't have to keep enabling / disabling the macro.
For applications that do not have a "paste special" you could use an application like PureText
The Visual Studio Extension Copy for review may be handy for you. Actually, it does not do unformatted copying, but applies it's own simple text-based template.
It supports a "Stack Overflow" format, which just removes the leading whitespace, while keeping the indentation as much as possible, and introduces some sort of header.
Get it from the from the Visual Studio Gallery and try it out.
Disclosure: I am the author of that Extension. Please notfiy me, if I can improve it to your needs.
A trick when applies:
You don't want to install an extension
Your destination application doesn't have options such as "Paste Special"..
You can copy the code and paste it in VS Code search box (shows when you press Ctrl+F). Then copy it again from there.
Then you can paste unformatted text anywhere you want.
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...".
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.
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
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).
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
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.
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.
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
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 :-)