Disable Shift+Delete Cutting in Visual Studio - visual-studio

I type fast. Often times when programming I will select a line with Shift+End and then press the delete key, but I do this so quickly that my finger hasn't come off of the shift key. This results in replacing clipboard item with what was selected.
This is bad because many times I am deleting code before pasting some other code.
Apparently shift+del is an old school way of cutting.
I am aware of ctrl+shift+v for cycling through clipboard history in visual studio, but this is still terribly annoying.
Is there a way to disable this shortcut in visual studio or windows in general?

Good answer. Although I assume some people will still like to perform the delete operation.
To still perform the wipe of the entire line with SHIFT+DEL but don't add it to the clipboard:
remove (as explained above) the binding of SHIFT+DEL to the Edit.Cut command
AND
bind the SHIFT+DEL combination to the Edit.LineDelete command.

The keyboard shortcuts are pretty thoroughly customizable in Visual Studio.
Go to Tools > Options then in the left select Environment > Keyboard
Select the command, select the shortcut you want to remove, click "Remove" and click "OK"
If you wanted to circumvent this across Windows, you can use a one-line AutoHotkey script to convert Shift+Delete to just plain Delete:
+DELETE::SendInput,{DELETE}

There is an easier way.
The shortcut CTRL+SHIFT+L simply deletes the line you're on. Without having to select it first and without copying it to the clipboard.

This autohotkey script solve this globally:
+Delete::
KeyWait Shift
Send {Delete}
shift+insert is okay, but shift+delete is just plain EVIL
I actually often lost code entirely, while being utterly confused where'd it go! :-)

Related

Is there a key command to open suggestion menu (see image) in ReSharper

This has always bugged me and this morning I decided to try and find out if there is a key command to open the resharper suggestion menu and quickly up/down select the appropriate option. It's annoying to have to grab the mouse every time.
I checked the Resharper key commands list but couldn't spot anything that sounded like it would be it (although I found a few cool key commands I never knew about, particularly the encapsulate field command!)
Anyone know it if it exists?
Alt + Enter
This is unless you chose to keep the Visual Studio shortcuts instead of ReSharper ones.

Is there a shortcut to move the cursor as shown in the following figure?

I am using a notebook without a mouse.
After typing prop and pressing tab, Visual Studio will automatically give me a property template. Pressing tab will move the cursor between type and propertyname placeholders.
I want to move the cursor to a new line after completing the property template.
Is there a shortcut to do so?
Press the Enter key twice.
I tried to post this answer 3 times before I left the comment. It wouldn't let me, too short. That's why I'm typing this otherwise useless verbiage.
It's not specific to snippets, but you can press Ctrl+Shift+Enter to start a new line below where the cursor currently is.
To insert a new line above where the cursor currently is, use Ctrl+Enter.
Both of these work anywhere in the editor. Both of these are handy because they work no matter where you are horizontally on your current line.
Update: Productivity PowerTools for VS2010 (Woot! 2012 too) provides the keyboard shortcut Tools.AddEndTokenAtEnd. (Thanks Ben.)
For some reason, magically, my VS2010 does this with Shift-Enter (which I prefer from my experience with TextMate.) Looking at my keyboard bindings (Tools > Customize > Keyboard) I see that this shortcut is assigned to the command Tools.AddEndTokenAtTheEnd. So if that command appears in your list of commands, assigning a keyboard shortcut to it should work. I have Productivity Power Tools, PowerCommands for Visual Studio 2010, and ReSharper installed. But I can't find any setting from the first two that would be responsible, and, in my experience, all of ReSharper's commands contain its name, so I don't think it added the command. Ooo, and I just discovered that the reason it is named that is because the command also ensures there's a semicolon at the end of the initial line before moving the cursor down; just like the useful keyboard shortcut in Textmate.
I'm interested, but baffled by the 2x-Enter solution. When I press enter twice I get two line breaks followed by whatever code was after the cursor on the first line. Can anyone explain how that shortcut/key-combination works? Is it time-sensitive so that the two enters must be pressed in rapid succession? What if the user wants to quickly insert some lines above some code and hits Return multiple times!?

Is there a keyboard shortcut to quickly find and open a file in Visual Studio 2005/2008 like how they do it in TextMate?

Is there a keyboard shortcut to quickly find and open a file in Visual Studio 2005/2008 like how they do it in TextMate?
In textmate Command + T in Textmate brings up something that you can type a few key which would display all relevant files and allow you to quickly select one, Command + T back and forth also allows you to quickly alternate between 2 files most recently used. This is extremely helpful.
I am aware that there is a Ctrl + Alt + ↓ which shows a list of all open documents which is almost there but not quite.
You can hit Ctrl+D to go to the search box, then type >of filename (with autocomplete).
You can also do this and other commands in the command window or the immediate window.
Or, if you don't mind buying, ReSharper has Go to File which I highly recommend. It's Ctrl+Shift+N and it brings up a nice search dialog that supports wildcards and other shortcuts.
Sonic File Finder is a free VS plugin which is basically the same thing, and quite well-loved by most people who install it.
http://www.jens-schaller.de/sonictools/sonicfilefinder/index.htm
I think the best solution is the following
CTRL + , (comma) then type your file/class/method name
I've made an extension that works exactly like Textmate's "go to file" feature: https://github.com/maxt3r/VS-CmdT
If you go to the search box in visual studio and type ">open " and then start typing, autocomplete will come up for all the files in your solution. This is in 2008, not so sure about 2005.
Out of the box in Visual Studio, Ctrl + Tab will toggle between the two most recent files.
Ctrl+Shift+T in Resharper works just like you describe. It provides a text box in which you type the filename and it generates a live list from which you can pick from. Nice features include wildcarding (e.g. Customer*xaml) and matching on camel case filenames (e.g. SVD will match SingleValueDecomposition.cs). At my work, if people use one feature of Resharper, it will be Ctrl+Shift+T.
If you code in C++ rather than C#, then Visual Assist provides some functionality. And in my opinion, works better than Resharper.
Sara Ford has a blog post about this: Did you know... How to open a file in the solution without using either a tool window or a dialog?
All the previous responses are accurate and are mentioned in her post and the comments. In addition, another approach is to launch the command window using CTRL+ALT+A then typing in "of filename" or "open filename" in the same way mentioned for the search field.
#Adam Neal mentioned ReSharper. Another popular tool is CodeRush/Refactor! Pro and it also has a file navigation window that can be launched (and searched) via the CTRL+ALT+F shortcut.

Can Ctrl+Backspace be made to work in VS2008's Solution Explorer?

I'm working in an ASP.NET MVC Beta 1 project, and I've noticed that if I want to rename a file in the Solution Explorer pane, Ctrl+Backspace does not do what it should (delete the closest "word"), and I get a silly box character and annoyed.
I'm doing this rather a lot as I'm using jTemplates, so rather than train myself out of using this very useful key combination, is there a way to make this function as expected in VS2008?
Probably not. File a bug on connect.microsoft.com, and hope that they fix it in VS 2010.
I'm not sure if this completely works, but if you go to Tools -> Options: Environemt -> Keyboard, you can set up short cuts.
Type "Rename" in the Show commands containing textbox.
Search for "File.Rename"
Put your cursor in the "Press shortcut keys" textbox and press Ctrl+Backspace.
Press Assign and it should take over the shortcut combination.
Hope that works for you.

Disabling single line copy in Visual Studio

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 :-)

Resources