Visual Studio shortcut for "quick fix" - visual-studio

Does Visual Studio 2010 have a shortcut for quick fix?
I'm tired of grabbing the mouse, hovering over this red line, waiting for the little clipboard icon to appear, clicking on the first menu item. It would be so much fast to just open that dialog with some keys and confirming the first (i.e. selected) item.

The feature is called the "Smart Tag".
Default Keyboard Shortcut Schemes (ReSharper documentation)
Stack Overflow question How does one set Visual Studio 2010 keyboard shortcuts comfortably, especially when using ReSharper?
Stack Overflow question Visual Studio keyboard shortcut to automatically add the needed 'using' statement
They can usually be invoked via the keyboard using either:
Ctrl+. (on a standard QWERTY keyboard)
Alt+Shift+F10 (if you've not got Function Lock enabled)

If your cursor is on the item that is underlined, you can use Ctrl + . to pop up the intellisence/suggestion context menu.

Alt + Shift + F10 does the trick.
Via #Rohit from Visual Studio keyboard shortcut to automatically add the needed using statement

If you want to edit the shortcut of quick fix you can do the following:
Open Tools->Options->Keyboard and in the Show commands containing field enter EditorContextMenus.CodeWindow.QuickActionsForPosition and replace the old shortcut with the new one.

Related

Is it possible to search for keyboard shortcuts by a keybind (Visual Studio 2017)

I want to find all shortcuts that are using a specific keybinding in an easy and reliable way.
In Visual Studio the only reliable way I've found so far is by changing a shortcut's keybinding and get list of shortcuts using the same keybinding. I think it's too roundabout and I'm looking for a way similar to VS Code.
In VS Code in the Keyboard Shortcuts tab you can search by a keybinding (by writing "Ctrl + R" for example) and you will get all shortcuts using that keybinding.
Is there a similar way to do this in Visual Studio?
If you open Visual Studio keyboard options and Press shortcut keys in the corresponding box, in the Shortcut currently used by list you will see all commands for this shortcut:

Visual Studio Keyboard Shortcut of quick watch (shift + F9) Not Working

My quick watch (shift + F9) shortcut suddenly is not working.
But its alternate keyboard chord Control + Alt + Q works fine.
And all other shortcut seems working fine. But quick watch is the only one that I currently found.
I have tried other shortcut with Shift or with F9 , no problem.
I am also using Resharper, is that affecting VS Shift F9?
If you have Snag-It installed on your machine, its global shortcuts may override application specific shortcuts in Visual Studio (or other apps).
See #nuri's answer here: Visual Studio 2010 QuickWatch window not visible for instructions and screen-shots to change the Snag-It settings.
In the meantime, just go into the Snag-It preferences, the HotKeys tab, and set the "Video capture start/pause/resume" hot key to something other than [Shift]-[F9]. For myself, I only use "Global capture", so I set everything else to "None".
You can try the following:
In TOOLS --> Options | Keyboard, make sure the right mapping scheme is selected (Visual C# 2005 for me) and click Reset and finally, Ok

Visual Studio: Shortcut to close window not working

I changed the shortcut to close a window to Ctrl+W and to close all windows to Ctrl+Shift+W. Close all windows works fine, but Ctrl+W selects the word currently under the cursor but does not close the window.
When I right-click a tab it say Ctrl+W is the shortcut to close it (And also Ctrl+S to save and Ctrl+Shift+W to close all). Why is only the close window shortcut not working?
In Visual Studio (VS 2015 in my case but it's similar down to VS 2010 at least) keyboard shortcuts may have a different meaning depending on the context in which they are executed.
Click Tools / Options / Environment / Keyboard to look up or define shortcuts (you already did that probably). What I called "context" is selected in the combobox labelled "Use new shortcut in:". Most likely you defined the shortcut in "Global" but you want it to work in "Text Editor". In the latter Ctrl+W selects the current word.
Redefine Ctrl+W for "Text Editor" and you should be fine.
I am using Visual Studio 2017 & Visual Studio 2019 and tried the answer from #TobiMcNamobi but it didn't work for me. After few such tries I got it work with below steps.
You should add it as Global shourtcut otherwise it will not work for Designer views.
Add CTRL+W as a Global shortcut for Window.CloseDocumentWindow
Remove the CTRL+W shortcut for Edit.SelectCurrentWord
In Visual Studio 2019 it is Ctrl-F4 by default to CloseDocumentWindow. The action is Window.CloseDocumentWindow. I know this is old but the accepted answer has you change the short-cut key instead. I would rather use the default option.
Tools -> Options -> Environment -> Keyboard
If you're ever unsure go to the path above and you will see the image above then you can click inside the box "Press shortcut key" at the bottom of the form and type the short cut key you're interested in and it will tell you if it is used and what it is currently used for.
You can also reference the docs
https://learn.microsoft.com/en-us/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio?view=vs-2019
2021: For Visual Studio 2019:
See: https://gist.github.com/jpoehls/2030795#gistcomment-2335647
In my case, I had to existing assignments that I had to remove. Thereafter, I could use the hotkey.
In my case, the tabs were not closing because I am using Vim extension. I had to add the following lines to Vim settings:
"vim.handleKeys": {
"<C-w>": false
}
Just press Ctrl + , or Command + , for Mac users, search for Vim and go into Edit in settings.json as the following picture shows:
Screenshot
For Visual Studio 2022, make sure you also remove Ctrl+W from selectCurrentWord command.
In my VS Pro 2019, on Tools / Options / Environment / Keyboard, the first line offers using a premade keyboard mapping scheme, with a drop-down option for VSCode keyborad mapping theme.
I picked it and it seems to have adopted the keyboard shortcuts I was used to from working on VSCode, Ctrl+W included.
For those using linux with VSCode v1.56.2,
File --> Preferences --> Keyboard Shortcuts.
Search for View:Close Editor and as mentioned above, remove any keybinding that has the keybinding you want.

What's the equivalent for eclipse's ALT+UP/DOWN (move line) in Visual Studio?

In Eclipse, selecting a line and pressing Alt + ↑/↓ will move the line up and down, a quick way to avoid copy&paste.
Is there an equivalent in Visual Studio?
In Visual Studio 2013 and later, this functionality is built in. ALT + UP/DOWN will move a line up or down.
If you need this functionality in VS2012 (works with VS2010 too), take a look at the MoveLine Visual Studio Extension or the Productivity Power Tools suite.
ReSharper's Ctrl + Shift + Alt + ↑/↓/←/→ is even more powerful - when on the beginning of the line, it will move the entire line, but can also be used to move entire methods, change the order of parameters, etc.
For me in Visual Studio 2019 it comes default closed.
For open it:
Tools -> Options -> Keyboard then select Edit.MoveSelectedLinesUp, click "Press shortcut keys" input and press Alt + Up (or whatever you want for it). And the other one is Edit.MoveSelectedLinesDown, click "Press shortcut keys" input and press Alt + Down (or whatever you want for it).
This is now working out of the box with Visual Studio 2013, same way as in Eclipse.
For Visual Studio 2013:
Tools -> Options -> Keyboard then select Edit.MoveSelectedLinesDown, click "Press shortcut keys" input and press Alt + Down. You also have to select the scope of the shortcut to be within "Text Editor".
In Visual Studio 2013 and later, you can move lines up and down using Alt + ↑ / Alt + ↓. Unfortunately this will not adjust the indentation if you move between blocks, as of today only ReSharper (and all other IDE's by Jetbrains including Rider) can help you with that.
To move entire blocks of code around you can move the cursor to its head and press Ctrl + m twice fast to collapse it, and then use the command above to move it around.
Here is a neat reference to all default keyboard shortcuts in different versions of Visual Studio.
With the VSCommands extension, you have exactly that keyboard shortcut. And, by the way, a Stack OVerflow notification toolbar :)

Shortcut for "Find Result 1" in Visual Studio?

Shortcut for "Find Result 1" in Visual Studio?
Hotkeys for Visual Studio 2010 - Alt + vn1
Hotkeys for Visual Studio 2015 - Alt + vnnEnter1
Hotkeys for Visual Studio 2017 - Alt + vnnnEnter1
If you don't feel like customizing your own shortcuts, or you use different environments where you can't always rely on your customization being present, you can always go the old school route of just navigating the menus via hotkeys.
For instance, in Visual Studio 2010, you can just type Alt + vn1.
Typing Alt + v opens up the "View" menu.
Typing n opens up the "Find Results" menu item in the View menu.
Typing 1 selects the "Find Results 1" menu item, thereby opening and setting focus to the "Find Results 1" window.
Likewise, Alt + vn2 opens up the "Find Results 2" window.
If you do this enough, it's like any other keyboard shortcut, and becomes second nature.
ProTip
You can discover the hotkey shortcut to any menu item you need by just hitting Alt, and looking at the letters that are underlined in the menus. This applies to pretty much any windows program you will ever use.
There's no predefined shortcut for that (at least in VS 2005) but just select Customize... from the Options menu, press the Keyboard... button and then create a suitable shortcut for View.FindResults1.
In Visual Studio Professional 2013 (not sure about the other version) the function key "F8" will take you to the next result in the Find Results window, and "Shift-F8" will take you in the reverse direction (i.e. find previous result).
You can assign keyboard shortcuts as you please through Tools > Customize > keyboard.
In the show commands containing textbox type View.FindResults1.
In the Press shortcut keys textbox type in the shortcuts you want to add and then press the Assign button.

Resources