Is there a standard keyboard shortcut to build the current project in Visual Studio? - visual-studio

I know that Ctrl + Shift + B launches a solution build, but I would like a shortcut that just builds the current project. Is a custom shortcut my only option?
Edit: Looks like a custom shortcut is my only option as Shift + F6 does not work for me.

Assigning the shortcut to "Build.BuildOnlyProject" command doesn't seem to work in VS2008.
Assign the shortcut to "Build.BuildSelection". If you have a solution with several projects and files open from the various projects, whatever file you are currently editing will define the project that will be built when you use the assigned shortcut for "Build.BuildSelection".
You'll know the keyboard shortcut is working when you click the Build menu option and you see the keyboard shortcut on the menu itself.
btw - a restart/reboot is not required when assigning keyboard shortcuts.

custom shortcut depending on what keybindings you are using.....if you look in your menu it will tell you if you have a keybinding.
The other thing I have got used to, because I make use of ViEmu, is use the menu shortcuts. Which are actually quite quick to do, and are independent of bindings.
So to build your project you go Alt + B, U

You can use the shortcuts already established in the main menu that are navigated with the Alt key:
At least for VS2013:
Alt + B, B -> Build Solution
Alt + B, R -> Rebuild Solution
Alt + B, U -> Build current project
Alt + B, E -> Rebuild current project
For some reason after installing Resharper I couldn't get a global shortcut to work (tried several times!!!), but as long as what you want to do is on the main menu, there is always an Alt + "Letter1", "Letter2" combination to trigger whatever action you'd like :-)

For C# development:
F6 or Shift+Ctrl+B - Builds all the projects in the solution.
Shift+F6 - Builds the selected project and its dependencies.

Visual Studio 2015/17
ALT + B + E
ALT + B = Open Build Menu
E = Rebuild Current Project

for C# development. Tools -> Options. Select Keyboard, select additional keyboard mapping scheme to "Visual C# 2005". This mapping has F6 as standard shortcut.

VS 2012 has Shift + F6 already mapped for this. I was surprised to learn this.

For Visual Studio 2017 community, you can use Alt+b then press u to build your current project.
Details: ALT Switch to the main menu -> choose b for build -> u choose the option of build your_project_name from the drop list.

In Visual Studio 2019 this has been set to Ctrl+b

In Visual Studio 2017 and 2019, Shift + F6 works for me.

As Happy Mittal said (Alt + B + J) open a drop window that select the project build, but then i had to press enter instead the last "B" (VS 2017).

In Visual Studio 2015, Alt + B, H will build your solution and publish it.

Sometimes I have to use Visual Studio in a language different than English and the navigation using Alt and a combination of keys is different. If there is someone in the same situation, I found out that is more convenient to create a keyboard shortcut to have consistency among languages. I followed the instructions from https://evanjpalmer.wordpress.com/2013/08/20/build-selection-short-cut-for-visual-studio/ to create the keyboard shortcut:
To set this up:
Tools -> Options -> Environment -> Keyboard (Spanish: Herramientas -> Opciones -> Entorno -> Teclado)
Put the cursor in “Press Keyboard Shortcut Keys” and shift CTRL+SHIFT+B
In Show Commands Containing, type: Build.BuildSelection (Spanish: Compilar.Compilarselección)
Select Build.BuildSelection from the drop down list and hit apply
Put the cursor in “Press Keyboard Shortcut Keys” and shift CTRL+ALT+SHIFT+B
In Show Commands Containing, type: Build.BuildSolution
Select Build.BuildSolutionfrom the drop down list and hit apply
???
PROFIT!

In the Visual Studio options window, under "Keyboard", look for the "Build.BuildOnlyProject" command and you can set whatever you want.

press (Alt + B + J + B) these key combinations to build only current selected project of the solution (VS 2010).
It selects "Build" option from toolbar (Alt + B key ) , then goto "project only" (J key ) and then "Build Only XXX" project (B key).

Related

In Mac how to switch between the projects' window in AndroidStudio?

My OS is Mac.
I have opened several projects in AndroidStudio, sometimes I wanted to switch between the projects to choose a project. Is there any keyboard shortcuts to do it just like "command/ctrl + tab" ?
Use Cmd + ` (Cmd + Backtick). It switches between all the projects that are open on Android Studio.
In Android studio command to switch between diffrent project windows (i.e. windows those are not minimised) is as following :
⌘` -> (i.e command + backtick) -> for next project window
⇧⌘`-> (i.e shift + command + backtick) for previous project window
You can add your preferable shortcuts in Android studio -> Preference -> Keymap
Sometimes it doesn't work because of conflicts with other shortcuts.
Go to the menu "Android Studio" -> "Preferences", choose "Keymap".
And, use the search field for quick access.
For example, I made Ctrl+Shift+` shortcut, which is easy to use with one hand.
I'm not familiar with the Mac version of Android Studio, but the standard key combo for switching between windows within an app on the Mac is cmd-` (cmd-backtick) unless the app maps that to something else.
For AS 3.5.3 and after, open Window menu and look for Next Project Window or Previous Project Window options. They have the shortcut combinations next to them.
Precisely:
Next Project ⌥ ⌘ `
Previous Project ⌥⇧ ⌘ `
On a MacBook Pro keyboard getting the backtick requires pressing Shift so stock shortcut doesn't work (Studio 3).
But you can remap it to use the 'tick' instead : ´
So it becomes ⌘ + ´ for next project
and ⌘ + shift + ´ for previous project (equivalent of ⌘ + `)
That is probably what the designer had in mind.
A forward tilted tick to indicate a forward navigation and the
backtick symbolizing "backwards".
See Android Studio -> Preferences -> Keymap -> Main Menu -> Window
⌘` is the default shortcut. But since I have Android Studio 3 installed it doesn't work anymore. I solved this by replacing it through ⌘^ which is the same key combination.
When I update android studio to version 4.2.1, I also can't switch project. When I swith to official keymap like "Eclipse (macOS)", I search "cmd+ Backtick". I find the name is "Active Next Window". So I switch to my keymap and search "Active Next Window" as the second screenshot. Then I set it to "cmd+ Backtick".
Backtick is the "'" key on keyboard.
Windows - Command + ` (Backtick)
Mac - Option + Command + ` (Backtick)
Command ⌘ + Backtick `
It's Worked for me.
To switch between projects:
command+option+`

Shortcut to rebuild solution in Visual Studio 2008

The shortcut to Build a solution in Visual Studio 2008 is Ctrl + Shift + B.
I would like to know the default shortcut to Rebuild the solution.
The command Build.RebuildSolution is not bound to any key combination in the standard profiles. However you can use the following trick to invoke it
Alt + B, R
This will navigate to the build menu via Alt + B and then R will select the Rebuild option
Another way is to do this:
Tools >> Options >> Environment >> Keyboard.
Locate the textbox decorated by the 'Show commands Containing' lable.
Type >> 'Build.Rebuild'
Select >> the rebuild type you want, you have two options to choose from.
Locate the textbox decorated by the 'Press shortcut Keys' lable.
Hit >> 'a key on your keyboard', i.e I used F6 for solution wide rebuild.
Click >> the assign button.
CLick >> O.K and to exit.
Finally load up a test project to test out the short cut.
In my installation, there is no default. I am configured for C#, it's possible other configurations will define this by default, but I don't think so. You can see if there is a key assigned by going to Tools -> Customize, clicking the Keyboard... button at the bottom and typing "Build.RebuildSolution" in the Show Commands Containing edit box. If there is a key assigned, it will show up at the bottom of the dialog.
There is no default shortcut to Rebuild Solution.
In addition to the ways mentioned in other answers you can perform the rebuild by
Create a Visual Studio Macro that rebuilds the solution and assign a keyboard shortcut to macro. The advantage of this approach is that you are no longer restricted by the commands provided in visual studio. You can create a custom operation like rebuild the solution, launch the application process and attach the visual studio debugger to the process. All this in a single keyboard shortcut!

How do you auto format code in Visual Studio?

I know Visual Studio can auto format to make my methods and loops indented properly, but I cannot find the setting.
To format a selection: Ctrl+K, Ctrl+F
To format a document: Ctrl+K, Ctrl+D
See the pre-defined keyboard shortcuts. (These two are Edit.FormatSelection and Edit.FormatDocument.)
Note for macOS
On macOS, use the CMD ⌘ key instead of Ctrl:
To format a selection: CMD ⌘+K, CMD ⌘+F
To format a document:
CMD ⌘+K, CMD ⌘+D
For Visual Studio 2010/2013/2015/2017/2019
Format Document (Ctrl+K,Ctrl+D), i.e. press&hold Ctrl, press&release K then tap D as it is a sequence
Format Selection (Ctrl+K,Ctrl+F)
Toolbar Edit -> Advanced (If you can't see Advanced, select a code file in solution explorer and try again)
Your shortcuts might display differently to mine as I am set up for C# coding but navigating via the toolbar will get you to your ones.
If it isn't working, look for errors in your code, like missing brackets which stop auto format from working
I have installed an extension named "Format document on Save" which formats the whole document every time you save it.
For installing it in Visual Studio 2015 or Visual Studio 2017, on Tools just click the "Extensions and Updates...":
And then just go to "Online" at the left panel and search for "Format document on save":
Go to menu Tools → Extensions & Updates and type "productivity" in search:
Install 'Productivity Power Tools 2015'
Restart Visual Studio.
Go to menu Tools → Options → Productivity Power Tools → Power Commands and check "Format document on save":
Note: In VS2022 we don't have power commands.
If anyone want to have "Format document on save" and "Remove and sort using on save" install Mads Kristensen extension for VS2022 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.CodeCleanupOnSave
After installing this extension it will automatically "Format document on save", "Remove and sort using on save" and "Apply file header preferences".
If we want to customize default settings click on "Configure Code Cleanup" menu item to add/remove any available fixers.
Visual Studio 2019 & 2022
Format Document, While you're holding down Ctrl button, first press K then D
Format Selection, While you're holding down Ctrl button, first press K then F
or just click Edit => Advanced => Format Document / Format Selection
Follow the steps below:
Go to menu Tools
Go to Options
Go to the Text Editor options
Click the language of your choice. I used C# as an example.
See the below image:
You can define new key bindings by going to Tools → Options → Environment → keyboard:
On mac : Shift + Option + F
On ubuntu : Ctrl + Shift + I
SinceVisual Studio 2022 17.1 there is a builtin Feature to run code formatting on save (see devblogs.microsoft), meaning there is no need to install extensions like Format document on Save.
In Visual Studio 2017, 2019, 2022
Format Document is Ctrl + E, D.
But...if you want to add the Format Document button to a tool bar do this:
Right click on tool bar.
Select "Customize.."
Select the "Commands" Tab.
Select the "Toolbar" radio button.
Select "Text Editor" from the pull down next to the radio button (or whatever tool bar you want the button on)
Now...
Click the Add Command button.
Categories: Edit
Commands: Document Format
Click OK
I used to use these combinations. I automated this process on Save of a document. You can try my extension Format Document on Save.
If you display the HTML Source Editing toolbar, there is a "Format the Whole Document" button as well.
The solution provided in accepted answer does not apply to Microsoft Visual Studio 2012.
In case of Visual Studio 2012, the shortcuts are:
For a highlighted block of code:
Ctrl + K, Ctrl + F
For the document-wide formatting:
Ctrl + K, Ctrl + D
In Visual Studio 2019 , "Code Cleanup" (RunDefaultCodeCleanup) is more advanced (taken from ReSharper):
Ctrl + K, Ctrl + E
Options dialog box: Text Editor → C# → Code Style → Formatting
Auto formatting settings in Visual Studio
Select the text you want to automatically indent.
Click menu Edit → Advanced → *Format Selection, or press Ctrl + K, Ctrl + F. Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.
Step (1): Ctrl + A
Step (2): Ctrl + K
Step (3): Ctrl + F
Under menu Tools → Options → Text Editor, then going to the Formatting → General section of whatever language you wish to format you will find General. Check all three formatting check-boxes.
Under menuTools → Options → Text Editor, then going to the TABS section of whatever language you wish to format you will find Indenting. Select Smart and it will activate automatic formatting whenever you use one of the closing elements ; ) } within that block.
There isn't any need for keystrokes.
You can add the buttons to your toolbar by clicking the little drop down arrow to the right of the last toolbar button, select "Add or Remove Buttons" and then click the buttons you want to add a tick to them. The button(s) you select will appear on your toolbar ...
Then you just select text and click the Increase Indent or Decrease Indent buttons. I tested this on Visual Studio 2013 only.
In newer versions, the shortcut for the document-wide formatting is: Shift + Alt + F
Right click:
It works in Visual Studio 2015, maybe earlier version.
The original question said "I cannot find the setting."
Simple answer is: Look at top menu, then
Edit --> Advanced --> Format Document
You will also see the currently assigned key strokes for that function. Nothing special to memorize. This really helps if you use multiple developer environments on different operating systems.
Select the data and the right click and you will find this option.
Format Document and Format Selection:
Just to further Starwfanatic and Ewan's answers, you can customise your IDE to add any button to any toolbar - so you can add the Format button (as the HTML Source Editing toolbar has) to any other toolbar (like Text Editing with all the other edit controls like increase/decrease indent).
Click the arrow to the right of the toolbar → Add or Remove Buttons → Customize... → Commands tab → button.
Document Format and Selection Format are both under the Edit group.
(Tested in Visual Studio 2010 and Visual Studio 2013)
Windows Shift + Alt + F
MacOS Shift + Option + F
Linux Ctrl + Shift + I
With the Continuous Formatting extension (commercial, developed by me), the code is formatted really automatically as you type.
Visual Studio Extension - CodeMaid is pretty fine.
In Visual Studio 2015 and 2017 for C# code.
Scroll to the end of the file
Remove the last "curly bracket", }
Wait until the line above it shows an error
Replace the "curly bracket", }
Fini. :)
If it's still not working then you can select your entire document, copy and paste and it will reformat.
So ...
Ctrl + A
Ctrl + C
Ctrl + V
This is the only thing that I have found that works in Visual Studio Community Edition on Mac.
It's Shift + Alt + F in Windows.
But you can always double check by doing following.
Go to menu View → Command Palette or press Ctrl + Shift + P
Search for Format Document
You can press that to Auto Format Code or its hot key, written in front of it.
You can also use the CodeMaid Extension.
You can get the extension from Visual Studio Market Place.
Here is the link to the extension. CodeMaid
If you can afford it (or if you're eligible for the 30-day free trial) JetBrains' ReSharper can reformat a whole project directory.
Just install → right-click a directory → select Cleanup Code from the context menu.

Is there a shortcut key to switch between split panes in visual studio/management studio?

When I have a file open in visual studio/sql server management studio and have it split in to two panes, I'd like to be able to switch between the panes without having to reach for the mouse. Does anyone know if a shortcut key exists for this?
F6 is your friend.
I think you can assign this by going to Tools -> Options -> Keyboard and searching for SplitPane. You should be able to assign shortcut keys for the following values:
Window.NextSplitPane
Window.PreviousSplitPane
CTRL+F6 will cycle through your files and across panes.
In SSMS: right-click toolbars, customize. Under categories, select Window, then under Commands select "Next Split Pane". Drag to toolbar. Right-click and change name to "Next Split P&ane". You can now use alt-a to change split pane.
On Microsoft SQL Server Management Studio (SSMS) 2012, I figured out that it is the combination of Ctrl+Shift+UpArrow(or DownArrow). :-)
This was not easy for me for some reason. This method finally worked (similar to Steve Dignan's answer above but I don't have enough rep to comment yet).
In VS 2012, Tools, Options, Environment, Keyboard.
"Apply the following additional keyboard scheme" set to "Visual C# 2005".
"Use new shortcut in" set to 'Global'.
Enter "splitpane" in "Show commands containing" to get only the 2 desired commands.
Select the first one and remove any shortcuts already assigned.
Click inside the "Press shortcut keys" box and use "Ctrl + Alt + Up Arrow" for prev and down arrow for next.
If either of those shortcut chords are currently used by something else, you may need to search on that command and remove it from there. Then come back to the split pane commands and Assign.
Don't forget to close VS before you open another instance of it.
For Visual Studio 2010 (maybe others as well) F6 will work to jump between split panes if Tools -> Options -> Keyboard does not use the Visual C# 2005 keyboard layout additionally (which was the case for me for I-don't-know-why reasons - maybe I said yes to an installer/first-start question a long time ago).
Of course you will no longer be able to build your project with F6 afterwards. ;-)
For Visual Studio 2012: Tools -> Options -> Keyboard -> search by Window.Split and add a new shortcut.

What is the shortcut to open a file within your solution in Visual Studio 2008?

What is the shortcut to open a file within your solution in Visual Studio 2008 (+ Resharper)?
Ctrl + T (ReSharper, Goto, type) will open a class file for you.
Looks like Ctrl + Shift + T opens files.
Depending on your keymap, Ctrl + Shift + N will open any file in the solution, or Ctrl + N will open any type.
If the standard toolbar is visible the following will open any file in the solution (resharper is not necessary).
Ctrl + D places you in the Find textbox. >of f will provide a dropdown with all files that start with f with path information after the filename to distinguish name collisions. Complete the filename, or arrow down to the correct one and hit enter to open it in the editor.
I attended a presentation recently where Kirk Jackson showed how to add aliases to the command window in Visual Studio. Bear with me, it gets better.
So it went like this:
Open Command Window and type
alias fo File.FileOpen
Now in your editor window hit Ctrl + / to put the focus into the Find box on the toolbar
If you use the prefix > this is command window (sneaky huh?) so type:
fo
and intellisense kicks in and shows you the names of the folders and files in the solution.
The alias is persistent between Visual Studio sessions.
Not exactly a keyboard shortcut but using this technique you can access any command in Visual Studio from the keyboard.
You should also check out Kirk's list of essential VS tips and tricks
It depends on the key mapping that you have set.
With default keymapping: Do Ctrl + T to open a type and Ctrl + Shift + T to open a file.
With IntelliJ like mapping : Do Ctrl + N to open a type and Ctrl + Shift + N to open a file.
Visit the following links for all your key mapping.
ReSharper 4 Default Keymap: Visual Studio scheme
http://www.jetbrains.com/resharper/docs/ReSharper40DefaultKeymap.pdf
ReSharper 4 Default Keymap: ReSharper 2.x / IDEA scheme
http://www.jetbrains.com/resharper/docs/ReSharper40DefaultKeymap2.pdf

Resources