Visual studio or resharper shortcut to close currently selected file in IDE - visual-studio

Is there a shortcut in VS 2005 or resharper to close the current file. or "save and close" would be even better

Ctrl + F4
Save and close would
Ctrl + S followed with Ctrl + F4

Visual Studio 2015 + Resharper
The question is a bit old. Just wanted to update it with the current solution.
As you can see below, you can also completely customize your shortcuts:
just navigate to Tools > Options
on the left pane, go to Environment > Keyboard
now use the field Show commands containing to search for file.close
select File.Close on the list
click the field Press shortcuts keys
type your desired shortcut, for example, <Ctrl> + W
finally, click Assign
And you're good to go!

Ctrl+S, Ctrl+F4 will save and close the current file.

Tools -> Options -> Keyboard
Find "Windos.CloseDocumentWindow"
And for me, need to set "Use new shortcut in" to "text editor" to override old ctrl+w without delete

Related

Ctrl+K was pressed. Waiting for second key of chord

I'm using Visual Studio 2013 Ultimate and when I select a code to be comment I press Ctrl+K but it show me this once I pressed Ctrl+K was pressed. Waiting for second key of chord... any idea how to fix it?
There is a command Ctrl K+C to comment any line, and Ctrl K+U to uncomment.
You can see what the keyboard binding is under Edit > Advanced > Comment Selection (2010):
And 2013:
Additionally, you find keyboard bindings under Tools > Options > Environment > Keyboard. Here if you search for "Comment", you can find the Edit.CommentSelection (and Edit.UncommentSelection) which you can assign whichever shortcut you prefer.
You can look after and manage your shortcuts in Tools / Options, Environment / Keyboard.
You should see a dropdown menu where all shortcuts are listed.
There you can change your existing shortcuts or reset them to the default.
The default shortcut for me (Visual Studio 2015 Community Edition) to comment was Ctrl K + C and to uncomment Ctrl K + U.

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.

Can I hex edit a file in Visual Studio?

I want to edit a binary file, but I don't want to use another tool other than Visual Studio because it's a pain to switch back and forth.
Is there perhaps an add-in or some built in functionality that can do that in Visual Studio?
Menu File → Open → File
Select the file to be opened
On the open file dialog at the bottom there is a down arrow on the "Open" button
Click "Open With..."
Click "Binary Editor"
Click OK
Or for the keyboard geeks out there:
Ctrl + o
Ctrl + v (paste filename)
tab
tab
↓
w
b
Enter
In addition to Kevin's answer, with Visual Studio 2017 you need to have the Visual Studio C++ Core Features component installed.
Source
Another way to do it is to rename your file to .bin and drag it into VS editor
right click the file in Solution Explorer,
select 'Open With...'
select 'Binary Editor'
Let's enjoy the hex world :)

Resources