Visual Studio's most useful (and underused) tips
There was a cool comment in my last blog post (one of many, as always, the comments > the content).
Btw, "until I realized that the Solution Explorer tree nodes are searchable." This one is a saver!
The commenter, Sam, noticed a throwaway bit in the middle of the post where I noted that the Solution Explorer was text-searchable. There's a lot of little tricks like this in Visual Studio that even the most seasoned developers sometimes miss. This phenomenon isn't limited to Visual Studio, of course. It's all software! Folks find non-obvious UX all the time in Windows, OSX, iPhone, everyday. If UX were easy then everything would be intuitive but it's not so it ain't. ;)
There's an old joke about Microsoft Office, which is known for having a zillion features.
"Most of the exciting new Office features you discover have always been in Office." - Me and Everyone Else
Here's some exceedingly useful stuff in Visual Studio (It's free to download and use, BTW) that folks often miss.
Search Solution Explorer with Ctrl+;
You can just click the text box above the Solution Explorer to search all the the nodes - visible or hidden. Or, press "Ctrl + ;"
Even stuff that's DEEP in the beast. The resulting view is filtered and will remain that way until you clear the search.
Quick Launch - Ctrl+Q
If there is one feature that no one uses and everyone should use, it's Quick Launch. Someone told me the internal telemetry numbers show that usage of Quick Launch in the single digits or lower.
Do you know that you (we) are constantly digging around in the menus for stuff? Most of you use the mouse and go Tools...Options...and stare.
Just press Ctrl+Q and type. Need to change the Font Size?
Want to Compare Files? Did you know VS had that?
What about finding a NuGet package faster than using the NuGet Dialog?
Promise me you'll Ctrl+Q for a few days and see if you can make it a habit. You'll thank yourself.
Map Mode for the Scroll Bar
I love showing people features that totally surprise them. Like "I had NO IDEA that was there" type features. Try "map mode" in the Quick Launch and turn it on...then check out your scroll bar in a large file.
Your scrollbar will turn into a thumbnail that you can hover over and use to navigate your file!
Most folks manage their tabs like this.
- Open Tab
- Declare Tab Bankruptcy
- Close All Tabs
- Goto 0
But you DO have both "pinned tabs" and "preview tabs" available.
If you pin useful tabs, just like in your browser those tabs will stay to the left and stay open. You can not just "close all" and "close all but this" on a right click, but you can also "close all but pinned."
Additionally, you don't always have to double-click in the Solution Explorer to see what's in a file. That just creates a new tab that you're likely going to close anyway. Try just single clicking, or better yet, use your keyboard. You'll get a preview tab on the far right side. You'll never have more than one and preview tabs won't litter your tab list...unless you promote them.
Navigate To - Ctrl+, (Control+Comma)
Absolutely high on the list of useful things is Ctrl+, for NavigateTo. Why click around with your mouse to open a file or find a specific member or function? Press Ctrl+, and start typing. It searches files, members, type...everything. And you can navigate around with your keyboard before you hit enter.
There's basically no reason to poke around in the Solution Explorer if you already know the name of the item you want to see. Ctrl+, is very fast.
Move Lines with your keyboard
Yes I realize that Visual Studio isn't Emacs or VIM (unless you want it to be VsVim) but it does have a few tiny tricks that most VS users don't use.
You can move lines just by pressing Alt-up/down arrows. I've never seen anyone do this in the wild but me. You can also Shift-Select a bunch of lines and then Alt-Arrow them around as a group.
You can also do Square Selection with Alt and Drag...and drag yourself a nice rectangle...then start typing to type on a dozen lines at once.
Perhaps you knew these, maybe you learned a few things. I think the larger point is to have the five to ten most useful features right there in your mind ready to go. These are mine. What are your tips?
Sponsor: Do you deploy the same application multiple times for each of your end customers? The team at Octopus have been trying to take the pain out of multi-tenant deployments. Check out their 3.4 beta release.
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
Would have shared my tips like map mode scrollbar, but everything is already in this blogpost... I do hope some can come up with a tip to fully expand 1 node in solution explorer ;)
The closer the cursor is to the actual code, the more detail you see.
If the cursor is all the way on the right you just see an overview of the nesting.
I also recently wrote a similar post on my blog. Surprisingly there aren't too many overlapping tips :) Just the one with Alt + drag. Hope it's ok to link my post
I constantly find myself trying to use it in Code and even Word.
One of your evangelists did this in a demo at an Azure Bootcamp we hosted, and I bet for a few of them this was one of their biggest take-aways of the day :)
The solution explorer search thing I was a little puzzled why anyone would not know about that given it says right in the box "Search Solution Explorer (Ctrl-;)"
The map mode thing, I tried once, forgot about it, tried it again after reading this and then turned it off again, not that useful for me.
I like using the full screen view (Shift-Alt-Enter toggles it) when I want to focus on coding. It gets rid of everything but the menu bar and tabs. There seems to be a bug with it though. If VS is not maximized it works fine; the Windows taskbar is hidden and VS fills the screen. But if VS is maximized the Windows taskbar remains visible but the height of the full screen VS window is calculated as if it was so a little is cut off top and bottom.
Often, the first keystroke gets eaten. I.e. "Control-; foo" becomes "oo" typed in the completion thingy. When this happens the screen flashes. After that it's OK for a while but can happen again in the same VS session.
Also, when typing quickly, chars tend to become swapped as the insertion cursor in the completion thingy doesn't catch up quickly enough. So "foo" can be typed in as "ofo" sometimes, or even "oof".
Another annoyance is that the using the mouse on the completion results sometimes selects the wrong file. This happens when using Control-comma as a surrogate for Control-;
Say I want all XYZ.xml files. Control-, XYZ presents DIR1\XYZ.xml ... DIRn\XYZ.xml, clicking on DIR3\XYZ.xml often opens/previews DIR2\XYZ.xml. Using the arrows is fine though.
A part from the annoyances, it's a time-saving feature without which navigating a large solution project becomes quickly undoable and remains an absolutely essential features.
Thanks for that!
My most successful tip has been for SQL Management Studio. You can configure (New Connection Dialog -> Options) different DB connections to show a different colour in the status bar. Green-Dev, Orange-Test, Prod-Red.
Dined out for a week on that one when I showed it to a new team that was struggling to make sure they were in the right environment. It's not mine, a SQL guru showed me once.
I notice from your screenshots that you've got line numbers turned on. That's a setting I always get people to turn on when they ask for my help looking at their code. I can't understand why it isn't turned on by default.
@Mihai Radulescu Resharper is great, but I'd prefer to use built-in features if they are at least as good as those of Resharper, because that way I can still use them if I ever have to use a copy of Visual Studio without Resharper.
Edit=>Paste Special=>Paste JSON As Classes
Tools -> Options ->Projects and solutions -> Track Active item in solution explorer
or Ctrl + Q start typing... track
- hit Ctrl + ,
- click on the little arrow on the right of the search box
- at the bottom of the menu, you'll see a "Search options" section
- uncheck the See Preview Tab
Want to Compare Files? Did you know VS had that?The option visible on the screenshot is just to show the toolbar for comparison. I don't see any option there to literally compare two files (toolbar itself doesn't give that). Am I missing something?
It works seamlessly when using any integrated VCS when committing files or comparing them between commits and that's cool, but has nothing to do with Ctrl-Q which is great by the way.
I like the list anyway, because I like that kind of "hacks" which can make developers life easier. For example I like the fact that you can search for references in Solution Explorer Search. It saved me some time once in the past.
> Tools.DiffFiles File1.cpp File2.cpp
May I know why Microsoft has not created an AngularJS 2 template project inside VS.NET ?. We are really need to just create and have a full prepared Hello word App in less than a minute.
But Resharper's Control+T and then immediately Control+V does...
So if you want to paste what you want to search, you are out of luck... your only option is to use Resharper.
And like Tom, I'm a big fan of the Vertical tab well in the Power Tools. The only things I don't like is that I can't adjust the tab width independently in different splits, or swap one split back to horizontal tabs to minimize dead space if I only have a few tabs open.
Ctrl-Tab - brings up the window browsing thingy.
F8 - "next thing in the list", where list is whatever has focus - error list, find symbol results etc. SHIFT-F8 to go back one.
ALT + - (dash), opens the context menu of the tab like you right clicked in the tab title.
Is there a shortcut to change the search mode to "current document"? A constant tussle is accidentally searching the entire solution when I've set the mode to that in a previous search.
I can't think of any shortcuts to share, I must be all mouse! :)
I know it's not baked into VS by default, but the GoToDefinition VS extension (Ctrl+click to drill into any class/property/method/etc, including JS) I stumbled upon a couple years ago was life-changing for me. I navigate around so much more quickly and efficiently. As a GUI oriented guy I used to right-click, Go to Definition, but this extension allows me to skip by the context menu and/or having to reach up to the F12 key and gives me an intuitive "you're about to navigate here if you click" visual cue while I'm holding the Ctrl key and hovering over various classes, methods, and properties.
Another tip is that you can select text from multiple lines and then start typing. For example:
Foo.Bar.FirstName = "Bob";
Foo.Bar.LastName = "Smith";
Can be changed to:
Foo.Bar.Person.FirstName = "Bob";
Foo.Bar.Person.LastName = "Smith";
by placing your cursor at Foo.Bar and pressing Alt+Shift+Down and then typing .Person (You'll see .Person being typed on both lines)
Just wondering what do you use to record the GIFs like the last one in this article?
and the edit - paste special option to paste JSON or XML on the clipboard as C# classes... that was a cool surprise when someone showed me that!
I discovered this fairly recently and use it ALL THE TIME now to reorganize my code. It's super handy when combined with collapsible code when you want to quickly rearrange the order of the members in a big class.
vs code has vertical editing (ctrl+alt+shift+ up/down). It's a few keys yes, but works.
It also has the multiple cursors too
Ctrl + Enter -> 'O' in vim
Ctrl + Shift + Enter -> 'o' in vim
Ctrl + Shift + L -> 'dd' in vim
- Scott Hanselman < Loved it!
Anyone who prints their source code out should be shot :) especially if you need print as a hotkey
In response to ALT-DRAG in vscode
VS Code has the more superior feature of multiple cursors which allow multiple line editing, but on every line you can put your cursor in a different spot if you want
or if you want a block quickly
Esc to get rid of them
Or with mouse SHIFT-ALT select an area, it's quite flexible
ctrl + [ + s
It highlights and brings into view the currently active file in the Solution Explorer.
It takes time and thought to pick pinned tabs, and in particular in means you know fairly early on which tabs are likely to be relevant to your current edit. In that one scenario - pinned tabs work - great! use em!
But there are many edits I make where I a priori do not know exactly what I need to change where in the codebase; e.g. you might discover something to change and you follow the changes as dictated by "if I change this type here, what miscompiles?". And during such an editing sequence it emerges that one or two files are central to unravelling the spagetti; whereas others that seem relevant turn out not to be.
I'd much rather have the feature "auto-kill all (possibly unpinned) tabs without unsaved changes that are not on the top N (e.g. 50) most recently used". Or really, any semi-sane heuristic for separating "important" from "stale" tabs while keeping the number open limited. Closing the wrong tab isn't a huge problem as long as the last few you viewed aren't the ones killed.
And I heard of that here, for - what was it - VS2010 or something?
(Nope, just checked, VS2005 and VS2008!)
Ctrl + LeftClick = highlights the whole word under the cursor(as does double-LeftClick)
Ctrl + ] = With caret before a bracket, it leaps to the matching bracket
Ctrl + Left/Right Cursor = Move caret to start or end of word
Hold down the shift key while doing this and you quickly highlight words and code chunks much faster and more accurately than messing around with your mouse.
I lament the sad death of Quick Macros in recent VS versions. Knowing all the keyboard shortcuts and being able to do quick record & playback loops was a huge timesaver. I had to go out and learn to use AutoHotKey to replace this & I still miss it..
Once I started using CTRL+Q, I have no more need of the toolbars or the menu bar (with the Hide Main Menu extension).
Ctrl+i, then start typing (followed by F3, as necessary) = quickest way to search through the current document.
Ctrl+Shift+V = cycling through the clipboard "ring". I use this especially if I want to swap two items: copy itemA, copy itemB, Ctrl+Shift+V over itemA, then Ctrl+Shift+V+V over itemB = swapped.
Ctrl+K, U - Uncomment out selected
Use this all the time, and is context aware - it'll use // in a .cs file, <!-- --> in XML, and config files.
Same commands in Sql Management Studio too.
Ctrl+Dis Add Selection To Next Find Match
Its quite handy, I hope this can be added to VS.
You are right.... Ctrl+, brings up Recent Files (a R# feature) in my VS... lol... my mistake... thanks for pointing that out..
To do this, in map mode view to the right, you'll find an arrow at the very top of the map mode, drag this arrow to the bottom and voila!, you can now see two separate sections of the same class!
Now this same feature is also available in the bar mode if you weren't already aware :)
How about a blog post on "most annoying feature for Visual Studio" which would probably answer most of the niggles: changing the default search options especially for Selection would be high on my list, and how to replace Ctrl-F2-Tab-Tab-Down with a single keystroke for what-is-that-called-anyway.
There is a feature I hope if it was there: when I click a varible/field/ method, etc, all occurrences of it appear highlighted on the scroll bar, just like when I search them using Find/Replace window.
If I can do customized settings to enable it, please tell me how.
Also Remove and Sort references is great, although I think you need to map that using the Keyboard options.
Before I used to hit Ctrl + Shift + ArrowRight repeatedly to select the text to the next line including white-space, and hit Backspace.
Now I found that Ctrl + Delete or Ctrl + Backspace does that trick for me.
That's one I use all the time. Typical use case:
- You're working on some code and want to look up a definition so you hit f12 and the buffer changes to that definition (which could be in the same file or another)
- Hit Ctrl+'-' to go back to where you were.
Also useful if you need to 'push to the stack' by navigating elsewhere (eg adding an include file) and then use this shortcut to pop the stack to get back to where you were.
Pinned files in their own row (settings)
Use the alt + enter menu when available (rename suggestions etc)
ctrl + f12 > go to implementation (so glad this got introduced in one of the updates)
ctrl + k + d > format document
ctrl + D > duplicate line
ctrl + tab/ctrl + shift + tab > switch recent files
ctrl + upArrow/downArrow > scroll page up/down without moving cursor
alt + shift + up/down block highlighting
ctrl + m + o > collapse all (ctrl + m + l > invert collapsed state)
ctrl + m + m > toggle collapsed state of function
ctrl + k + c > comment
ctrl + k + u > uncomment
turn on line numbers for all files
turn on white space characters
use the mouse less, it takes a little bit but you'll get faster.
Comments are closed.