Quick pro tip - Open File in Sublime from Visual Studio
Tuesday, April 17, 2012 4:58:45 PM (GMT Daylight Time, UTC+01:00)
This is one of those really simple little gems that helps productivity ten-fold. Firstly, regardless of whether you're running a PC, Mac or Linux, if you've not already come across Sublime Text 2 you should go download it right now.
There are a ton of amazing features in Sublime (enough to warrant an talk by Dan Kendall no less), some of them are available in Visual Studio but none are quite as rich. Things like the multi-selection/multi-cursor feature are just awesome for quickly making the same changes in multiple places, not to mention the "select this word throughout the document" shortcut which has saved me hours already.
So what's my quick tip?
Rather than copying/pasting the path in the open dialog each time you want to edit the file, Dan pointed out to me the other day that you can easily wire it up as an external tool and then add a shortcut so you can open the current file in a flash.
Here's a step-by-step guide:
Optional Additional Enhancement
You can wire up a keyboard shortcut for extra speed, again under the "Tools" menu, go to "Options" and then "Keyboard" (under "Environment"):
Thanks Dan for the heads up on this one.
Collapse all Solution Explorer items in Visual Studio 2010
Saturday, February 27, 2010 12:22:48 PM (GMT Standard Time, UTC+00:00)
Ever wanted to be able to collapse all items within Visual Studio's solution window? This is a nifty little Visual Studio macro that I came across a few years ago and have been using successfully in Visual Studio 2005, Visual Studio 2008 and now in the Visual Studio 2010 RC.
I'll overview how to install it below in case you're unsure how to do it but I have this bound to the key combination Ctrl+Shift+` as ReSharper now uses my previous key combination of Ctrl+` for it's new bookmark explorer.
Anyway, here's the Visual Studio Solution Explorer item Collapse All macro:
' CollapseAll Module
' Simple macro that fully collapses all items in the
' Solution Explorer rather than just the top level node
' To make live easier, bind it to a keyboard setting such
' as Ctrl+Shift+` which by default has no bindings (Ctrl+` is
' now used by Resharper
' Tested and works with:
' Visual Studio 2005
' Visual Studio 2008
' Visual Studio 2010
' Originally from: http://bit.ly/bmRu3W
Public Module CollapseAll
' Get the the Solution Explorer tree
Dim solutionExplorer As UIHierarchy
solutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (solutionExplorer.UIHierarchyItems.Count = 0) Then
' Get the top node (the name of the solution)
Dim rootNode As UIHierarchyItem = solutionExplorer.UIHierarchyItems.Item(1)
rootNode.DTE.SuppressUI = True
' Collapse each project node
' Select the solution node, or else when you click
' on the solution window
' scrollbar, it will synchronize the open document
' with the tree and pop
' out the corresponding node which is probably not what you want.
rootNode.DTE.SuppressUI = False
Private Sub Collapse(ByVal item As UIHierarchyItem, ByRef solutionExplorer As UIHierarchy)
For Each innerItem As UIHierarchyItem In item.UIHierarchyItems
If innerItem.UIHierarchyItems.Count > 0 Then
' Re-cursive call
If innerItem.UIHierarchyItems.Expanded Then
innerItem.UIHierarchyItems.Expanded = False
If innerItem.UIHierarchyItems.Expanded = True Then
' Bug in VS 2005
In case you've never installed a Visual Studio macro before, here's a couple of instructions:
- In Visual Studio, press Alt+F11 to load up the Visual Studio Macro editor (or View > Other Windows > Macro Explorer > Double Click on "Module1" in "My Macros")
- Either create a new module of it it's not in use, you can edit Module1 and past in the code above
- Save and close the Visual Studio Macro editor
- You should be back in Visual Studio so click "Tools > Options > Environment > Keyboard"
- In the "Show commands containing" text box, enter "CollapseTree" and the macro you just created should be shown.
- Make sure "Global" is selected in the "Use new shortcut in:" drop down list
- Press Ctrl+Shift+` in the "Press shortcut keys:" text box
- Click Assign
- Click OK
You're done :)
Update via Graeme: Make sure your module name (in the above it's Module1) is the same as your file name otherwise Step 5 minght not work.
Visual Studio Tip of the day: Open files/folders in Windows Explorer
Monday, March 02, 2009 11:09:25 AM (GMT Standard Time, UTC+00:00)
A little irritation/time consuming process when you're working with multiple projects on multiple drives/SVN repos/directories is to open the current file's location within Windows Explorer. If you weren't already aware, you can do this from most projects/files by right clicking on the project in the solution browser:
Problem for me (and my mate Chris) is that not only is it just for the Project Item but more importantly it means using the mouse -which is something I'm trying to avoid as much as possible. Then I stumbled across a couple of posts which suggested opening Windows Explorer with Visual Studio's External Tools dialog.
They're both great ideas but you still need to use the mouse so I thought I'd take the final step and wire up some keyboard shortcuts. I'll recap the process here as I've added/grouped a few of their settings.
Creating the "External Tools"
There's a little productivity tip here for setting the folder in question the root of Windows Explorer, this encourages you to focus on just the work in question (though it can be a little irritating sometimes so I may "undo" this change later.
Custom #1: Open the current solution item in Windows Explorer
Title: Windows Explorer - Item
Custom #2: Open the current Visual Studio project in Windows Explorer
Title: Windows Explorer - Project Directory
Custom #3: Open the current Visual Studio solution in Windows Explorer
We've got a number of projects that have useful files/folders stored in the same folder as the solution file so this one's useful to get quick access to them, I think I'll use this one a lot when dealing with SVN.
Title: Windows Explorer - Solution Directory
Custom #4: Open the current solution's binary (bin) directory in Windows Explorer
Useful when you want to get access to the dll i.e. to copy to another folder/upload just the dll to a website.
Title: Windows Explorer - Binary Directory
Custom #5: Open the current solution's target build directory in Windows Explorer
This is useful when you have a project that builds to another directory (i.e. a common DLL directory, I'm not sure how many people do this but I've got a couple of projects that do this so I thought I'd share it).
Title: Windows Explorer - Target Directory
In all instances you can leave the Initial Directory field empty.
Note: On a couple of the directory related commands I've set the "/root" argument, this is a useful little productivity tip I learn a while ago to stop you navigating away from your work. Irritatingly I've not found a way of using the /select and /root commands together. It would also be nice to say "Open the bin folder and set the root to the project folder" but again I've not found a way.
If you're interested in the arguments I'm using there, check out the Microsoft Support article about How To Customize the Windows Explorer Views in Windows XP (these also work in Vista). Alternatively you can read more about the Visual Studio macros for build commands here (some of which are global I believe). I'm interested to see the use of $(TargetDir) as although it'll be useful for non-web projects, however using Web Deployment Projects might make it irrelevant for you.
You should now have 5 new items in your Tools' toolbar:
Wire up the keyboard shortcuts
As mentioned earlier, I want keyboard shortcuts but if you want toolbar icons, you should checkout the end of this post.
Open up the Keyboard settings within the Visual Studio Option dialog (Tools -> Options -> Environment -> Keyboard) -you may need to select the "Show all settings" checkbox in the bottom left of the Options dialog to see the Keyboard option.
In the Show commands containing field enter "Tools.ExternalCommand" to list the set of commands, irritatingly it just labels each command as "Tools.ExternalCommand#" for each command so this bit will require a little thinking on your behalf. My commands are #2-6 (#1 is the Dotfuscator Community Edition command).
I would then wire up the following shortcuts (I've set them up Globally for convenience):
Tools.ExternalCommand2 (Current Item): Ctrl+E, I
Tools.ExternalCommand3 (Current Project): Ctrl+E, P
Tools.ExternalCommand4 (Current Solution): Ctrl+E, S
Tools.ExternalCommand5 (Bin dir): Ctrl+E, B
Tools.ExternalCommand6 (Target dir): Ctrl+E, T
To enter these shortcuts simply press the first combination (in this case Ctrl+E), then press the second key (I -item, P -project, S -solution, B -binary, T -target). I found that a couple of these were already wired up to ReSharper and Pex which is a pain but I don't tend to use those particular shortcuts so I just overrode them
Now you should be able to press Ctrl+E followed by I and get your current item in Explorer.
It'd be nice if I could get it to use a single instance of Explorer and just refocus the items (on another key combo as that's not always the desired action). Update:
After using it a little, I've noticed that in my projects, I had the Bin/TargetDir the wrong way around (now corrected).